You can Watch all our Tutorials and Training Videos on our YouTube Channel for Free! Subscribe Now! & Free Web Tools available on

Ansible Inventory Introduction - Ansible Beginner Tutorials

ansible tutorials, ansible inventory tutorials, ansible inventory management, ansible inventory examples, ansible inventory explained
This tutorial explains you about the basics of Ansible Inventory, At the end of this tutorial you will be able to understand What is Ansible Inventory, how to change or create a new inventory rather than using the default inventory, how to define the hosts and host groups.

Ansible Inventory Introduction - Ansible Beginner Tutorials

Lets get started.

Ansible Inventory Management - Ansible Tutorials for Beginners

What is Ansible Inventory?

Ansible is an automation tool which works for multiple systems in a infrastructure at the same time. So we should have system lists to manage it. we call that as a inventory. Ansible inventory file has the list of all managed host names one line per host. Inventory management is also important factor in Ansible.

Note : You can define your host names in ipaddress or hostname or fqdn.

By default, this ansible host inventory file is located under /etc/ansible/hosts. Hence if you run a Ansible Playbook or Ansible Ad-hoc commands, that will look the hosts groups under the default file. You can specify a different inventory file using the "-i <path>" option on the command line as shown below.

ansible-playbook -i /root/database_servers install.yml

But remember, We must enable password less SSH authentication between ansible master server host and client hosts, else you would get an error as "Failed to connect to the host via ssh: Permission denied". Refer this link to know how to Configure SSH Passwordless Login Authentication


Hosts Groups Declaration

You can declare the different groups in single host inventory file. For example, If you have database and web servers, then we can declare the list of server names under each groups.



Also, you can simplify the decalarion more, if you have similar hostname starts with same characters.



Either in alphabetic format or numeric format.

Note : A host can be in more than one group.

Inventory File Parameters

By default, Ansible works on SSH port number 22. if you have different port to connect the hosts, then define the hosts as below.

You can also define the connection type and also user depend on the target hosts:

[webservers]     ansible_connection=ssh        ansible_user=mjohn     ansible_connection=ssh        ansible_user=peter

As shown above, some of the ansible parameters mentioned below can be used on need and these are commonly used parameters. You can get more parameters from

Host connection:

Connection type to the host. This can be the name of any of ansible’s connection plugins. SSH protocol types are smart, ssh or paramiko. The default is smart.

General for all connections:

The name of the host to connect to, if different from the alias you wish to give to it.

The ssh port number, if not 22

The default ssh user name to use.

Specific to the SSH connection:

The ssh password to use (never store this variable in plain text; always use a vault)

Private key file used by ssh. Useful if using multiple keys and you don’t want to use SSH agent.

This setting is always appended to the default command line for sftp, scp, and ssh. Useful to configure a ProxyCommand for a certain host (or group).

This setting is always appended to the default sftp command line.

This setting is always appended to the default scp command line.

This setting is always appended to the default ssh command line.

Determines whether or not to use SSH pipelining. This can override the pipelining setting in ansible.cfg.

ansible_ssh_executable (added in version 2.2)
This setting overrides the default behavior to use the system ssh. This can override the ssh_executable setting in ansible.cfg.

Privilege escalation

Equivalent to ansible_sudo or ansible_su, allows to force privilege escalation

Allows to set privilege escalation method

Equivalent to ansible_sudo_user or ansible_su_user, allows to set the user you become through privilege escalation

Equivalent to ansible_sudo_pass or ansible_su_pass, allows you to set the privilege escalation password (never store this variable in plain text; always use a vault.)

Equivalent to ansible_sudo_exe or ansible_su_exe, allows you to set the executable for the escalation method selected

Equivalent to ansible_sudo_flags or ansible_su_flags, allows you to set the flags passed to the selected escalation method. This can be also set globally in ansible.cfg in the sudo_flags option

Hope you have got an idea about Ansible Inventory. Going forward, we will play more with ansible tool with some test cases.
Support Us: Share with your friends and groups.

Stay connected with us on social networking sites, Thank you.

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.