Friday, July 10, 2020

ansible playbook os update security

$ cat /opt/ansible/osupdate.yml
---
  - name: Osupdate
    hosts: all
    become: yes
    become_user: root
    tasks:
      - name: taking backup of important files.
        shell: mkdir /var/tmp/security_patching_bkp;cd /var/tmp/security_patching_bkp;df -h>df.txt;ifconfig -a>ifconfig.txt;uname -a>uname.txt;ps -eaf>ps.txt
        register: result
      - name: Clean yum
        shell: yum clean all
        register: yumclean
      - debug:
          var: yumclean
      - name: yum list security
        shell: yum list-security > /var/tmp/security_patching_bkp/yum_list-security.txt
        register: yumlist_security
      - name: Yum security update
        shell: yum update --security -y
        register: yumsecurityupdate
      - debug:
          var: yumsecurityupdate
      - name: Yum security update skip-broken
        shell: yum update --security -y --skip-broken
        register: yumsecurityupdateskipb
      - debug:
          var: yumsecurityupdateskipb
      - name: Checking reboot required or not
        shell: LAST_KERNEL=$(rpm -q --last kernel | awk 'NR==1{sub(/kernel-/,""); print $1}'); CURRENT_KERNEL=$(uname -r); if [ $LAST_KERNEL != $CURRENT_KERNEL ]; then echo 'reboot'; else echo 'no'; fi
        ignore_errors: true
        register: reboot_hint
      - name: Rebooting if required...
        shell: shutdown -r now "Reboot required for updated kernel"
        async: 0
        poll: 0
        when: reboot_hint.stdout.find("reboot") != -1
        register: rebooting
      - name: Waiting for thing to reboot
        pause: seconds=45
        when: rebooting|changed
]$

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.