How to Install and Configure Ansible on RHEL 8 / CentOS 8

Cpanel/Whm License $3/mo Plesk License $10/mo Cloudlinux License $5/mo

(: September 25, 2019)

You want to install and configure Ansible on CentOS 8 / RHEL 8?. Ansible is the leading Open Source configuration management system. It makes it easy for administrators and operations teams to control thousands of servers from cental machine without installing agents on them.

Ansible is the simplest to use and manage when compared to other configuration management systems such as Puppet, Chef and Salt. It is easy to install, learn, and use. The only dependency required on the remote server is SSH service and Python.

Install Ansible on RHEL 8 using the steps below.

.td_uid_2_5d906449bc402_rand.td-a-rec-img{text-align:left}.td_uid_2_5d906449bc402_rand.td-a-rec-img img{margin:0 auto 0 0}

Step 1: Install Python on RHEL 8 . CentOS 8

Install and Set your default Python on RHEL 8 using the guide below.

How to Install Python 3 / Python 2.7 on RHEL 8

Once it has been installed, proceed to install Pip which is a Python package manager used to install Ansible.

If you’re using Python3, install python3-pip package.

sudo dnf -y install python3-pip
sudo pip3 install --upgrade pip

For Python2 users you have to install python2-pip

sudo dnf -y install python2-pip
sudo pip2 install --upgrade pip

Step 2: Install Ansible on RHEL 8

Once you have Pip installed, use it to get Ansible installed in your RHEL 8 machine.

$ pip3 install ansible --user

For Python2 pip, use:

$ pip2 install ansible --user

You can see Ansible installed using the following command:

$ ansible --version
ansible 2.7.5
config file = None
configured module search path = ['/home/jmutai/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/jmutai/.local/lib/python3.6/site-packages/ansible
executable location = /home/jmutai/.local/bin/ansible
python version = 3.6.6 (default, Oct 16 2018, 01:53:53) [GCC 8.2.1 20180905 (Red Hat 8.2.1-3)]

Testing Ansible on CentOS 8 / RHEL 8

To test Ansible, you should have OpenSSH service running on the remote server.

$ sudo systemctl status sshd
● sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2018-12-29 20:17:11 EAT; 39min ago
Docs: man:sshd(8)
man:sshd_config(5)
Main PID: 820 (sshd)
Tasks: 1 (limit: 11510)
Memory: 4.6M
CGroup: /system.slice/sshd.service
└─820 /usr/sbin/sshd -D [email protected],[email protected],aes256-ctr,aes256-cbc,[email protected],aes128->
Dec 29 20:17:11 rhel8.local systemd[1]: Starting OpenSSH server daemon…
Dec 29 20:17:11 rhel8.local sshd[820]: Server listening on 0.0.0.0 port 22.
Dec 29 20:17:11 rhel8.local sshd[820]: Server listening on :: port 22.
Dec 29 20:17:11 rhel8.local systemd[1]: Started OpenSSH server daemon.
Dec 29 20:19:03 rhel8.local sshd[1499]: Accepted publickey for jmutai from 192.168.122.1 port 35902 ssh2: RSA SHA256:b/8AoYgbThoBYPcFh7CetJuGY/Tl7s4fi>
Dec 29 20:19:03 rhel8.local sshd[1499]: pam_unix(sshd:session): session opened for user jmutai by (uid=0)

Create Ansible inventory file, default is /etc/ansible/hosts

I like creating inventory file in my working directory.

$ vim hosts

Copy the IP address of your remote server(s) to manage and add to Ansible inventory file.

$ echo "192.168.122.197" > hosts

You can also create a group of hosts like below:

[web]
192.168.122.197

[db]
192.168.122.198

[staging]
192.168.122.199
192.168.122.200
192.168.122.201

Generate SSH key and copy it to remote servers.

$ ssh-keygen
$ ssh-copy-id [email protected]192.168.122.197

Use ping module to test ansible:

$ ansible  -i hosts  192.168.122.197 -m ping  
192.168.122.197 | SUCCESS => {
"changed": false,
"ping": "pong"
}

The -i option is used to provide path to inventory file. You should get the same output for hosts group name.

$ ansible  -i hosts  web -m ping  
192.168.122.197 | SUCCESS => {
"changed": false,
"ping": "pong"
}

For commands that need sudo, pass the option --ask-become-pass. This will ask for privilege escalation password. This may require installation of the sshpass program.

$ ansible  -i hosts  web -m command -a "sudo yum install vim"  --ask-become-pass
....

192.168.122.197 | CHANGED | rc=0 >>
 Updating Subscription Management repositories.
 Updating Subscription Management repositories.
 Last metadata expiration check: 0:52:23 ago on Sat 29 Dec 2018 08:28:46 PM EAT.
 Package vim-enhanced-2:8.0.1763-7.el8.x86_64 is already installed.
 Dependencies resolved.
 Nothing to do.
 Complete!

You now have Ansible installed on RHEL 8 / CentOS 8 server or Workstation. You can learn more on using Ansible to Manage your servers from Official Ansible documentation.

More on Ansible:

How To Install Ansible AWX on Ubuntu 18.04 / Debian 10

Ansible Vault Cheat Sheet / Reference guide

How to automate simple repetitive tasks using Ansible

How To Install speedtest-cli on Ubuntu / CentOS / Debian using Ansible

.td_uid_4_5d906449bc603_rand.td-a-rec-img{text-align:left}.td_uid_4_5d906449bc603_rand.td-a-rec-img img{margin:0 auto 0 0}

Related posts

Coinplug’s $2.5 Million Funding Round Reveals Bitcoin Growth in Korea

SXI ADMIN

R3’s Newest Regulator Looks to DLT For KYC Testing

SXI ADMIN

Bitcoin Proves Just the Tonic for London Gin Distillery

SXI ADMIN

A Possible Digital Currency Scam is Using JPMorgan’s Branding

SXI ADMIN

Twitter Pledges Action on Crypto Scams After Account Bans

SXI ADMIN

Rand Paul Accepts Bitcoin for Presidential Campaign

SXI ADMIN

8,000 Convenience Stores in Argentina Now Sell Bitcoin

SXI ADMIN

Maryland Bills Call for Study, Possible Regulation of Blockchain

SXI ADMIN

Watch: Jesse Ventura Moderates Colorado Governor Candidates in Bitcoin Debate

SXI ADMIN

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More