How to build Ansible inventory file

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

Hello All,

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

  • Xinhuan Zheng