Would you like to learn how to do an Ansible installation on Ubuntu Linux? In this tutorial, we are going to show you how to install Ansible on a computer running Ubuntu Linux.

• Ubuntu 18.04
• Ubuntu 19.04
• Ansible 2.8.6

Hardware List:

The following section presents the list of equipment used to create this Ansible tutorial.

Every piece of hardware listed above can be found at Amazon website.

Ansible Related Tutorial:

On this page, we offer quick access to a list of tutorials related to Ansible.

Tutorial - Ansible Installation on Ubuntu Linux

Install the list of required packages.

Copy to Clipboard

Add the official Ansible repository to your APT database

Copy to Clipboard

Install Ansible.

Copy to Clipboard

Verify the Ansible version installed.

Copy to Clipboard

As an example, here is our output.

Copy to Clipboard

In our example, we installed Ansible on a computer using the IP address: 192.168.15.13

Create a local user account named ansible.

Copy to Clipboard

Use the SU comand to become the Ansible user.

Generate a SSH key to the Ansible user account.

Copy to Clipboard

Exit the local Ansible user account.

Copy to Clipboard

Edit the Ansible hosts file and add the list of desired Ansible nodes.

Copy to Clipboard

Edit the Ansible hosts file and add the list of desired Ansible nodes.

Copy to Clipboard

In our example, we add only 1 Ansible node using the IP address 192.168.15.12.

We created a group of Ansigle hosts named test.

On the command-lise of your Ansible node, create a user account named Ansible.

Copy to Clipboard

Don't forget to set a password for the Ansible user account.

Copy to Clipboard

On the Ansible node, edit the SUDOERS configuration file

Copy to Clipboard

Add the following line at the end of the SUDOERS file.

Copy to Clipboard

Go back to the Ansible server command-line.

Use the ssh-copy-id command to copy the Ansible user account SSH key from the server to the node.

Copy to Clipboard

In our example, 192.168.15.12 is the IP address of the Ansible node.

Copy to Clipboard

Now, from the Ansible server, try to login on the Ansible node.

You will need to enter the SSH key password.

Copy to Clipboard

Logoff from the Ansile node and go back to the Ansible server.

Copy to Clipboard

On the Ansible server console, test the communication with the Ansible nodes.

Copy to Clipboard

Here is the command output:

Copy to Clipboard

On the Ansible server console, use the following command to get the Uptime of all Ansible nodes.

Copy to Clipboard

Here is the command output:

Copy to Clipboard

Congratulations! You have finished the Ansible installation on Ubuntu Linux.

Tutorial - Ansible Playbook Example

On the Ansible server, become the Ansible user.

Copy to Clipboard

Create an Ansible playbook.

Copy to Clipboard

Here is the content of the Ansible playbook named: playbook-test.yaml

Copy to Clipboard

In our example, the Ansible server will install the NTPDATE package using APT-GET on all hosts.

Use the following command to run your playbook.

Copy to Clipboard

Here is the playbook output.

Copy to Clipboard

Congratulations! You created an Ansible playbook successfully.