Easy Way to Install Ansible on Linux

What is the easiest way to install Ansible on Linux?

Ansible is a powerful open-source automation tool that helps sysadmins manage and configure systems quickly and easily. It’s one of the most popular automation tools out there, and for a good reason – it’s easy to use and delivers powerful results.

This article shows you how to install Ansible on Linux versions using PIP. We’ll also show you how to configure Ansible and use it to automate system administration tasks.

If you use Ansible from the official Red Hat or CentOS repositories, you may have noticed that the Ansible revision available via Yum is significantly outdated. Take Red Hat 7, for example; not a very old version of Red Hat, but certainly not the newest. If you install Ansible via the official rhel-7-server-extras-beta-rpms repo, you get version ansible-2.3.0.0-4.el7.noarch

What is the latest version of Ansible?

At the time of writing, the latest version of Ansible is 4.10.0 (much more up-to-date than 2.3.0)

How do I Install Python PIP?

Python is a high-level programming language that lets you create sophisticated software programs. Pip is a package management tool for Python that makes it easy to install and manage software packages. Pip is included with the Python installation, so you can install and manage software packages using the command line.

Step 1 – Install Python PIP

If you are using Python3.6 or above, use

Bash
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py --user

If you are using an older version of Python use

Bash
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
python get-pip.py --user

You should receive a message like this

Successfully installed pip-20.3.4 setuptools-44.1.1 wheel-0.37.1

Step 2 – Install Ansible

Now use PIP to install the latest version of Ansible

Bash
python -m pip install --user ansible

Depending on your system, it may take a few minutes to install. The installation will look something like this:

Thats it! You are now ready to start experimenting with Ansible on your Linux System. Have Fun.

Step 3 – Create an Ansible User ID

An Ansible system account can be set up to use no password

Bash
 sudo useradd ansible
 sudo passwd ansible

You should see this output:

Bash
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

Step 4 – Add user to the sudoers file

Adding your ansible user account to the sudoers makes administration a lot easier

  • Open the sudoers file using the visudo command:
Bash
sudo visudo

This command opens the sudoers file in a safe manner, preventing syntax errors.

  • In the sudoers file, add the following line to grant sudo privileges to the Ansible user:
Bash
ansible ALL=(ALL:ALL) ALL
  • Next log in as the ansible user with the password created above
Bash
 su ansible

Now you wont be prompted for password every time you run sudo

Then check the ansible config file.

Step 5 – Create and Copy SSH Keys to all Ansible servers

Creating and copying SSH keys to your Ansible servers enables secure and passwordless authentication.

  • Generate SSH Key Pair:
Bash
ssh-keygen -t rsa -b 2048


Follow the prompts to generate a new SSH key pair. Press Enter to accept the default file location.

  • Copy SSH Key to Each Server:

Replace server_ip with the actual IP address of each Ansible server.

Bash
ssh-copy-id ansible@server_ip


This command copies your public SSH key to the specified server, allowing secure logins.

  • Repeat for Each Server:

If you have multiple Ansible servers, repeat the SSH key copying process for each server.

  • Test SSH Authentication:
Bash
ssh ansible@server_ip


Ensure you can log in without a password prompt. Repeat for all servers to confirm key-based authentication.

With SSH keys set up, Ansible can securely communicate with your servers without relying on passwords.

Elsewhere On TurboGeek:  Update (Rotate) RDS SSL Certificates

Richard.Bailey

Richard Bailey, a seasoned tech enthusiast, combines a passion for innovation with a knack for simplifying complex concepts. With over a decade in the industry, he's pioneered transformative solutions, blending creativity with technical prowess. An avid writer, Richard's articles resonate with readers, offering insightful perspectives that bridge the gap between technology and everyday life. His commitment to excellence and tireless pursuit of knowledge continues to inspire and shape the tech landscape.

You may also like...

2 Responses

  1. 14/09/2023

    […] Ansible Script to pull all this information from your AWS Account […]

  2. 25/01/2024

    […] We are going to assume you already have Ansible Installed. If not, you will find a complete guide to Installing Ansible on Linux systems here. […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Translate »