How to install Ansible on Ubuntu 22.04

Ansible is an open-source software provisioning, configuration management, and application deployment tool enabling infrastructure as code. It runs both on Unix-like systems and on Windows platforms.

Ansible is a radically simple IT automation engine that automates cloud provisioning, configuration management, application deployment, intra-service orchestration, etc.

Ansible uses no agents and no additional custom security infrastructure. It is easy to deploy because it uses YAML file systems that allow you to describe your deployment environment in plain English.

It is an agentless automation tool installed on a single host called a control node. It is from the control node that Ansible starts managing the entire machine called managed nodes via remote SSH controls.

Requirements to run Ansible

  • Unix machine with Python 3.8 or newer.
  • User with sudo privileges

Installing Ansible on Ubuntu 22.04

1. Run system updates

To begin with we need to run system updates in order to make our repositories up to date. Open your terminal and type in the following code.

$ sudo apt update && apt upgrade -y

When updates are complete, move forward to install pip.

2. Install Pip

If pip is not already installed, we can do install it with the following command;

$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

After you have finished bootstrapping pip then run the following;

$ python3 get-pip.py --user

You will get the following output.

Output
Collecting pip
  Downloading pip-22.1.2-py3-none-any.whl (2.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 36.0 MB/s eta 0:00:00
Collecting wheel
  Downloading wheel-0.37.1-py2.py3-none-any.whl (35 kB)
Installing collected packages: wheel, pip
 
Successfully installed pip-22.1.2 wheel-0.37.1

Once pip is installed then it’s time for us to install Ansible.

3. Installing Ansible with pip

Install Ansible with the following command;

$ sudo python3 -m pip install --user ansible

Sample output you will get.

Output
Collecting ansible
  Downloading ansible-6.0.0-py3-none-any.whl (40.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 40.3/40.3 MB 29.7 MB/s eta 0:00:00
Collecting ansible-core~=2.13.0
  Downloading ansible_core-2.13.1-py3-none-any.whl (2.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 55.3 MB/s eta 0:00:00
Requirement already satisfied: PyYAML>=5.1 in /usr/lib/python3/dist-packages (from ansible-core~=2.13.0->ansible) (5.4.1)
Collecting packaging
  Downloading packaging-21.3-py3-none-any.whl (40 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 40.8/40.8 kB 79.3 kB/s eta 0:00:00
Requirement already satisfied: jinja2>=3.0.0 in /usr/lib/python3/dist-packages (from ansible-core~=2.13.0->ansible) (3.0.3)
Requirement already satisfied: cryptography in /usr/lib/python3/dist-packages (from ansible-core~=2.13.0->ansible) (3.4.8)
Collecting resolvelib<0.9.0,>=0.5.3
  Downloading resolvelib-0.8.1-py2.py3-none-any.whl (16 kB)
Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /usr/lib/python3/dist-packages (from packaging->ansible-core~=2.13.0->ansible) (2.4.7)
Installing collected packages: resolvelib, packaging, ansible-core, ansible
Successfully installed ansible-6.0.0 ansible-core-2.13.1 packaging-21.3 resolvelib-0.8.1

To upgrade Ansible to a newer version, We upgrade the command on our terminal.

$ python3 -m pip install --upgrade --user ansible

Check the version of the installed version.

$ python3 -m pip show ansible
# output
Name: ansible
Version: 6.0.0
Summary: Radically simple IT automation
Home-page: https://ansible.com/
Author: Ansible, Inc.
Author-email: [email protected]
License: GPLv3+
Location: /root/.local/lib/python3.10/site-packages
Requires: ansible-core
Required-by: 

Installing Ansible via PPA packages

Ansible Ubuntu builds are available in PPA repositories.

First Run system updates on your system.

$ sudo apt update 

1. Install prerequisites

We need to install Ansible prerequisites to aid in the installation of Ansible. Run the following command;

$ sudo apt install software-properties-common

2. Add PPA Repository to Ubuntu 22.04

To add the Ubuntu PPA repository to our system, run the following command on your terminal.

$ sudo add-apt-repository --yes --update ppa:ansible/ansible

Then run updates again

3. Install Ansible on Ubuntu 22.04

Run the following command on your terminal to install Ansible.

$ sudo apt install ansible

Press Y to allow installation to continue, dependencies will be installed in the process.

We can check the version with the following command;

$ python3 -m pip show ansible
output
Name: ansible
Version: 6.0.0
Summary: Radically simple IT automation
Home-page: https://ansible.com/
Author: Ansible, Inc.
Author-email: [email protected]
License: GPLv3+
Location: /root/.local/lib/python3.10/site-packages
Requires: ansible-core
Required-by: 

Uninstall Ansible

If you will like to remove ansible use the following command.

$ sudo apt remove ansible

It will remove Ansible with its all dependencies.

Conclusion

We have successfully installed Ansible in our Ubuntu 22.04. Continue learning more with Ansible documentation.

About Mason Kipward

I am a technology enthusiast who loves to share gained knowledge through offering daily tips as a way of empowering others. I am fan of Linux and all other things open source.
View all posts by Mason Kipward →

Leave a Reply

Your email address will not be published.