Mir Sayeed Hassan – Oracle Blog

Oracle DBA – Tips & Techniques | Learn with real-time examples

  • Translate

  • It’s Me




  • My Certificates

  • Links

    My Acclaim Certification : Credly Profile
    My Oracle ACE Pro Profile

  • Achievements

    Awarded Top 100 Oracle Blogs from Worldwide - #RANK 39
  • VISITORS COUNT

  • Verified International Academic Qualification from World Education Service (WES)

    Verified International Academic Qualification from World Education Service (WES)

  • Jobs

How to install a RPM Linux Packages by using the Ansible Playbook

Posted by Mir Sayeed Hassan on November 22nd, 2023

How to install a RPM Linux Packages by using the Ansible Playbook

Install the yum package on same workstation ansible server

Create a directory

[root@test-ansible ~]# mkdir /home/ansible

Create a file as “inventory”

[root@test-ansible ansible]# vi inventory
192.168.***.131
:wq

Note: You can assign the single or multiple server host inside the inventory file

Create a file with install package config

[root@test-ansible ansible]# vi package1.yaml
---
- hosts: 192.168.***.131
tasks:
- name: Install package
yum:
name: telnet
state: latest
:wq

Pre-check before execute

[root@test-ansible ansible]# ansible-playbook -i /home/ansible/inventory package1.yaml --syntax-check
playbook: package1.yaml
[root@test-ansible ansible]# ansible-playbook -i /home/ansible/inventory package1.yaml

PLAY [192.168.***.131] **********************************************************************************

TASK [Gathering Facts] **********************************************************************************
Enter passphrase for key '/root/.ssh/id_ed25519':
[WARNING]: Platform linux on host 192.168.***.131 is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
ok: [192.168.***.131]

TASK [Install package] *********************************************************************************
changed: [192.168.***.131]

PLAY RECAP *********************************************************************************************
192.168.***.131 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

Hence until here i have install the telnet package by using an Ansible Playbook

Install the yum package from workstation to another server

Add the IP Address of the different server in workstation

[root@test-ansible ~]# cat /home/ansible/inventory
192.168.***.131
192.168.***.130

Login to the Workstation ansible server & copy the ssh-keygen

[root@test-ansible ~]# ssh-copy-id -i .ssh/id_ed25519 192.168.***.130

/bin/ssh-copy-id: INFO: Source of key(s) to be installed: ".ssh/id_ed25519.pub"
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/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@192.168.***.130's password:

Number of key(s) added: 1

Now try logging into the machine, with: "ssh '192.168.***.130'"
and check to make sure that only the key(s) you wanted were added.
Note: Provide the passphare password

Login & Verify the ssh-copy-id key present in different server (192.168.***.130)
[root@oemdb ~]# ls -la .ssh/

total 12
drwx------. 2 root root 48 Nov 22 05:52 .
dr-xr-x---. 18 root root 4096 Jan 23 2021 ..
-rw-------. 1 root root 185 Nov 22 05:54 authorized_keys
-rw-r--r--. 1 root root 535 Jun 30 2019 known_hosts
[root@oemdb ~]# cat .ssh/authorized_keys
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPIeUIkDlUKzL/ZxDbhZBx/x2HO4STftNllCdNQadnpn NEWANSIBLE
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIL6EVJctvsxnc2NzWOdjON58j9hb8wCmMicyUE+74Tfs MIR_ANSIBLE

Create a yaml file

[root@test-ansible ~]# cat /home/ansible/package1.yaml
---
- hosts: all
tasks:
- name: Install package
yum:
name: telnet
state: latest

NOTE: Here hosts: all It means any number of hosts are assign in inventory.

[root@test-ansible ansible]# ansible-playbook -i /home/ansible/inventory package1.yaml

PLAY [all] **********************************************************************

TASK [Gathering Facts] *********************************************************
Enter passphrase for key '/root/.ssh/id_ed25519':
[WARNING]: Platform linux on host 192.168.***.131 is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
ok: [192.168.***.131]
ok: [192.168.***.130]

TASK [Install package] **********************************************************
ok: [192.168.***.131]

changed: [192.168.***.130]

PLAY RECAP ********************************************************************
192.168.***.130 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
192.168.***.131 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

Verify telnet package on 192.168.***.130

[root@oratdb ~]# rpm -qa telnet
telnet-0.17-64.el7.x86_64

If you want to REMOVE the packages from the server, fallow below step

Edit the package1.yaml file & change the state to “absent”

[root@test-ansible ansible]# cat package1.yaml
---
- hosts: all
tasks:
- name: Install package
yum:
name: telnet
state: absent

Run the ansible-playbook

[root@test-ansible ansible]# ansible-playbook -i /home/ansible/inventory package1.yaml

PLAY [all] *************************************************************

TASK [Gathering Facts] ************************************************
Enter passphrase for key '/root/.ssh/id_ed25519': Enter passphrase for key '/root/.ssh/id_ed25519':
[WARNING]: Platform linux on host 192.168.***.131 is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.

Enter passphrase for key '/root/.ssh/id_ed25519':

ok: [192.168.***.131]
ok: [192.168.***.130]

TASK [Install package] *************************************************
changed: [192.168.***.131]
changed: [192.168.***.130]

PLAY RECAP ***********************************************************
192.168.***.130 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
192.168.***.131 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

=====Hence tested & verified in our test env=====