According to that error, you have not defined a variable called
'ansible_host'.   Where is that variable supposed to be coming from?

The variable that ansible creates that references the current host is
called inventory_hostname.  Perhaps you were meaning ansible_hostname?

In either case inventory_hostname is safer to use, as that is what ansible
knows about from the inventory, and ansible_hostname is not necessarily the
same value as inventory_hostname.

On Wed, Nov 5, 2014 at 4:06 PM, Joel Sdc <sdc.j...@gmail.com> wrote:

> Hi Michael,
>
> Just tried, same problem...
>
> "{{ hostvars[ansible_host]['ansible_bond0.11']['ipv4']['address'] }}":
>
> fatal: [testserver1] => {'msg': "AnsibleUndefinedVariable: One or more
> undefined variables: 'ansible_host' is undefined", 'failed': True}
> fatal: [testserver1] => {'msg': "AnsibleUndefinedVariable: One or more
> undefined variables: 'ansible_host' is undefined", 'failed': True}
> fatal: [testserver2] => {'msg': "AnsibleUndefinedVariable: One or more
> undefined variables: 'ansible_host' is undefined", 'failed': True}
> fatal: [testserver2] => {'msg': "AnsibleUndefinedVariable: One or more
> undefined variables: 'ansible_host' is undefined", 'failed': True}
>
> FATAL: all hosts have already failed -- aborting
>
> Just in case, tried this one also:
>
> "{{ hostvars['ansible_host']['ansible_bond0.11']['ipv4']['address'] }}"
>
> fatal: [testserver1] => {'msg': 'AnsibleError: host not found:
> ansible_host', 'failed': True}
> fatal: [testserver1] => {'msg': 'AnsibleError: host not found:
> ansible_host', 'failed': True}
> fatal: [testserver2] => {'msg': 'AnsibleError: host not found:
> ansible_host', 'failed': True}
> fatal: [testserver2] => {'msg': 'AnsibleError: host not found:
> ansible_host', 'failed': True}
>
> FATAL: all hosts have already failed -- aborting
>
>
>
> Any other ideas?
>
> Thank you!
>
> J.
>
> On Wednesday, November 5, 2014 3:14:21 PM UTC+1, Michael DeHaan wrote:
>>
>> >> "{{ hostvars[{{ ansible_host }}]['ansible_bond0.11']['ipv4']['address']
>> }}"
>>
>> You'll want to remove the template stuff inside the template stuff:
>>
>> "{{ hostvars[ansible_host]['ansible_bond0.11']['ipv4']['address'] }}"
>>
>>
>> On Tue, Nov 4, 2014 at 5:25 PM, Joel Sdc <sdc....@gmail.com> wrote:
>>
>>> Hi Matt,
>>>
>>> Would this be valid?
>>>
>>> "{{ hostvars[{{ ansible_host }}]['ansible_bond0.11']['ipv4']['address']
>>> }}"
>>>
>>> This is the playbook:
>>>
>>> ---
>>> - name: Setup SNMP on testservers
>>>   hosts: testservers
>>>   roles:
>>>     - { role: snmp, snmp_rocommunity: comtestsrv, snmp_listen_ip: "{{
>>> ansible_bond0.11['ipv4']['address'] }}" }
>>>
>>>
>>> And then:
>>>
>>> # cat templates/snmpd.conf.j2
>>>
>>> # {{ ansible_managed }}
>>> agentAddress  udp:{{ snmp_listen_ip }}:161
>>> {% for server in snmp_authorized_hosts %}
>>> rocommunity {{ snmp_rocommunity }} {{ server.ip }}/32
>>> {% endfor %}
>>> syslocation {{ snmp_syslocation }}
>>> syscontact {{ snmp_syscontact }} <{{ snmp_syscontact_email }}>
>>>
>>>
>>> testservers is a group with testserver1 and testserver2, so the
>>> "snmp_listen_ip" would be the bond0.11 IPv4 address for each host when
>>> creating the snmpd.conf file.
>>>
>>>
>>> I also tried:
>>>
>>> "{{ ['ansible_bond0.11']['ipv4']['address'] }}"
>>> "{{ ansible_bond0.11['ipv4']['address'] }}"
>>>
>>> But they also failed..
>>>
>>>
>>> Thanks again!
>>> J.
>>>
>>>
>>>
>>> On Tue, Nov 4, 2014 at 9:21 PM, Matt Martz <ma...@sivel.net> wrote:
>>>
>>>> To use a hostvar that contains a '.' you will need to do something such
>>>> as:
>>>>
>>>> {{ hostvars[inventory_hostname]['ansible_bond0.11']['ipv4']['address']
>>>> }}
>>>>
>>>> On Tue, Nov 4, 2014 at 1:51 PM, Joel Sdc <sdc....@gmail.com> wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> I am using Ansible v1.7.1.
>>>>>
>>>>> I am having trouble using the gathered facts when an interface has
>>>>> bonding and VLANs enabled:
>>>>>
>>>>> # ansible -m setup testserver
>>>>>
>>>>> [...]
>>>>>         "ansible_bond0.11": {
>>>>>             "active": true,
>>>>>             "device": "bond0.11",
>>>>>             "ipv4": {
>>>>>                 "address": "192.168.11.66",
>>>>>                 "netmask": "255.255.255.0",
>>>>>                 "network": "192.168.11.0"
>>>>>             },
>>>>>             "macaddress": "d4:ae:52:98:71:1f",
>>>>>             "mtu": 1500,
>>>>>             "promisc": false,
>>>>>             "type": "ether"
>>>>>         },
>>>>> [...]
>>>>>
>>>>> Then, I have a playbook that sets a variable:
>>>>>
>>>>> Example from a different server that doesn't have bonding or VLANs:
>>>>>
>>>>> listen_ip: "{{ ansible_eth1.ipv4.address }}"
>>>>>
>>>>> Example that doesn't work:
>>>>>
>>>>> listen_ip: "{{ ansible_bond0.11.ipv4.address }}"
>>>>>
>>>>> Ansible output:
>>>>>
>>>>> fatal: [testserver] => {'msg': 'AnsibleUndefinedVariable: One or more
>>>>> undefined variables: dict object has no element 11', 'failed': True}
>>>>> fatal: [testserver] => {'msg': 'AnsibleUndefinedVariable: One or more
>>>>> undefined variables: dict object has no element 11', 'failed': True}
>>>>>
>>>>> FATAL: all hosts have already failed -- aborting
>>>>>
>>>>> I have tried different possibilities but they all failed:
>>>>>
>>>>> "{{ ansible_bond0\.11.ipv4.address }}"
>>>>> "{{ ansible_bond0\\.11.ipv4.address }}"
>>>>> "{{ [ansible_bond0.11].ipv4.address }}"
>>>>> "{{ {ansible_bond0.11}.ipv4.address }}"
>>>>> "{{ 'ansible_bond0.11'.ipv4.address }}"
>>>>>
>>>>> I think Ansible is taking the VLAN tag as part of the subgroup in the
>>>>> config...
>>>>>
>>>>> What is the correct way of selecting the IPv4 address of a bond0.11
>>>>> interface?
>>>>>
>>>>> Thank you in advanced.
>>>>>
>>>>> Best regards,
>>>>> J.
>>>>>
>>>>>  --
>>>>> 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 ansible-proje...@googlegroups.com.
>>>>> To post to this group, send email to ansible...@googlegroups.com.
>>>>> To view this discussion on the web visit https://groups.google.com/d/
>>>>> msgid/ansible-project/15e60e0b-879b-4ce2-8935-
>>>>> 717f5be40cf7%40googlegroups.com
>>>>> <https://groups.google.com/d/msgid/ansible-project/15e60e0b-879b-4ce2-8935-717f5be40cf7%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Matt Martz
>>>> @sivel
>>>> sivel.net
>>>>
>>>> --
>>>> You received this message because you are subscribed to a topic in the
>>>> Google Groups "Ansible Project" group.
>>>> To unsubscribe from this topic, visit https://groups.google.com/d/
>>>> topic/ansible-project/mpB96y4Ee58/unsubscribe.
>>>> To unsubscribe from this group and all its topics, send an email to
>>>> ansible-proje...@googlegroups.com.
>>>> To post to this group, send email to ansible...@googlegroups.com.
>>>> To view this discussion on the web visit https://groups.google.com/d/
>>>> msgid/ansible-project/CAD8N0v_ohv%2B5czaYvmg2%2BV_%3DvQcR-
>>>> iT8GLt1ctHQeVnyskr%3DgQ%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/ansible-project/CAD8N0v_ohv%2B5czaYvmg2%2BV_%3DvQcR-iT8GLt1ctHQeVnyskr%3DgQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>  --
>>> 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 ansible-proje...@googlegroups.com.
>>> To post to this group, send email to ansible...@googlegroups.com.
>>> To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/ansible-project/CACwajiME7VyPE9ZQ-8gD3LtX7KicrkECbNKY15uexxL9J3j
>>> gbw%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/ansible-project/CACwajiME7VyPE9ZQ-8gD3LtX7KicrkECbNKY15uexxL9J3jgbw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>  --
> 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 ansible-project+unsubscr...@googlegroups.com.
> To post to this group, send email to ansible-project@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/54c1da78-8e36-42ab-aff9-99f7ef30d97d%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/54c1da78-8e36-42ab-aff9-99f7ef30d97d%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Matt Martz
@sivel
sivel.net

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAD8N0v9_QTMazffiVb3%2Bi1ESDZ%3Dh7%2BFxJkbF8puQVd2MudP0sA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to