Javatpoint Logo
Javatpoint Logo

Ansible Inventory

Ansible works against multiple managed hosts in your infrastructure at the same time, using a list or group of lists is known as the inventory.

Once an inventory is defined, you use patterns to select the hosts or groups you want to run against to Ansible.

The default location for inventory is a file called /etc/ansible/hosts. You can also specify a different inventory file at the command line using the -i <path> option. You can pull the inventory file from dynamic or cloud sources or different formats (YAML, ini). Ansible has inventory plugins to make it flexible and customize.

Hosts and group

The format is /etc/ansible/ hosts are in INI like format, such as:

Heading in the brackets is a group name, which is used in classifying the systems. And deciding what policy you are controlling at what time and for what purpose. You can put the systems in more than one group.

For example, a server could be both a dbserver and a webserver.

If you have hosts that run on a non-standard SSH port, then you can put the port number after the hostname with the colon. The Ports listed in the SSH configuration file that can be used with the OpenSSH connection but not use with the paramiko connection.

To makes things explicit, it is suggested that you set them if items are not running on the default ports:

Suppose you have static IPs and want to set up some aliases that live in your host file, or you can connect through tunnels. Also, you can describe the hosts like the below example:

In the above example, trying to Ansible against the host alias "jumper" will connect 192.0.2.50 on port 5555. It is using features of the inventory file to define the special variables.

Hosts Variables

You can assign the variables to the hosts that will be used in playbooks, such as:

Group Variables

The variables can be applied to an entire group at once, such as:

Groups of Groups and Group Variables

It is possible to make groups of the group using the :children's suffix. And you can apply variables using :vars.


Next TopicAnsible Debug





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA