Yes and no. I have already put some of the variables that are contained in 
the hosts files into group_vars/all, but since I am using a directory for 
inventory it is reading all the hosts files and so some environment host 
files I have not yet had the chance to migrate to group_vars/envname.yml. 
In those cases the precedence is those inventory vars will be a higher 
priority than group_vars. I am in a halfway house and attempting to migrate 
away so no variables are contained in the inventory files. I'm just not 
there yet and wonder how the variable precedence is used where multiple 
host files exist.


On Friday, 12 May 2017 19:16:20 UTC+1, Dan Bateman wrote:
>
> I have a setup where I have multiple inventory files in a directory and my 
> ansible.cfg points to that inventory directory rather than a file. Also 
> using ec2.py for aws dynamic inventory which is inside the inventory 
> directory also. All hosts files, except for one are in a sub directory.
> All of the host files have [all:vars] defined, pretty much all the 
> variables are duplicated across these different hosts files, but some have 
> different values based on the type of environment. I'm attempting to use 
> Dynamic inventory and to accommodate this I have a 'hosts' file named as 
> such, in the root of the inventory directory. This contains all my tagging 
> for AWS to allow me to use short names which relate to an AWS tag + the 
> same [all:vars] which I want to be read when I'm using dynamic inventory, 
> because I don't want ansible reading other [all:vars] from other inventory 
> files. 
> Along with the hosts files, I have a group_vars dir, which contains an 
> all.yml that also duplicates some of the variables in the different hosts 
> files(I know, I know). I eventually want to deprecate the [all:vars] 
> contained in the hosts files in favour of just using 
> group_vars/{all,env1,env2, etc}, but at the moment I can't. 
>
> My question is, when I run ansible, in what order will it obtain variables 
> when multiple host files exist, i.e. using dynamic inventory option I don't 
> specify a hosts file or ec2.py, just allow ansible.cfg to read everything 
> in the inventory dir:
>
> ansible-playbook someplaybook.yml -e 'somevar=something 
> anothervar=anotherthing' --limit devenv
>
> Ideally I want ansible to use just read ec2.py and 'hosts' file, or at 
> least read the 'hosts' and pickup the [all:vars] from there. I don't want 
> it reading all the other host files that exist in the directory or at least 
> I want to know what order it will read them. What is the precedence?
> Does having hosts files in sub-directories help in the precedence of 
> reading the hostfiles?
>
> Thanks.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/816ccce6-efe2-4159-b981-ea7fde1e8645%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to