# How to build Ansible inventory file

**URL:** <https://forum.ansible.com/t/how-to-build-ansible-inventory-file/32227>\
**Category:** Ansible Project\
**Created:** [February 13, 2020, 9:46pm UTC](https://forum.ansible.com/t/how-to-build-ansible-inventory-file/32227 "2020-02-13T21:46:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xinhuan\_Zheng](https://avatars.discourse-cdn.com/v4/letter/x/a88e57/32.png) [@Xinhuan\_Zheng](https://forum.ansible.com/u/Xinhuan_Zheng)\
**Post date:** [February 13, 2020, 9:46pm UTC](https://forum.ansible.com/t/how-to-build-ansible-inventory-file/32227/1 "2020-02-13T21:46:35Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![Xinhuan\_Zheng](https://avatars.discourse-cdn.com/v4/letter/x/a88e57/32.png) [@Xinhuan\_Zheng](https://forum.ansible.com/u/Xinhuan_Zheng)\
**Post date:** [February 26, 2020, 8:18pm UTC](https://forum.ansible.com/t/how-to-build-ansible-inventory-file/32227/2 "2020-02-26T20:18:28Z")

</div>

Hello All,

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

- Xinhuan Zheng
