How to Install Ansible on Ubuntu 18.04

Install Ansible on Ubuntu 18.04

In this article, we will have explained the necessary steps to install and configure Ansible on Ubuntu 18.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Ansible is a free and open source Configuration and automation tool for UNIX like operating system. It is written in python and similar to Chef or Puppet but there is one difference and advantage of Ansible is that we don’t need to install any agent on the nodes. It uses SSH for making communication to its nodes.

In this article we will demonstrate how to install and configure Ansible in CentOS 7 and will try to manage its two nodes:

  • Ansible Server – ansible.idroot.us ( 192.168.13.33 )
  • Ansible Client – 192.168.100.120

Install Ansible on Ubuntu

Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.

Step 2. Install Anisble on Ubuntu.

We need to enable the ansible repo first. Install the repo with the following command:

After adding the Ansible repository execute below commands to install:

Upon successful installation of Ansible, you can verify the version of ansible installed by running:

Step 3. Setup Password less SSH configuration between ansible server and ansible client.

We need to generate ssh keys on ansible server and copy this key to public key on ansible client:

We can use ssh-copy-id command to copy public key from ansible server to ansible clients:

We need to be check our ansible server and ansible clients is working password less or not? We can check as like below:

Step 4. Ansible server configuration to manage ansible client.

You can make inventory of our ansible server and ansible client using ansible server host file. Host file can be find in this path on ansible server /etc/ansible/host:

Step 5. Manage ansible client from ansible server.

Check the connectivity of ‘test-servers’ or ansible clients using ping:

We can check the uptime of our ansible client from ansible server:

Redirecting the output of command to a file. Like below:

That’s all you need to do to install Ansible on Ubuntu 18.04. I hope you find this quick tip helpful. If you have questions or suggestions, feel free to leave a comment below.