Home · Latest · Trends  /  general
-1

Ansible yum update kernel, reboot only if needed (playbook)

rated 1 times [  0] [ 1]  / comments: 0 / hits: 1110  / 1 year ago, wed, may 3, 2017, 15:07:32
I pieced this playbook together from multiple snippets from various playbooks on the internet.. have tried it w/ a testbed of CentOS 6 and 7 hosts all at once and can say it works in my environment.
- hosts: all
  become: false
  tasks:
    - name: upgrade the kernel
      yum: name=kernel state=latest

    - name: Check for reboot
      shell: if [ $(rpm -q kernel|tail -n 1) != kernel-$(uname -r) ]; then echo 'reboot'; else echo 'no'; fi
      ignore_errors: true
      register: reboot_hint

    - name: Rebooting ...
      command: shutdown -r now "Reboot required for updated kernel"
      async: 0
      poll: 0
      become: false
      ignore_errors: true
      when: reboot_hint.stdout.find("reboot") != -1
      register: rebooting

    - name: Wait for rebooted servers to come back
      local_action: wait_for host={{ ansible_ssh_host | default(inventory_hostname) }} state=started port=22 delay=30 timeout=300 connect_timeout=15
      when: rebooting|changed
More From » general
 

Comments

There are no comments for this Snippet yet
Only authorized users can post. Please sign in first, or register a free account
 
Share
Sponsor
Posted
rob

rob

Member since Feb 22, 2017
Total Code Snippets: 108
Total Comments: 1
Location: n/a
Following
User not following anyone yet.
rob snippets
1 year ago, wed, feb 22, 2017
1 year ago, wed, feb 22, 2017
1 year ago, wed, feb 22, 2017
1 year ago, wed, feb 22, 2017
1 year ago, wed, feb 22, 2017
1 year ago, wed, feb 22, 2017
1 year ago, wed, feb 22, 2017
1 year ago, wed, feb 22, 2017