# Can i use variables as values to variables defined in inventory file

**URL:** <https://forum.ansible.com/t/can-i-use-variables-as-values-to-variables-defined-in-inventory-file/22304>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [August 17, 2016, 10:02am UTC](https://forum.ansible.com/t/can-i-use-variables-as-values-to-variables-defined-in-inventory-file/22304 "2016-08-17T10:02:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ishan\_jain](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@ishan\_jain](https://forum.ansible.com/u/ishan_jain)\
**Post date:** [August 17, 2016, 10:02am UTC](https://forum.ansible.com/t/can-i-use-variables-as-values-to-variables-defined-in-inventory-file/22304/1 "2016-08-17T10:02:36Z")

</div>

I am trying to imply environment wide values via inventory file for which i need to use some other variables as values.  
My host file looks like this:

[linunx]  
linux1  
linux2

[windows]  
windows1  
windows2

[all]  
linux  
windows

[all:vars]  
environment=ABC  
client=XYZ  
path=/opt/config/{{environment}}\_{{client}}

Is this possible within inventory file or i will have to prepare all.yaml in group vars ?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 17, 2016, 10:51am UTC](https://forum.ansible.com/t/can-i-use-variables-as-values-to-variables-defined-in-inventory-file/22304/2 "2016-08-17T10:51:08Z")

</div>

Why not test it yourself?

In a folder create these 3 files, ansible.cfg, hosts and test.yml:

ansible.cfg  
[defaults]  
hostfile = hosts

hosts  
[all:vars]  
environment=ABC  
client=XYZ  
path=/opt/config/{{environment}}\_{{client}}

test.yml

---

<div class="post-metadata">

**Author:** ![ishan\_jain](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@ishan\_jain](https://forum.ansible.com/u/ishan_jain)\
**Post date:** [August 29, 2016, 6:14am UTC](https://forum.ansible.com/t/can-i-use-variables-as-values-to-variables-defined-in-inventory-file/22304/3 "2016-08-29T06:14:56Z")

</div>

This seems to be working just fine. Ansible is parsing the variables in inventory files.
