Inventory is a list of nodes, where #202204272036 run against, managed by #202204272021. Ansible has a default inventory file /etc/ansible/hosts
but it could be changed using the option -i
. We could create multiple groups that can contain multiple hosts either in domain name or 202206151453# within an inventory.
Note: Although Inventory could be used to store 202205042134#, it is advised to only define them if they are necessary for device connection such as user password and mean of communication.
A typical Inventory is file-based which could be in INI or YAML format. Some are in a service or in git repository. This is shown as follows:
[webservers] # webservers group
b2bwebprod1 urlpath=https://b2bprod.abc.xyz
b2bwebprod2 ansible_host=10.100.25.3 # set name for IP address 10.100.25.3
b2bwebprod3 ansible_host=10.100.25.4 # set name for IP address 10.100.25.4
[appservers] # appservers group, contains both IP addresses and domain name
10.25.13.25
10.40.12.44
b2bappprod1
b2bappprod2
b2bappprod3
[frontend:children] # parent group for group webservers and appservers
webservers
appservers
b2bslavedb
[webservers:vars] # define group variables for webservers group
server_path=/var/www/html
[all:vars] # define variables for all groups
user_name=ansible
ssh_key=/home/clover/.ssh/ssh.rsa
Note: By default, #202204272021 use Domain Name Server (DNS)# for name lookup. This could be circumvented by using the option ansible_host
where custom name is assigned to an IP address.
Note: Using keyword children
after the group name impose a hierarchy of groups. Such group can contain both groups and hosts.
Note: Using keyword vars
after the group name define group variables which are only able to be used for that group. However, if the name before the keyword is all
, the variables could be used by every group or host in the Inventory.