Step 13:
Create An Inventory File
ANSIBLE has a default inventory file used to designate which servers it will be managing. The location is located at /etc/ansible/hosts.
The inventory file can configured be in differentyformats, depending on what inventory plugins you have installed. In this example, the format for /etc/ansible/hosts is similar to an INI which is one of the default formats for ANSIBLE. In the image below we have defined some groups and in each group there are some servers to manage.
****Note:
Groups must be enclosed with brackets in the hosts file.
In the screenshot below we have created 3 groups:
1.) [application]
2.) [databasegroup]
3.) [redhat8]
In the application group [application] we have 1 server with an ip address of 3.17.167.81.
In the database group [databasegroup] we also have 1 server with an ip of 18.22.229.199.
In the redhat 8 group [redhat8] we have 2 server to manage with 2 ip addresses
3.17.167.81 and 18.224.229.199.
Notice how the last group [redhat8] has an ip of 3.17.167.81 and 18.224.229.199 inside of it.
This is to illustrate that servers can be part of multiple groups.
For instance a server could be both a webserver and in a specific datacenter. For example, you could create groups that track:
What - It could be an application or a microservice in Docker or Kubernetes.
For example: database servers, web servers, application servers etc.
Where - A specific datacenter or region.
For example: north, south, east, west.
When - Different stages of cic/cd, to avoid testing on resources.
For example: dev, prod, test.