# Suggest : inventory variables should have more weight

**URL:** <https://forum.ansible.com/t/suggest-inventory-variables-should-have-more-weight/19879>\
**Category:** Ansible Developer\
**Created:** [November 27, 2015, 10:25pm UTC](https://forum.ansible.com/t/suggest-inventory-variables-should-have-more-weight/19879 "2015-11-27T22:25:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rainer\_Weinhold](https://avatars.discourse-cdn.com/v4/letter/r/c37758/32.png) [@Rainer\_Weinhold](https://forum.ansible.com/u/Rainer_Weinhold)\
**Post date:** [November 27, 2015, 10:25pm UTC](https://forum.ansible.com/t/suggest-inventory-variables-should-have-more-weight/19879/1 "2015-11-27T22:25:39Z")

</div>

Hello,

i would like to propose a behavoiur change for variable overwrite order:

When running a playbook, variables defined in the inventory ( or inventory groups) should have a higher weight then playbook group\_vars. They should actually be at the same ‘level’ als the extra vars ( [http://docs.ansible.com/ansible/playbooks\_variables.html#variable-precedence-where-should-i-put-a-variable](http://docs.ansible.com/ansible/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable) ).

Why?  
Because inventories are a commandline option and naturally they are therefore very specific for a given environment. One would expected them to overwrite playbooks variables.  
E.g. we use the same playbook in all our environments. The designated site-teams provide their inventory with environment specific stuff ( endpoints, key and certs etc.). These should _not_ be checked in at the low(er) security developer repository ( even with a vault ), so the production inventory needs a way to overwirte some/all variables. Currently this only works when these variables are not defined elsewhere. So if we didn’t think about providing a inventory-variable for overwrite a setting, we cannot change a varibale X via the inventory and have thereforte to change the playbook and rerun the complete (playbook) pipeline.

Workarounds:

- extra vars  
This works, but does not have the power of groups, so you cannot have one site.yml run, but differences in group variables. ( So this only works in very rare cases. )

- group\_vars  
Will overwrite the inventory, but not playbook variables ( that only works with extra vars ).

Suggestion:

Sort variable precedence from the less specific ones to more specific ones:

- role defaults
- playbook group\_vars
- playbook host\_vars
- host facts
- registered vars
- set\_facts
- play vars
- play vars\_prompt
- play vars\_files
- role and include vars
- block vars (only for tasks in block)
- task vars (only for the task)
- 

> inventory vars \<

- 

> inventory group\_vars \<

- 

> inventory host\_vars \<

- extra vars

I know this is a very different behaviour than 1.x , but this is the behaviour i would (have) expect(ed) when just using ansible as newbee.

Cheers Rainer

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 1, 2016, 7:01am UTC](https://forum.ansible.com/t/suggest-inventory-variables-should-have-more-weight/19879/2 "2016-01-01T07:01:29Z")

</div>

You could argue in the same way that the playbooks are also passed in  
the command line (always, unlike inventories which can be inferred  
from other configs).

This can be approached in many ways and there are good arguments for  
each weight/precedence order, but changing this will break backwards  
compatibility in a big way and not a good one, as it won't be a 'fail  
the play' but 'run the play with data you did not expect'.
