How To - Install Ansible on Ubuntu for Managing AWS

AWS like other cloud service providers (CSPs) offer multiple management options. Most users start with the AWS GUI console. It’s flexible and provides clear access to most of the capabilities the platform provides. The GUI is great, but probably best for infrequently used tasks and for becoming familiar with new services. Advanced users tend to grow past the GUI for certain tasks that need to be run often or repeatedly.

Automating actions is usually best handled at the command line. Here, either the AWS command line interface (CLI), or third party tools such as Ansible and Terraform can be used. Scripted commands are often very friendly and easily consumable by Continuous Integration / Continuous Deployment (CI/CD) tools. There are number of these tools such as Jenkins, GitLab, and even AWS’ own CodePipeline applications among others.

To use Ansible with AWS, a few companion apps need to be installed along with it.

Ansible is written in the Python programming language. Because of that, Python and supporting tools need to be installed. The Ansible documentation says the following packages are needed : Python version 2.6 or higher and Boto. Boto is the AWS Software Development Kit (SDK) for python. This guide opts to use the newer versions of those packages. Specifically, version 3.x. Pip (Package Installer for Python) also gets installed and is used to bring in Ansible itself.

Requirements:

  • Python3

  • Pip3

  • Boto + Boto3

Ansible:

  • Ansible

Install Python3 and Python-Pip3. Pip3 will be called in the next step to install Boto, Boto3, and Ansible.

sudo apt install python3
sudo apt install python-pip3
Blog-Post_Ansible_Install_on_Ubuntu_Python3_and_Pip3-Screen Shot 2020-07-03 at 11.20.15 PM.png

Install Boto, Boto3, and Ansible, The install is achieved via one line.

pip3 install boto boto3 ansible
Blog-Post-Anible-Install_on_Ubuntu_boto_boto3_ansible-Screen Shot 2020-07-03 at 11.27.27 PM.png

Verify that Ansible is installed and can be called.

ansible —version
Blog-Post-Ansible-Install-Verify_ansible_version-Screen Shot 2020-07-03 at 11.36.04 PM.png

At this point Ansible should be ready to use.

References

https://docs.ansible.com/ansible/latest/modules/ec2_module.html

https://mindbowser.com/how-to-create-ec2-instances-using-ansible/

https://boto3.amazonaws.com/v1/documentation/api/latest/index.html

https://pip.pypa.io/en/stable/