How to Install and Configure ‘Ansible’ Automation Tool for IT Management – Part 1

Step 3: Creating Inventory File for Remote Hosts

Inventory file, This file hold the host information’s like which host we need to get connect from local to remote. Default inventory file will be under /etc/ansible/hosts.

7. Now let’s add these three hosts to inventory file. Open and edit file using your favourite editor, Here I use vim.

# sudo vim /etc/ansible/hosts

Add the following three hosts IP address..


Note: The ‘web-servers‘ in the brackets indicates as group names, it is used in classifying systems and deciding which systems you are going to controlling at what times and for what reason.

Create Ansible Inventory File
Create Ansible Inventory File

8. Now time to check our all 3 server by just doing a ping from my localhost. To perform the action we need to use the command ‘ansible‘ with options ‘-m‘ (module) and ‘-all‘ (group of servers).

# ansible -m ping web-servers


# ansible -m ping -all

Ping Remote Hosts
Ping Remote Hosts

In the above example, we’ve used ping module with Ansible command to ping all remote hosts at ones, the same way there are various modules can be used with Ansible, you can find available modules from ansible Official site here.

9. Now, here we are using another module called ‘command‘, which is used to execute list of commands (like, df, free, uptim, etc.) on all selected remote hosts at one go, for example watch out few examples shown below.

a. To check the partitions on all remote hosts

# ansible -m command -a "df -h" web-servers
Check Disk Space on all Hosts
Check Disk Space on all Hosts

b. Check memory usage on all remote hosts.

# ansible -m command -a "free -mt" web-servers
Check Memory on all Hosts
Check Memory on all Hosts

c. Checking Uptime for all 3 servers.

# ansible -m command -a "uptime" web-servers
Check uptime on all Hosts
Check uptime on all Hosts

d. Check for hostname and Architecture.

# ansible -m command -a "arch" web-servers
# ansible -m shell -a "hostname" web-servers
Check hostname on all Hosts
Check hostname on all Hosts

e. If we need the output to any file we can redirect as below.

# ansible -m command -a "df -h" web-servers > /tmp/df_outpur.txt
Redirect Output to File
Redirect Output to File

Like this way, we can run many shell commands using ansible as what we have run the above steps.


Okay, We can see how to in next article.

Ansible is a Powerful IT automation tool which is must every sysadmins for deploying applications and managing server’s at one go. Among any other automation tool such as puppet, Capistrano, salt, Ansible is quit very interesting and very easy to setup for production environment. Capistrano oh no i feel headache please leave me alone :p this what i used to say.

Ansible use only SSH as there agent. We don’t have to install and run any agent in the remote servers. Hope this article will be interesting one for you too. In our next article, I will show you how to setup the directory structure for Ansible deployment and creating playbooks and working with it.

Till then keep on tracking us to get updated articles and don’t forget to tell us your opinions on the Ansible and also tell us do you use any other automation tool which is more powerful than Ansible….

Reference Links

If you liked this article, then do subscribe to email alerts for Linux tutorials. If you have any questions or doubts? do ask for help in the comments section.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

53 thoughts on “How to Install and Configure ‘Ansible’ Automation Tool for IT Management – Part 1”

  1. I don’t want to use ssh-key for ansible, what I need is I always need to use passwords for each and every commands

    how to configure that?


Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.