--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
You have already learned about inventory variables, ‘vars’, and ‘vars_files’. In the event the same variable name occurs in more than one place, what happens? There are really three tiers of precedence, and within those tiers, some minor ordering rules that you probably won’t even need to remember. We’ll explain them anyway though.
Variables that are set during the execution of the play have highest priority. This includes registered variables and facts, which are discovered pieces of information about remote hosts.
Descending in priority are variables defined in the playbook. ‘vars_files’ as defined in the playbook are next up, followed by variables as passed to ansible-playbook via –extra-vars (-e), then variables defined in the ‘vars’ section. These should all be taken to be basically the same thing – good places to define constants about what the play does to all hosts in the play.
Finally, inventory variables have the least priority. Variables about hosts override those about groups. If a variable is defined in multiple groups and one group is a child of the other, the child group variable will override the variable set in the parent.
This makes the ‘group_vars/all’ file the best place to define a default value you wish to override in another group, or even in a playbook. For example, your organization might set a default ntp server in group_vars/all and then override it based on a group based on a geographic region. However if you type ‘ntpserver: asdf.example.com’ in a vars section of a playbook, you know from reading the playbook that THAT specific value is definitely the one that is going to be used. You won’t be fooled by some variable from inventory sneaking up on you.
So, in short, if you want something easy to remember: facts beat playbook definitions, and playbook definitions beat inventory variables.
== end ==
Hi,
I noticed that the new text does not mention parameters to included tasks/handlers list and also not for parameters to included playbooks. Also `vars_prompt` could be added.
Yes, changing the precedence is dangerous, but I really wondering if any playbook in the wild ever uses:
vars:
foo: "this will get overriden"
vars_files:
- vars/file_overriding_foo.yml
Maybe in combination with conditional imports it would make a little sense (under one condition `foo` is overriden, otherwise not), but I doubt anyone is doing this. Or is there anyone on this list? Can you explain the use case?
Greetings,
gw
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
How does it work with precedence with hosts/groups specified on command line versus hosts and groups in playbook-of-playbooks and/or playbooks?