How to install and configure Ansible on Oracle Linux 9.3

To Install And Configure Ansible On Oracle Linux 9.3

Introduction:

Ansible is an open-source platform for IT configuration management (CM) and automation developed by Red Hat. It uses human-readable YAML templates to automate repetitive tasks without requiring advanced programming skills.

Installation Procedure:

Step 1: Check the Oracle Linux Version by using the below command

[root@linuxhelp ~]# cat /etc/os-release
NAME="Oracle Linux Server"
VERSION="9.3"
ID="ol"
ID_LIKE="fedora"
VARIANT="Server"
VARIANT_ID="server"
VERSION_ID="9.3"
PLATFORM_ID="platform:el9"
PRETTY_NAME="Oracle Linux Server 9.3"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:oracle:linux:9:3:server"
HOME_URL="https://linux.oracle.com/"
BUG_REPORT_URL="https://github.com/oracle/oracle-linux"
ORACLE_BUGZILLA_PRODUCT="Oracle Linux 9"
ORACLE_BUGZILLA_PRODUCT_VERSION=9.3
ORACLE_SUPPORT_PRODUCT="Oracle Linux"
ORACLE_SUPPORT_PRODUCT_VERSION=9.3

Step 2: Update the DNF Package Repository cache with the below command

[root@linuxhelp ~]# sudo dnf makecache
Oracle Linux 9 BaseOS Latest (x86_64)            29 kB/s | 3.6 kB     00:00    
Oracle Linux 9 BaseOS Latest (x86_64)           8.2 MB/s |  21 MB     00:02    
Oracle Linux 9 Application Stream Packages (x86  39 kB/s | 3.9 kB     00:00    
Oracle Linux 9 Application Stream Packages (x86 8.6 MB/s |  29 MB     00:03    
Oracle Linux 9 UEK Release 7 (x86_64)            43 kB/s | 3.0 kB     00:00    
Oracle Linux 9 UEK Release 7 (x86_64)           8.9 MB/s |  28 MB     00:03    
Last metadata expiration check: 0:00:03 ago on Friday 15 March 2024 11:16:53 PM.
Metadata cache created.

Step 3: Enable EPEL Repository, Install the epel-release package with the below command

[root@linuxhelp ~]# dnf install epel-release
Last metadata expiration check: 0:00:30 ago on Friday 15 March 2024 11:16:53 PM.
Dependencies resolved.
================================================================================
 Package                  Arch    Version              Repository          Size
================================================================================
Installing:
 oracle-epel-release-el9  x86_64  1.0-1.el9            ol9_baseos_latest   14 k
Installing dependencies:
 yum-utils                noarch  4.3.0-11.0.1.el9_3   ol9_baseos_latest   53 k
Transaction Summary
================================================================================
Install  2 Packages

Total download size: 67 k
Installed size: 41 k
Is this ok [y/N]: y
Downloading Packages:
(1/2): oracle-epel-release-el9-1.0-1.el9.x86_64 125 kB/s |  14 kB     00:00    
(2/2): yum-utils-4.3.0-11.0.1.el9_3.noarch.rpm  401 kB/s |  53 kB     00:00    
--------------------------------------------------------------------------------
Total                                           490 kB/s |  67 kB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Installing       : yum-utils-4.3.0-11.0.1.el9_3.noarch                    1/2 
  Installing       : oracle-epel-release-el9-1.0-1.el9.x86_64               2/2 
  Running scriptlet: oracle-epel-release-el9-1.0-1.el9.x86_64               2/2 
  Verifying        : oracle-epel-release-el9-1.0-1.el9.x86_64               1/2 
  Verifying        : yum-utils-4.3.0-11.0.1.el9_3.noarch                    2/2 
Installed:
  oracle-epel-release-el9-1.0-1.el9.x86_64  yum-utils-4.3.0-11.0.1.el9_3.noarch 
Complete!

Step 4: Update the DNF package repository cache again with the below command

[root@linuxhelp ~]# dnf makecache
Oracle Linux 9 EPEL Packages for Development (x 9.0 MB/s |  57 MB     00:06    
Oracle Linux 9 BaseOS Latest (x86_64)            48 kB/s | 3.6 kB     00:00    
Oracle Linux 9 Application Stream Packages (x86  54 kB/s | 3.9 kB     00:00    
Oracle Linux 9 UEK Release 7 (x86_64)            41 kB/s | 3.0 kB     00:00    
Metadata cache created.

Step 5: Next install Ansible by using the below command

[root@linuxhelp ~]# dnf install ansible
Last metadata expiration check: 0:01:03 ago on Friday 15 March 2024 11:18:00 PM.
Dependencies resolved.
================================================================================
 Package               Arch      Version            Repository             Size
================================================================================
Installing:
 ansible               noarch    5.4.0-2.el9        ol9_developer_EPEL     71 M
Installing dependencies:
 ansible-core          x86_64    2.12.2-2.el9_0     ol9_appstream         3.6 M
 git                   x86_64    2.39.3-1.el9_2     ol9_appstream          78 k
 git-core              x86_64    2.39.3-1.el9_2     ol9_appstream         4.3 M
 git-core-doc          noarch    2.39.3-1.el9_2     ol9_appstream         3.9 M
 perl-Error            noarch    1:0.17029-7.el9    ol9_appstream          57 k
 perl-Git              noarch    2.39.3-1.el9_2     ol9_appstream          43 k
 perl-TermReadKey      x86_64    2.38-11.el9        ol9_appstream          42 k
 perl-lib              x86_64    0.65-480.el9       ol9_appstream          15 k
 python3-babel         noarch    2.9.1-2.el9        ol9_appstream         6.6 M
 python3-jinja2        noarch    2.11.3-4.el9       ol9_appstream         330 k
 python3-markupsafe    x86_64    1.1.1-12.el9       ol9_appstream          52 k
 python3-packaging     noarch    20.9-5.0.1.el9     ol9_appstream         117 k
 python3-pytz          noarch    2021.1-5.el9       ol9_appstream          73 k
 python3-resolvelib    noarch    0.5.4-5.el9        ol9_appstream          59 k
 sshpass               x86_64    1.09-4.el9         ol9_appstream          33 k

Transaction Summary
================================================================================
Install  16 Packages

Total download size: 90 M
Installed size: 375 M
Is this ok [y/N]: y
Downloading Packages:
(1/16): git-2.39.3-1.el9_2.x86_64.rpm           402 kB/s |  78 kB     00:00    
(2/16): ansible-core-2.12.2-2.el9_0.x86_64.rpm  3.0 MB/s | 3.6 MB     00:01    
(3/16): git-core-2.39.3-1.el9_2.x86_64.rpm      3.5 MB/s | 4.3 MB     00:01    
(4/16): perl-Error-0.17029-7.el9.noarch.rpm     1.2 MB/s |  57 kB     00:00    
(5/16): perl-Git-2.39.3-1.el9_2.noarch.rpm      1.8 MB/s |  43 kB     00:00    
(6/16): perl-TermReadKey-2.38-11.el9.x86_64.rpm 1.5 MB/s |  42 kB     00:00    
(7/16): perl-lib-0.65-480.el9.x86_64.rpm        725 kB/s |  15 kB     00:00    
(8/16): git-core-doc-2.39.3-1.el9_2.noarch.rpm  3.4 MB/s | 3.9 MB     00:01    
(9/16): python3-jinja2-2.11.3-4.el9.noarch.rpm  1.8 MB/s | 330 kB     00:00    
(10/16): python3-markupsafe-1.1.1-12.el9.x86_64 740 kB/s |  52 kB     00:00    
(11/16): python3-packaging-20.9-5.0.1.el9.noarc 419 kB/s | 117 kB     00:00    
(12/16): python3-pytz-2021.1-5.el9.noarch.rpm   157 kB/s |  73 kB     00:00    
(13/16): python3-babel-2.9.1-2.el9.noarch.rpm   3.5 MB/s | 6.6 MB     00:01    
(14/16): python3-resolvelib-0.5.4-5.el9.noarch. 475 kB/s |  59 kB     00:00    
(15/16): sshpass-1.09-4.el9.x86_64.rpm          1.7 MB/s |  33 kB     00:00    
(16/16): ansible-5.4.0-2.el9.noarch.rpm         7.6 MB/s |  71 MB     00:09    
--------------------------------------------------------------------------------
Total                                           9.6 MB/s |  90 MB     00:09     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Installing       : git-core-2.39.3-1.el9_2.x86_64                        1/16 
  Installing       : git-core-doc-2.39.3-1.el9_2.noarch                    2/16 
  Installing       : sshpass-1.09-4.el9.x86_64                             3/16 
  Installing       : python3-resolvelib-0.5.4-5.el9.noarch                 4/16 
  Installing       : python3-pytz-2021.1-5.el9.noarch                      5/16 
  Installing       : python3-babel-2.9.1-2.el9.noarch                      6/16 
  Installing       : python3-packaging-20.9-5.0.1.el9.noarch               7/16 
  Installing       : python3-markupsafe-1.1.1-12.el9.x86_64                8/16 
  Installing       : python3-jinja2-2.11.3-4.el9.noarch                    9/16 
  Installing       : perl-lib-0.65-480.el9.x86_64                         10/16 
  Installing       : perl-TermReadKey-2.38-11.el9.x86_64                  11/16 
  Installing       : perl-Error-1:0.17029-7.el9.noarch                    12/16 
  Installing       : perl-Git-2.39.3-1.el9_2.noarch                       13/16 
  Installing       : git-2.39.3-1.el9_2.x86_64                            14/16 
  Installing       : ansible-core-2.12.2-2.el9_0.x86_64                   15/16 
  Installing       : ansible-5.4.0-2.el9.noarch                           16/16 
  Running scriptlet: ansible-5.4.0-2.el9.noarch                           16/16 
  Verifying        : ansible-5.4.0-2.el9.noarch                            1/16 
  Verifying        : ansible-core-2.12.2-2.el9_0.x86_64                    2/16 
  Verifying        : git-2.39.3-1.el9_2.x86_64                             3/16 
  Verifying        : git-core-2.39.3-1.el9_2.x86_64                        4/16 
  Verifying        : git-core-doc-2.39.3-1.el9_2.noarch                    5/16 
  Verifying        : perl-Error-1:0.17029-7.el9.noarch                     6/16 
  Verifying        : perl-Git-2.39.3-1.el9_2.noarch                        7/16 
  Verifying        : perl-TermReadKey-2.38-11.el9.x86_64                   8/16 
  Verifying        : perl-lib-0.65-480.el9.x86_64                          9/16 
  Verifying        : python3-babel-2.9.1-2.el9.noarch                     10/16 
  Verifying        : python3-jinja2-2.11.3-4.el9.noarch                   11/16 
  Verifying        : python3-markupsafe-1.1.1-12.el9.x86_64               12/16 
  Verifying        : python3-packaging-20.9-5.0.1.el9.noarch              13/16 
  Verifying        : python3-pytz-2021.1-5.el9.noarch                     14/16 
  Verifying        : python3-resolvelib-0.5.4-5.el9.noarch                15/16 
  Verifying        : sshpass-1.09-4.el9.x86_64                            16/16 

Installed:
  ansible-5.4.0-2.el9.noarch                                                    
  ansible-core-2.12.2-2.el9_0.x86_64                                            
  git-2.39.3-1.el9_2.x86_64                                                     
  git-core-2.39.3-1.el9_2.x86_64                                                
  git-core-doc-2.39.3-1.el9_2.noarch                                            
  perl-Error-1:0.17029-7.el9.noarch                                             
  perl-Git-2.39.3-1.el9_2.noarch                                                
  perl-TermReadKey-2.38-11.el9.x86_64                                           
  perl-lib-0.65-480.el9.x86_64                                                  
  python3-babel-2.9.1-2.el9.noarch                                              
  python3-jinja2-2.11.3-4.el9.noarch                                            
  python3-markupsafe-1.1.1-12.el9.x86_64                                        
  python3-packaging-20.9-5.0.1.el9.noarch                                       
  python3-pytz-2021.1-5.el9.noarch                                              
  python3-resolvelib-0.5.4-5.el9.noarch                                         
  sshpass-1.09-4.el9.x86_64                                                     

Complete!

Step 6: Check the Ansible version by using the below command

[root@linuxhelp ~]# ansible --version
ansible [core 2.12.2]
  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.9/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.9.18 (main, Sep  7 2023, 00:00:00) [GCC 11.4.1 20230605 (Red Hat 11.4.1-2.1.0.1)]
  jinja version = 2.11.3
  libyaml = True

Step 7: Open your /etc/hosts file and add the following using the below command

[root@linuxhelp ~]# vim /etc/hosts

Step 8: Now generate SSH Key.copy, this created ssh key for another remote server

[root@linuxhelp ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa
Your public key has been saved in /root/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:9LBEGbYd03rhda982PjxtRmtTia3azPjUJvJVPNzQdc root@linuxhelp
The key's randomart image is:
+---[RSA 3072]----+
|        +oo.   .o|
|       o.o oo o E|
|        = .o o +o|
|       o +. o  .=|
|        S .. .o*+|
|             +=*B|
|            o O+B|
|             **+o|
|             +== |
+----[SHA256]-----+

[root@linuxhelp ~]# ssh-copy-id root@vm1.linuxhelp.local
The authenticity of host 'vm1.linuxhelp.local (192.168.6.140)' can't be established.
ED25519 key fingerprint is SHA256:zLc8ctMiULvhvu/YUZMD8cwdzVBpLbQFKGNR+Jr+csk.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@vm1.linuxhelp.local's password: 
Number of key(s) added: 1
Now try logging into the machine, with:   "ssh 'root@vm1.linuxhelp.local'"
and check to make sure that only the key(s) you wanted were added.

Step 9: After added the SSH key without any SSH password you can able to access for remote server

[root@linuxhelp ~]# ssh root@vm1.linuxhelp.local
Activate the web console with: systemctl enable --now cockpit.socket
Last login: Fri Mar 15 22:39:23 2024 from 192.168.6.104
[root@linuxhelp ~]#
[root@linuxhelp ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:0c:29:5e:e3:25 brd ff:ff:ff:ff:ff:ff
    altname enp3s0
    inet 192.168.6.140/24 brd 192.168.6.255 scope global noprefixroute ens160
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe5e:e325/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

Step 10: Next run the below command without password for login user.

[root@linuxhelp ~]# echo "$(whoami) ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/$(whoami)
root ALL=(ALL) NOPASSWD:ALL

Step 11: Exit from Remote Server

[root@linuxhelp ~]# exit
logout
Connection to vm1.linuxhelp.local closed.

Conclusion:

We have reached the end of this article. In this guide, we have walked you through the steps required to install and configure Ansible on Oracle Linux 9.3. Your feedback is much welcome.

FAQ
Q
Is Ansible open source?
A
Yes, Ansible is an open-source IT automation tool.
Q
Does Ansible have a GUI?
A
One of the major gripes from Ansible users is that it didn't have a proper GUI.
Q
Can Ansible replace Jenkins?
A
Ansible Tower can be considered a replacement for Jenkins, it does not yet have the latter's huge plugin support
Q
Is Ansible a CI tool?
A
Ansible is a powerful tool for IT automation and can be used in a CI/CD process
Q
What language does Ansible use?
A
Ansible uses human-readable YAML templates