Curious the best pattern to do the following. I want to add the feature to allow host files to have variables, but it seems there should be a better way:
We have a few identical clusters of machines in different physical locations. So we have all our playbooks and then define the cluster in different hosts files. For example:
ansible-playbooks -i dev.vagrant some_playbook.yml
ansible-playbooks -i beijing_idc some_playbook.yml
ansible-playbooks -i ec2-west some_playbook.yml
Now, there are some variables that need to be specific to the host file or cluster. For example, the location of the yum repository to use.
Am I missing something obvious?
Thanks -
P.S.
Some basic ansible tasks to get a centos server online: https://github.com/brainpage/ansible-common
Jonathan Palley wrote:
Curious the best pattern to do the following. I *want* to add the feature
to allow host files to have variables, but it seems there should be a
better way:
We have a few identical clusters of machines in different physical
locations. So we have all our playbooks and then define the cluster in
different hosts files. For example:
ansible-playbooks -i dev.vagrant some_playbook.yml
ansible-playbooks -i beijing_idc some_playbook.yml
ansible-playbooks -i ec2-west some_playbook.yml
Now, there are some variables that need to be specific to the host file or
cluster. For example, the location of the yum repository to use.
Am I missing something obvious?
Does [all:vars] not work for you?
Plenty of options here.
There's definitely [groupname:vars] as documented in the host file.
Also, you can store files in
(directory_inventory_file_is_in)/group_vars/$groupname.yml
If you do the latter, I'd recommend a latest pull of 0.7, as
previously there was a slight bug where if your vars_files section
was empty it wouldn't load.
There's also vars_files, itself, where you can load in a set of
variables for a particular play only.
All of this is covered in the various pages of the docs, so I'd just
pick which you like best. group_vars/$groupname.yml or vars_files
are what you'll need for structured data.
Jonathan Palley wrote:
Curious the best pattern to do the following. I want to add the feature
to allow host files to have variables, but it seems there should be a
better way:
We have a few identical clusters of machines in different physical
locations. So we have all our playbooks and then define the cluster in
different hosts files. For example:
ansible-playbooks -i dev.vagrant some_playbook.yml
ansible-playbooks -i beijing_idc some_playbook.yml
ansible-playbooks -i ec2-west some_playbook.yml
Now, there are some variables that need to be specific to the host file or
cluster. For example, the location of the yum repository to use.
Am I missing something obvious?
Does [all:vars] not work for you?
That is the obvious way that I just wasn’t seeing. Thanks.
I think why the groupname variations on loading vars doesn’t work is because I’m using the same group names in different inventory files.
Maybe this is where I’ve gone off track in terms of the standard pattern; but the host files just became to long and messy which is why I put each “cluster” in its own host files.
I think why the groupname variations on loading vars doesn’t work is because I’m using the same group names in different inventory files.
ansible looks at one and only one inventory file, so I can close this. ok.
Maybe this is where I’ve gone off track in terms of the standard pattern; but the host files just became to long and messy which is why I put each “cluster” in its own host files.
I suspect as we grow there will be alternative external inventory scripts that support more of a “.d” directory structure. I’d suggest someone write one for their own use and release it, and
I’ll gladly mention it on the “ansible-resources” page.
(As a refresher, if you have a script that behaves correctly, you can use it with “-i” or even place it in default the inventory file location.)