Documentation (see 4-7, 9, 10 from the list of priorities) says that playbook level variables override an inventory ones. Can somebody explain why this is the case? To me this is counter-intuitive and keeps leading to mistakes.
Intuitive way would be:
role defaults (specified within the role itself)
⇩
infrastructure defaults, e.g. datacenter level (specified in group_vars or host_vars on the playbook level)
⇩
inventory defaults, e.g. availability zone, or a specific project, etc (specified in group_vars or host_vars on inventory level)
However the fact is that 2 always overrides 3. How was it supposed to be used?
I choose not to do that, and instead forgo separating inventory from playbook group_vars.
I, too, would be interested in an explanation of why the order is what it is. I’ve been bitten by it in the past.
Ansible is supposed to be simple and overriding precedence would make it a way more complicated. Changing the default behaviour (with an option for backwards compatibility) would make it more logical. Any devs here?
4-10 are all talking about host related vars. It’s just that group_vars and host_vars can live at 2 locations:
relative to the inventory file
relative to the playbook file
It is assumed that if you put host_vars and group_vars relative to the playbook, that they are more specific to that playbook, as such they override host_vars and groups_vars that are relative to the inventory file.
It is assumed that if you put host_vars and group_vars relative to the playbook, that they are more specific to that playbook, as such they override host_vars and groups_vars that are relative to the inventory file.
I’m having hard time imagining how this can be useful and when somebody would want to override inventory variables by the play ones. What would be the use case? What would be the files structure?