Thank you Michael for the right syntax :)
Is it also possible to select one host in the goup array based on a city
defined as variable for a particular host? In other words, I don't know on
what position in the array the servername is I need. I only know it is in
group databaseserver and that it has amterdam defined as variable city.
By the way if I try this in a template:
{{ hostvars[groups['databaseserver'][0]].ansible_eth0.ipv4.address }}
I get the following error running a playbook with the above in a template:
fatal: [localhost] => {'msg': "One or more undefined variables: 'dict'
object has no attribute 'ansible_eth0'", 'failed': True}
fatal: [localhost] => {'msg': "One or more undefined variables: 'dict'
object has no attribute 'ansible_eth0'", 'failed': True}
FATAL: all hosts have already failed -- aborting
Op dinsdag 29 juli 2014 17:07:57 UTC+2 schreef Michael DeHaan:
>
> The above imaginary syntax will not work, but this will :) The groups
> array contains the names of each host in each group, and this picks out the
> first one in inventory order.
>
> {{ hostvars[groups['databaseserver'][0]].ansible_eth0.ipv4.address }}
>
> If using a template file versus inline in the playbook, I'd do this:
>
> {# set db_head_node = groups['databaseserver'][0] #}
> {{ hostvars[db_head_node].blarg }}
>
> for readability purposes
>
>
>
>
> On Tue, Jul 29, 2014 at 11:02 AM, Piet83 <[email protected]
> <javascript:>> wrote:
>
>> Ok but what if I don't know the server name but only that it is an
>> database server in amsterdam?
>>
>> Something like this, but then with the right syntax?
>>
>> {{ groups["databaseserver"] | {{ hostvars["amsterdam"] }} | {{
>> ansible_eth0.ipv4.address }} }}
>>
>> Op dinsdag 29 juli 2014 14:23:04 UTC+2 schreef Brian Coca:
>>
>>> just do {{ city }}, if it is the 'current host', to access vars of
>>> other hosts {{ hostvars['server3'].city }}
>>>
>> --
>> 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] <javascript:>.
>> To post to this group, send email to [email protected]
>> <javascript:>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/0ec5b636-9383-4a80-9c51-28831b33406a%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/ansible-project/0ec5b636-9383-4a80-9c51-28831b33406a%40googlegroups.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 [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/1cfae46f-eeea-4936-9cfe-1b9313c9a45f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.