AnsibleUndefinedVariable

1,611 views
Skip to first unread message

Mike Michel

unread,
Apr 9, 2015, 8:50:06 AM4/9/15
to ansible...@googlegroups.com
hi,

im running a master/slave cluster where i want to add another slave via ansible so i am limiting the play to the new slave

ansible-playbook -vvv -l mesos_slaves[3] -i hosts-prod.yml   playbook.yml -u xxx -k -K

Add a point there comes a template which needs the ips of the other slaves

{% for host in groups['mesos_slaves'] %}
   {{ hostvars[host]['ansible_eth0']['ipv4']['address'] }}"
{% endfor %}

where mesos_slaves is

[mesos_slaves]
slave01
slave02
slave03
slave04


The play ends there with


fatal: [slave04] => {'msg': "AnsibleUndefinedVariable: One or more undefined variables: 'dict object' has no attribute 'ansible_eth0'", 'failed': True}
fatal: [slave04] => {'msg': "AnsibleUndefinedVariable: One or more undefined variables: 'dict object' has no attribute 'ansible_eth0'", 'failed': True}


but a 

ansible -i hosts-prod.yml slave01 -m setup -a "filter=*eth0*"

gives me

slave01 | success >> {
    "ansible_facts": {
        "ansible_eth0": {
            "active": true,
            "device": "eth0",
            "ipv4": {
                "address": "192.168.0.12",



Why is it not working in the play?


Mike

Brian Coca

unread,
Apr 9, 2015, 12:21:56 PM4/9/15
to ansible...@googlegroups.com
I'm guessing you are not gathering facts for the others



--
Brian Coca

Mike Michel

unread,
Apr 9, 2015, 1:02:19 PM4/9/15
to ansible...@googlegroups.com
how can i do it while limiting to one host?

Brian Coca

unread,
Apr 9, 2015, 3:43:01 PM4/9/15
to ansible...@googlegroups.com
A couple of ways, the simplest would be 2 plays, the first just
gathers facts on all hosts, the 2nd is limited to a single host, facts
are kept in memory cache by default. Another way is just setting up
persistent fact caching.

--
Brian Coca
Reply all
Reply to author
Forward
0 new messages