Would you like to learn how to install Ansible on a computer running Ubuntu Linux on the Amazon AWS cloud? In this tutorial, we are going to show you how to create a new account at Amazon AWS, how to create an Ubuntu virtual machine instance and how to perform the Ansible installation on a new virtual machine on the Amazon EC2 cloud.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 - How to Create a Key Pair

To access a Linux Virtual Machine on AWS, first, you need to create a private Key.

Open your browser, access the Amazon AWS website and enter your login information.

After a successful login, you will be sent to the AWS Dashboard.

aws dashboard

Access the COMPUTE menu and select the EC2 option.

amazon aws ec2 menu

On the EC2 Dashboard, access the Network & Security menu and click on the Key Pairs option.

aws key pair menu

On the Key Pairs screen, click on the Create Key Pair button.

create key pair

You will have to enter a name to the new Key Pair.

You will have to save locally your private key.

aws new key pair

In our example, we created a key pair named TEST.

In our example, we saved a file named TEST.PEM.

Tutorial - How to Create an AWS EC2 Ubuntu

On the EC2 Dashboard, access the Instances menu and click on the Instances option.

aws ec2 instances

On the EC2 Instance screen, click on the Launch Instance button.

aws ec2 launch instance

Now, it is time to select the desired Operational system image.

On the list presented, locate and select the Ubuntu Linux image.

aws ubuntu

As the second step, you will have to select the type of virtual machine that will run the Ubuntu Linux.

Basically, you will select the number of processors and the amount of RAM that you want.

aws ec2 vm type

If you do not want to specify the amount of hard disk available to this virtual machine, click on the Review and Launch button.

If you want to specify the amount of hard disk available to this virtual machine, click on the Configure instance detail button.

On the summary screen, click on the Launch button.

aws ec2 launch

Select the Key pair authorized to connect to the new virtual machine and click on the Launch Instances.

In our example, the key pair named TEST was selected.

aws instance keypair

On the EC2 Dashboard, access the Instances menu and click on the Instances option.

As you can see a new virtual machine was created.

aws instances

In our example, the virtual machine got the Dynamic IP address: 34.217.14.140

Tutorial - How to Access an AWS Ubuntu

To access the Linux virtual machine you will have to download the following software:

• Putty

• PuttyGen

First, we need to convert the private key from the PEM format to the PPK format.

Open the PuttyGen software, access the Conversions menu and select the Import key.

putty key generator

After importing the PEM file, you need to set a password to protect your private key.

Click on the Save private key button to generate a file with the PPK extension.

In our example, a file named TEST.PPK was created.

aws puttygen private key

Open the Putty software, select the SSH option and enter the username ubuntu@ followed by the IP address of the AWS virtual machine.

In our example, we used ubuntu@34.217.14.140.

aws putty ssh

Access the SSH authentication tab, click on the Browse button, locate the PPK file and click on the Open button.

aws putty ssh key auth

An SSH connection will be started with your Ubuntu virtual machine.

Use the following command to become the root user on the Ubuntu virtual machine.

Copy to Clipboard

You have successfully created an Ubuntu virtual Machine on Amazon AWS.

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: 20.200.200.200

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

Add the list of desired Ansible nodes.

Copy to Clipboard

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

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, 200.100.100.100 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.