Ansible Core Yum Update RHEL

Scenario: Patching run yum update using Ansible to RHEL 6/7 remote machine
System: RHEL 7, Ansible 2.6 (Callback and ansible log is active)
Remote System: RHEL 6/7 (not using ssh key), same root password.

Example yum update host group devservers, here my steps:
1) Empty ansible log.
# cat /dev/null > /var/log/ansible.log

2) Input hosts devservers in /etc/ansible/hosts
# vi /etc/ansible/hosts

[devservers]
192.168.99.18
192.168.99.19

3) Crete yaml file ssh login to remote servers.
# mkdir -p /etc/ansible/group_vars
# vi /etc/ansible/group_vars/devservers

---
ansible_connection: ssh
ansible_ssh_user: tempe
ansible_ssh_pass: yourPassword

4) Create yum playbook
# vi /etc/ansible/yumupdatedev.yml

---
- hosts: devservers
 remote_user: tempe
 become: yes
 become_method: su
 gather_facts: False
 tasks:
 - name: Subscribe to RHSM
 command: subscription-manager register --username yoursubslogin --password yoursubspassword --auto-attach --force
 register: task_rhsm
 until: task_rhsm is succeeded
 retries: 10
 delay: 2
 ignore_errors: yes
 failed_when: task_rhsm is failure
 - name: Patching Yum Update Latest
 delay: 180
 yum:
 name: '*'
 state: latest
# exclude: kernel*,java*
 - name: Grep Yum Log
 shell: hostname ; "`date '+%b.%d'`" /var/log/yum.log
 register: task_grep
 until: task_grep is succeeded
 retries: 10
 delay: 2
 ignore_errors: yes
 failed_when: task_grep is failure

5) Run the yum playbook.
Below is the result when running above playbook in step 4.

[root@horse ansible]# ansible-playbook --ask-become-pass /etc/ansible/yumupdate.yml
SUDO password: -type remote root password here-
2018-08-09 08:24:41,696 p=2470 u=root | 192.168.99.18 | SUCCESS | rc=0 >>
Unregistering from: subscription.rhsm.redhat.com:443/subscription
The system with UUID 830a7ec8-390d-462b-93d3-c11eb658 has been unregistered
All local data removed
Registering to: subscription.rhsm.redhat.com:443/subscription
The system has been registered with ID: 6ea85048-91d5-4273-8718-c92ba268
The registered system name is: rhel7
Installed Product Current Status:
Product Name: Red Hat Enterprise Linux Server
Status: Subscribed

2018-08-09 08:24:47,013 p=2470 u=root | 192.168.99.19 | SUCCESS | rc=0 >>
Unregistering from: subscription.rhsm.redhat.com:443/subscription
The system with UUID a7d7f558-e29a-47be-b3a1-adddcc09 has been unregistered
All local data removed
Registering to: subscription.rhsm.redhat.com:443/subscription
The system has been registered with ID: c43e07ba-65dc-44ae-9326-46bb500a
The registered system name is: rhel6
Installed Product Current Status:
Product Name: Red Hat Enterprise Linux Server
Status: Subscribed

