# How to handle variables

**URL:** <https://forum.ansible.com/t/how-to-handle-variables/21825>\
**Category:** Ansible Project\
**Created:** [June 22, 2016, 2:18am UTC](https://forum.ansible.com/t/how-to-handle-variables/21825 "2016-06-22T02:18:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![john.shao](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@john.shao](https://forum.ansible.com/u/john.shao)\
**Post date:** [June 22, 2016, 2:18am UTC](https://forum.ansible.com/t/how-to-handle-variables/21825/1 "2016-06-22T02:18:30Z")

</div>

Looking for some help on a variable scenario

We have a lot of variables defined in the group\_vars/all file which set the default variable that is used across multiple roles/playbook

For each environment, we have an ini inventory file. We would like to use the ini file as the place to override variable that might be different from default.

There is the feature for ansible to have env specific variable but you would need two file. Ideally we would like to keep everything in the same inventory file.

We have a section in the ini file called “[all:vars]” but it seems like the value in the group\_vars/all override the one in the ini file which isn’t ideal.

Anyone have any suggestion on how I could make this happen? Was thinking of using lookup but there doesn’t seem to be a way to load it from the inventory file for variables.

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [June 22, 2016, 11:27pm UTC](https://forum.ansible.com/t/how-to-handle-variables/21825/2 "2016-06-22T23:27:53Z")

</div>

I do this by having a per-environment inventory, each of which has its  
own group\_vars/all.  
e.g.

production/hosts  
production/group\_vars/all  
staging/hosts  
staging/group\_vars/all  
dev/hosts  
dev/group\_vars/all

and so on. Then invoke the same play against each environment like :

ansible-playbook -i production/ site.yml

If you want you could have a file per environment with an [all:vars]  
section laid out like this:

production\_hosts  
staging\_hosts  
dev\_hosts

called with

ansible-playbook -i production\_hosts site.yml

and do away with your group\_vars/all altogether.
