Order of magic "groups" variable

Hi everyone,

I was under the impression that when using the magic “groups” variable, the list order would follow the order as specified in the inventory file.

So for example given the following inventory:

[databases]
db1
db2

I expected that ${hostvars.${groups.databases[0]}.ansible_hostname} would expand to ‘db1’.
It now appears to me that might not always be the case.

Can someone give some guidance here as far as what the expected behavior should be?
Is it a list or a set?

Thanks!

  • Oren

For one, thou shalt not use deprecated old style variables, you want this below:

hostvars[groups[databases[0]][‘ansible_hostname’]

:slight_smile:

Ordering in some versions of Ansible is not very predictable. This was fixed in 1.4, which releases tomorrow.

They will appear in the order listed in inventory.