How to build Ansible inventory file

31 views
Skip to first unread message

Xinhuan Zheng

unread,
Feb 13, 2020, 4:46:35 PM2/13/20
to Ansible Project
Hello,

I need to build Ansible inventory files, but somehow got stuck. Typically for a service, there is development, staging and production. Initially, I thought I can create 3 inventory files with those names. Later I feel it may not be the case. As I look at this Ansible document: https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#example-group-by-function, it actually lists (3) grouping methods, by environment, by functions, and by locations. Can I have a inventory file that is both grouped by environment and by functions? It seems not possible. For example, consider the following inventory file named as myservices:

[development]
testwebserver1
testwebserver2
testloadbalancer1

[production]
webserver1
webserver2
loadbalancer1

[myservices:children]
development
production

If the inventory file is development or production, that means it would include all other services and it will become a big inventory file, and playbook will be hard to write to manage all kinds services, for example, development inventory file:

[myservice1]
testwebserver1
testwebserver2

[myservice2]
testwebserver3
testwebserver4

[load_balancers]
loadbalancer1

[development:children]
myservice1
myservice2
load_balancers

Is it a good practice to break down one big inventory file containing a lot of services into inventory files just for that service like the first one?

Thank you,

- Xinhuan Zheng

Xinhuan Zheng

unread,
Feb 26, 2020, 3:18:29 PM2/26/20
to Ansible Project
Hello All,

I'm still patiently waiting for someone to give me some hint on below questions. Thanks

- Xinhuan Zheng
Reply all
Reply to author
Forward
0 new messages