Ansible 2 group_vars order

204 views
Skip to first unread message

antony.p...@polyconseil.fr

unread,
May 18, 2016, 10:12:56 AM5/18/16
to Ansible Project

Hello,


I do many tests and I don't understand the group_vars load order in ansible 2. With ansible 1 vars are load in my playbook order. But with ansible 2 it seems to be totally random.


For example:


I have 2 groups:


group_vars# tree
├── all.yml
├── site_plo.yml

           toto: foo
└── machine_ehp.yml

           toto: bar


I place my machine in thats groups with this playbook :


- name: Dynamically define site
  group_by: "key=site_{{ inventory_hostname_short[0:3] }}"

- name: Dynamically define environment
  group_by: "key=machine_{{ inventory_hostname_short[3:6] }}"


- debug: var=toto



In this configuration toto=foo


When I rename machine_eh1 there is no logic :
amachine_eh1:  toto=bar
bmachine_eh1:  toto=bar
cmachine_eh1:  toto=bar
dmachine_eh1:  toto=foo
emachine_eh1:  toto=bar
zmachine_eh1:  toto=foo



There is a bug ? a specific order rule ? a random rule ?


Thanks for your help

Johannes Kastl

unread,
May 18, 2016, 1:38:25 PM5/18/16
to ansible...@googlegroups.com
On 18.05.16 16:12 antony.p...@polyconseil.fr wrote:

> There is a bug ? a specific order rule ? a random rule ?

Does this help?
https://docs.ansible.com/ansible/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable

Johannes

signature.asc

antony.p...@polyconseil.fr

unread,
May 19, 2016, 3:15:44 AM5/19/16
to Ansible Project
My question is about this part of doc:

If multiple groups have the same variable, the last one loaded wins

What is the load order ? It seems to not be alphabetical.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages