How to Create a New Ansible Inventory

In this short blog post, I will show you how to create a new Ansible inventory file and add hosts into.


By default, Ansible comes with an inventory file called hosts that is located in the following path on the server you install Ansible. The file also shows us how to group hosts.


Create a new Inventory

To create a new inventory file, I can either create in the /etc/ansible or somewhere also. Let’s create a new inventory file addcservers which will hold my Windows domain controllers. In my case, I will use the nano text editor.

nano addcservers

The inventory file will look like:


To test that the inventory file is working OK, I will use a ping test as shown below. Just note that because I have Windows hosts, I use the win_ping module. If your managed hosts are Linux use ping.

ansible dc -i addcservers -m win_ping

If you have a playbook that you would like to run the inventory file on using the following command (-i and the path to the file).

ansible-playbook -i addcservers file.yaml