Best way of writting inventory file

31 views
Skip to first unread message

fanvalt

unread,
Sep 26, 2016, 4:22:25 AM9/26/16
to Ansible Project
Hello,

I have an inventory file to install for one user many ways, it looks like this:

[USER1_DEV1]
PARAM="[app1','1.0.1','1']"

[USER1_DEV2]
PARAM="['app1','1.1.0','5']"

[USER1_REC1]
PARAM="['app1','1.0.4','2']"

[USER1_REC2]
PARAM="['app1','1.1.0','6']"

[USER1_PREREC1]
PARAM="['app1','1.0.3','3']"

[USER1_PREREC2]
PARAM="['app1','1.0.3','7']"

[USER1_DEV:children]
USER1_DEV1
USER1_DEV2

[USER1_PREREC:children]
USER1_PREREC1
USER1_PREREC2

[USER1_REC:children]
USER1_REC1
USER1_REC2

[user1:children]
USER1_DEV
USER1_REC
USER1_PREREC

[linux1:children]
user[1:10]
produser[70:72]

[user1:vars]
ansible_user=user1

[linux1:vars]
ansible_host=linux1.fr.com

[webservers:children]
linux1


So when running the ansible-playbook command, I do use the -l option to decide what to deploy (-l USER1_REC in example).
The issue is, that I have 10 users and 10 produsers, all working the same way so I would have to duplicate all these lines again and again like:
[user2:children]
USER2_DEV
USER2_REC
USER2_PREREC

etc ..
but only the first lines are different:
[USER1_DEV1]
PARAM="[app1','1.0.1','1']"

[USER2_DEV1]
PARAM="[app1','2.0.1','1']"

[USER1_DEV2]
PARAM="[app1','1.0.1','1']"

[USER2_DEV2]
PARAM="[app1','1.1.1','1']"

Is there a simple way to proceed for not writing all these lines ? Shall I try to use a dynamic inventory file , could someone give me an example ?
Regards

J Hawkesworth

unread,
Sep 26, 2016, 9:08:30 AM9/26/16
to Ansible Project
Have a look at using separate group_vars files for common variables you can apply to more than one machine - see http://docs.ansible.com/ansible/intro_inventory.html#splitting-out-host-and-group-specific-data
Also, consider having different inventory files.  I have a different inventory for development, testing and each production environment.

Hope this helps,

Jon

Brian Coca

unread,
Sep 26, 2016, 9:10:43 AM9/26/16
to ansible...@googlegroups.com
Using group/host_vars is a good idea, even so, this looks incorrect:

[USER1_DEV1]
PARAM="[app1','1.0.1','1']"

It should be:

[USER1_DEV1:vars]
PARAM="[app1','1.0.1','1']"


----------
Brian Coca

fanvalt

unread,
Sep 26, 2016, 10:41:19 AM9/26/16
to Ansible Project
Thank you,

We might use many inventory files, depending on DEV, REC and PROD environments.
I did correct the inventory file, instead of setting [USER1_DEV1:vars], I did add an alias:
[USER1_DEV1]
USER1_DEV1 PARAM="[app1','1.0.1','1']"

so when running the ansible-playbook to list the different hosts, the list contains only the more detailed ones USER1_DEV1, USER2_DEV1 ....

Regards
Reply all
Reply to author
Forward
0 new messages