# variables defined in the Inventory

**URL:** <https://forum.ansible.com/t/variables-defined-in-the-inventory/25230>\
**Category:** Ansible Project\
**Created:** [August 11, 2017, 7:20am UTC](https://forum.ansible.com/t/variables-defined-in-the-inventory/25230 "2017-08-11T07:20:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wenxing\_zheng](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wenxing\_zheng](https://forum.ansible.com/u/wenxing_zheng)\
**Post date:** [August 11, 2017, 7:20am UTC](https://forum.ansible.com/t/variables-defined-in-the-inventory/25230/1 "2017-08-11T07:20:29Z")

</div>

Dear all,

I have an inventory defined in the way below:

> [Group1]  
> host1

> [Group1:vars]  
> package\_name: aaa

> foo: bar

> [Group2]  
> host1

> [Group2:vars]  
> package\_name: bbb  
> foo1: bar

then I defined a playbook for the hosts with: Group2. But when I execute the playbook, I found the package\_name was in aaa instead of bbb.

What’s the problem here?

Thanks for the advice  
Regards, Wenxing

---

<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 11, 2017, 9:04am UTC](https://forum.ansible.com/t/variables-defined-in-the-inventory/25230/2 "2017-08-11T09:04:45Z")

</div>

There is no problem, this is how Ansible work.

You always get all the variables for a host regardless from where the variable is defined, inventory, group\_vars and host\_vars.

So in you example host1 will always have foo and foo1 defined.  
And since package\_name is set two times for host1 only the last one will stick since the variable is overwritten.

---

<div class="post-metadata">

**Author:** ![wenxing\_zheng](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wenxing\_zheng](https://forum.ansible.com/u/wenxing_zheng)\
**Post date:** [August 11, 2017, 9:28am UTC](https://forum.ansible.com/t/variables-defined-in-the-inventory/25230/3 "2017-08-11T09:28:07Z")

</div>

Get it. Many thanks for the feedback.