2018-08-09 08:27:14,515 p=1807 u=root | 192.168.99.18 | SUCCESS => {
 "changed": true,
 "msg": "",
 "rc": 0,
 "results": [
 "Loaded plugins: product-id, search-disabled-repos, subscription-manager\nResolving Dependencies\n--> Running transaction check\n---> Package microcode_ctl.x86_64 2:2.1-29.2.el7_5 will be updated\n---> Package microcode_ctl.x86_64 2:2.1-29.10.el7_5 will be an update\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package Arch Version Repository Size\n================================================================================\nUpdating:\n microcode_ctl x86_64 2:2.1-29.10.el7_5 rhel-7-server-rpms 1.2 M\n\nTransaction Summary\n================================================================================\nUpgrade 1 Package\n\nTotal download size: 1.2 M\nDownloading packages:\nDelta RPMs disabled because /usr/bin/applydeltarpm not installed.\nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n Updating : 2:microcode_ctl-2.1-29.10.el7_5.x86_64 1/2 \n Cleanup : 2:microcode_ctl-2.1-29.2.el7_5.x86_64 2/2 \n Verifying : 2:microcode_ctl-2.1-29.10.el7_5.x86_64 1/2 \n Verifying : 2:microcode_ctl-2.1-29.2.el7_5.x86_64 2/2 \n\nUpdated:\n microcode_ctl.x86_64 2:2.1-29.10.el7_5 \n\nComplete!\n"
 ]
}
2018-08-09 08:27:44,641 p=1807 u=root | 192.168.99.19 | SUCCESS => {
 "changed": true,
 "msg": "",
 "rc": 0,
 "results": [
 "Loaded plugins: product-id, search-disabled-repos, security, subscription-\n : manager\nSetting up Update Process\nResolving Dependencies\n--> Running transaction check\n---> Package microcode_ctl.x86_64 1:1.17-33.1.el6 will be updated\n---> Package microcode_ctl.x86_64 2:1.17-33.3.el6_10 will be an update\n---> Package yum-plugin-security.noarch 0:1.1.30-41.el6 will be updated\n---> Package yum-plugin-security.noarch 0:1.1.30-42.el6_10 will be an update\n---> Package yum-utils.noarch 0:1.1.30-41.el6 will be updated\n---> Package yum-utils.noarch 0:1.1.30-42.el6_10 will be an update\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package Arch Version Repository Size\n================================================================================\nUpdating:\n microcode_ctl x86_64 2:1.17-33.3.el6_10 rhel-6-server-rpms 1.8 M\n yum-plugin-security noarch 1.1.30-42.el6_10 rhel-6-server-rpms 43 k\n yum-utils noarch 1.1.30-42.el6_10 rhel-6-server-rpms 114 k\n\nTransaction Summary\n================================================================================\nUpgrade 3 Package(s)\n\nTotal download size: 2.0 M\nDownloading Packages:\n--------------------------------------------------------------------------------\nTotal 115 kB/s | 2.0 MB 00:17 \nRunning rpm_check_debug\nRunning Transaction Test\nTransaction Test Succeeded\nRunning Transaction\n\r Updating : 2:microcode_ctl-1.17-33.3.el6_10.x86_64 1/6 \n\r Updating : yum-plugin-security-1.1.30-42.el6_10.noarch 2/6 \n\r Updating : yum-utils-1.1.30-42.el6_10.noarch 3/6 \n\r Cleanup : yum-plugin-security-1.1.30-41.el6.noarch 4/6 \n\r Cleanup : yum-utils-1.1.30-41.el6.noarch 5/6 \n\r Cleanup : 1:microcode_ctl-1.17-33.1.el6.x86_64 6/6 \n\r Verifying : yum-utils-1.1.30-42.el6_10.noarch 1/6 \n\r Verifying : yum-plugin-security-1.1.30-42.el6_10.noarch 2/6 \n\r Verifying : 2:microcode_ctl-1.17-33.3.el6_10.x86_64 3/6 \n\r Verifying : yum-plugin-security-1.1.30-41.el6.noarch 4/6 \n\r Verifying : yum-utils-1.1.30-41.el6.noarch 5/6 \n\r Verifying : 1:microcode_ctl-1.17-33.1.el6.x86_64 6/6 \n\nUpdated:\n microcode_ctl.x86_64 2:1.17-33.3.el6_10 \n yum-plugin-security.noarch 0:1.1.30-42.el6_10 \n yum-utils.noarch 0:1.1.30-42.el6_10 \n\nComplete!\n"
 ]
}
2018-08-09 08:27:45,527 p=1807 u=root | 192.168.99.18 | SUCCESS | rc=0 >>
rhel7
Aug 09 08:26:38 Updated: 2:microcode_ctl-2.1-29.10.el7_5.x86_64

2018-08-09 08:27:45,661 p=1807 u=root | 192.168.99.19 | SUCCESS | rc=0 >>
rhel6
Aug 09 08:27:41 Updated: 2:microcode_ctl-1.17-33.3.el6_10.x86_64
Aug 09 08:27:41 Updated: yum-plugin-security-1.1.30-42.el6_10.noarch
Aug 09 08:27:42 Updated: yum-utils-1.1.30-42.el6_10.noarch

[root@horse ansible]#

6) Finish copy ansible.log for the your report to your boss.
# cp -avi /var/log/ansible.log /home/bachem/yumreport_$(date -I).txt


1 thought on “Ansible Core Yum Update RHEL

Leave a Reply

Your email address will not be published. Required fields are marked *