In v2.4.x.x how can I include host groups in one inventory file to another? If so how?

29 views
Skip to first unread message

ZillaYT

unread,
Dec 5, 2017, 11:42:57 AM12/5/17
to Ansible Project
Say I have inventory files that look like this

host_vars/bitbucket_servers
-------------------------------------
[bb-cluster1]
www
.bb-loc1.domain.com
www
.bb-loc2.domain.com

host_vars
/gerritt_servers
---------------------------------
[gerritt-cluster1]
www
.gerritt-loc1.domain.com
www
.gerritt-loc2.comain.com

host_vars
/jira_servers
[jira-cluster1]
www
.jira-loc1.domain.com
www
.jira-loc2.comain.com


How can I configure a host_vars file to include ALL the hosts in host_vars/bitbucket_servers and host_vars/gerritt_servers, but NOT host_vars/jira_servers for example?

Larry Smith

unread,
Dec 6, 2017, 12:15:49 AM12/6/17
to Ansible Project
Why not just create one inventory like below?

/inventory/hosts.inv
[bb-gerrit-cluster:children]
bb
-cluster1
gerrit
-cluster1

[bb-cluster1]
www
.bb-loc1.domain.com
www
.bb-loc2.domain.com

[gerritt-cluster1]
www
.gerritt-loc1.domain.com
www
.gerritt-loc2.comain.com

[jira-cluster1]
www
.jira-loc1.domain.com
www
.jira-loc2.comain.com

And then create your folder structure like:
inventory/
inventory/hosts.inv
inventory/group_vars/
inventory/group_vars/bb-cluster1
inventory/group_vars/gerritt-cluster1
inventory/group_vars/jira-cluster1
inventory/host_vars
inventory/host_vars/xxxxxxxx

Not sure if this would meet your requirements but this would be much cleaner IMHO. But maybe not? As I am not sure what your requirements are.

ZillaYT

unread,
Dec 6, 2017, 4:16:07 AM12/6/17
to Ansible Project
Definitely a single inventory file is NOT what I want/need, but thanks.

Larry Smith

unread,
Dec 6, 2017, 10:49:15 AM12/6/17
to Ansible Project
Cool. No worries. However, I would be interested in hearing your use case. Always interesting to hear others perspective on how to use inventory, group vars, and host vars.

ZillaYT

unread,
Dec 6, 2017, 11:08:34 AM12/6/17
to Ansible Project
In my case, I have different servers represented in their respective inventory files - bitbucket, gerrit, atlassian, etc. I need to set up group variables that are common to some, but NOT all.
Reply all
Reply to author
Forward
0 new messages