I have trouble understanding the variable hierarchy

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

Can someone explain when you want to store variables here:

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

Or here:

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.

http://ansibleworks.com/docs/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable

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.

Hi Liarte,

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

Thanks,
D