Categories
Network Automation

Ansible: The Inventory file

So whats this “Inventory file” anyway?

The inventory file houses all the info about the hosts you will be managing with Ansible; impossible to do it without one. You can add a bunch of hosts to this thing and manage each of time simultaneously ( depending on how you group your hosts– more on that later). In order to be used within playbooks and templates, you gotta set them up correctly.

Lets begin by opening up your default Ansible inventory:

If it doesn’t exist, then create one.

$ sudo nano /etc/ansible/hosts

If you do have the file, you’ll see number of examples that you can use as references for setting up your inventory; quite helpful, yah?

So lets quickly discuss groups:

It is basically the ability to segment your hosts into specific groups..simple as that.

cali-server ansible_host=192.168.0.12
bos-server ansible_host=192.168.0.15
ny-server ansible_host=192.168.0.17

tx-router ansible_host=192.168.1.17
nj-router ansible_host=192.168.1.18
ca-router ansible_host=192.168.1.19

tx-switch ansible_host=172.0.1.1
nj-switch ansible_host=172.0.1.2
ca-switch ansible_host=172.0.1.3

[databases]
cali-server 
bos-server 
ny-server 

[routers]
tx-router 
nj-router 
ca-router

[switches]
tx-switch 
nj-switch  

The above is pretty self-explanatory. You first create your individual hosts and then group them accordingly.

Hope this helps.