Ansible Installation Guide on RHEL/CentOS 8


Ansible Tutorial

There are different methods using which you can install ansible

  • Using default package manager such as yum, dnf, apt etc
  • Using pip
  • Using source compile file

 

Install using package manager on RHEL 8

First register your system to RHSM:

~]# subscription-manager register

Attach your Red Hat Ansible Engine subscription. This command will help you find the Red Hat Ansible Engine subscription:

~]# subscription-manager list --available

Grab the pool id of the subscription and run the following:

~]# subscription-manager attach --pool=<pool id>

Enable the Red Hat Ansible Engine Repository:

~]# subscription-manager repos --enable ansible-VERSION-for-rhel-8-x86_64-rpms

To subscribe to ansible 2.9 repository:

~]# subscription-manager repos --enable ansible-2.9-for-rhel-8-x86_64-rpms

Install Ansible Engine using default package manager:

~]# dnf -y install ansible

 

Install using package manager on CentOS 8

If you are on CentOS 8 then you will need access to respective EPEL repository

[root@server ~]# dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm -y

This will install and enable EPEL repository

~]~]# dnf repolist
repo id                         repo name
AppStream                       CentOS-8 - AppStream
BaseOS                          CentOS-8 - Base
epel                            Extra Packages for Enterprise Linux 8 - x86_64
epel-modular                    Extra Packages for Enterprise Linux Modular 8 - x86_64
extras                          CentOS-8 – Extras

Search for the ansible package in the available repository.

~]# dnf search ansible
Last metadata expiration check: 1 day, 21:16:38 ago on Thu 17 Sep 2020 01:25:51 PM IST.
===================================== Name Exactly Matched: ansible =====================================
ansible.noarch : SSH-based configuration management, deployment, and task execution system

Install ansible using the default package manager

~]# dnf install -y ansible

Check the version of ansible

[root@controller ~]# ansible --version
ansible 2.9.13
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /bin/ansible
  python version = 3.6.8 (default, Apr 16 2020, 01:36:27) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]

 

Install using pip

NOTE:
These steps are provided here only for reference purpose, our controller nodes will be installed via DNF package manager.

Ansible can be installed with pip, the Python package manager. If pip isn’t already available on your system of Python, run the following commands to install it:

~]# dnf -y install python3 python3-pip

Check the version of pip3

~]# pip3 --version
pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)

Login as a normal user as root user cannot be used to install ansible with pip. Next as normal user initiate the installation process:

[deepak@centos8-2 ~]$ pip3 install ansible --user 
Collecting ansible
  Downloading https://files.pythonhosted.org/packages/32/62/eec759cd8ac89a866df1aba91abf785 486fed7774188a41f42f5c7326dcb/ansible-2.9.13.tar.gz (14.3MB)
    100% |████████████████████████████████| 14.3MB 36kB/s
Collecting jinja2 (from ansible)
  Downloading https://files.pythonhosted.org/packages/30/9e/f663a2aa66a09d838042ae1a2c5659828bb9b41ea3a6efa20a20fd92b121/Jinja2-2.11.2-py2.py3-none-any.whl (125kB)
    100% |████████████████████████████████| 133kB 1.1MB/s

<output trimmed>

Installing collected packages: MarkupSafe, jinja2, ansible
  Running setup.py install for ansible ... done
Successfully installed MarkupSafe-1.1.1 ansible-2.9.13 jinja2-2.11.2

Check the ansible version

 ~]$ ansible --version
ansible 2.9.13
  config file = None
  configured module search path = ['/home/deepak/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/deepak/.local/lib/python3.6/site-packages/ansible
  executable location = /home/deepak/.local/bin/ansible
  python version = 3.6.8 (default, Nov 21 2019, 19:31:34) [GCC 8.3.1 20190507 (Red Hat 8.3.1-4)]

 

What's Next

Next in our Ansible Tutorial we will configure Ansible in our lab environment

 

Deepak Prasad

Deepak Prasad

He is the founder of GoLinuxCloud and brings over a decade of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels in various domains, from development to DevOps, Networking, and Security, ensuring robust and efficient solutions for diverse projects. You can connect with him on his LinkedIn profile.

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can send mail to admin@golinuxcloud.com

Thank You for your support!!

Leave a Comment