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
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py --user
#Example Output
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2224k 100 2224k 0 0 3259k 0 --:--:-- --:--:-- --:--:-- 3256k
Collecting pip
Downloading pip-24.1.1-py3-none-any.whl.metadata (3.6 kB)
Downloading pip-24.1.1-py3-none-any.whl (1.8 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.8/1.8 MB 4.5 MB/s eta 0:00:00
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 23.2.1
Uninstalling pip-23.2.1:
Successfully uninstalled pip-23.2.1
If you are using an older version of Python, use
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
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
sudo useradd ansible
sudo passwd ansible
You should see this output:
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:
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:
ansible ALL=(ALL:ALL) ALL
- Next log in as the ansible user with the password created above
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:
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.
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:
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.
2 Responses
[…] Ansible Script to pull all this information from your AWS Account […]
[…] 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. […]