# I have trouble understanding the variable hierarchy

**URL:** <https://forum.ansible.com/t/i-have-trouble-understanding-the-variable-hierarchy/13730>\
**Category:** Ansible Project\
**Created:** [October 21, 2013, 2:38pm UTC](https://forum.ansible.com/t/i-have-trouble-understanding-the-variable-hierarchy/13730 "2013-10-21T14:38:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guillem\_Liarte](https://avatars.discourse-cdn.com/v4/letter/g/e95f7d/32.png) [@Guillem\_Liarte](https://forum.ansible.com/u/Guillem_Liarte)\
**Post date:** [October 21, 2013, 2:38pm UTC](https://forum.ansible.com/t/i-have-trouble-understanding-the-variable-hierarchy/13730/1 "2013-10-21T14:38:49Z")

</div>

Hello,

I have experience in CfEngine and Puppet and I am trying to get to understand Ansible, but soem simple things as expading a variable do not seem to work as easy as it says in tin.

I am following the structure describe here:

[http://www.ansibleworks.com/docs/playbooks\_best\_practices.html](http://www.ansibleworks.com/docs/playbooks_best_practices.html)

Can someone explain when you want to store variables here:

```auto
<b>group_vars/
   group1 # here we assign variables to particular groups
   group2 # ""</b>

```

Or here:

```auto
roles/
    common/ # this hierarchy represents a "role"
        tasks/ #
            main.yml # <-- tasks file can include smaller files if warranted
        handlers/ #
            main.yml # <-- handlers file
        templates/ # <-- files for use with the template resource
            ntp.conf.j2 # <------- templates end in .j2
        files/ #
            bar.txt # <-- files for use with the copy resource
            foo.sh # <-- script files for use with the script resource
<b> vars/ #
            main.yml # <-- variables associated with this role</b>

```

I think I understand that the group\_var is the variables that will be assigned to a group of hosts that are defined with the same name as the file inside group\_vars directory, and the second would be default variables for a certain role. Correct me if I am wrong so far.

Then, my question is; in which order does Ansible assign variables. So far in my experience it looks like any group variables are being ignored.

Can somebody with experience with something like external variables and ‘Hiera’ in Puppet tell me how this one works? So far I fail to see the logic.

Many thanks in advance.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 22, 2013, 1:21am UTC](https://forum.ansible.com/t/i-have-trouble-understanding-the-variable-hierarchy/13730/2 "2013-10-22T01:21:24Z")

</div>

[http://ansibleworks.com/docs/playbooks\_variables.html#variable-precedence-where-should-i-put-a-variable](http://ansibleworks.com/docs/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable)

---

<div class="post-metadata">

**Author:** ![Guillem\_Liarte](https://avatars.discourse-cdn.com/v4/letter/g/e95f7d/32.png) [@Guillem\_Liarte](https://forum.ansible.com/u/Guillem_Liarte)\
**Post date:** [October 22, 2013, 3:47pm UTC](https://forum.ansible.com/t/i-have-trouble-understanding-the-variable-hierarchy/13730/3 "2013-10-22T15:47:17Z")

</div>

Michael,

Thank for the link.

I am sure there is a simplicity in there I am not able to appreciate yet. Maybe too used to more complicated ways. I will give it another shot.

Thanks again.

---

<div class="post-metadata">

**Author:** ![D11](https://avatars.discourse-cdn.com/v4/letter/d/47e85d/32.png) [@D11](https://forum.ansible.com/u/D11)\
**Post date:** [June 11, 2018, 4:20am UTC](https://forum.ansible.com/t/i-have-trouble-understanding-the-variable-hierarchy/13730/4 "2018-06-11T04:20:38Z")

</div>

Hi Liarte,

please share if this worked for you or how you organized your data ?

Thanks,  
D
