I have some tasks like:
- debug: var=hostvars[item]
with_items: groups.rabbitmq_server
- name: Update /etc/hosts with rabbitmq-server hostnames
lineinfile:
dest: /etc/hosts
regexp: "^{{hostvars[item]['ansible_default_ipv4']['address']}}
{{hostvars[item]['ansible_hostname']}}$"
line: "{{hostvars[item]['ansible_default_ipv4']['address']}}
{{hostvars[item]['ansible_hostname']}}"
state: present
with_items: groups.rabbitmq_server
When the second runs I get:
TASK: [Update /etc/hosts with rabbitmq-server hostnames]
**********************
fatal: [10.0.136.70] => One or more undefined variables: 'dict object' has
no attribute 'ansible_default_ipv4'
fatal: [10.0.137.195] => One or more undefined variables: 'dict object' has
no attribute 'ansible_default_ipv4'
But just in the debug above I have:
"ansible_default_ipv4": {
"address": "10.0.137.195",
"alias": "eth0",
"gateway": "10.0.137.1",
"interface": "eth0",
"macaddress": "0e:ab:ba:38:c4:a1",
"mtu": 9001,
"netmask": "255.255.255.0",
"network": "10.0.137.0",
"type": "ether"
},
( I used to reference the hostvars
like hostvars[item].ansible_default_ipv4.address but tried using [] just
out of frustration. )
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/202bf1f1-2b5c-4a4a-b030-d2aa09b89e35%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.