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.

Inventory

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.

/etc/ansible/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:

[dc]
192.168.0.110
192.168.0.111
[dc:vars]
ansible_user=ansible
ansible_password=password
ansible_connection=winrm
ansible_winrm_transport=ntlm
ansible_winrm_server_cert_validation=ignore

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

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.