Let's say the 2nd host of 20 hosts fail since I'm doing updates in pairs. How can I tell ansible to stop if the 2nd, or any in the host group fails?
Code:
---
- hosts: test
gather_facts: yes
remote_user: root
become: yes
become_method: sudo
serial: 2
tasks:
- name: Yum Update
yum:
name: "*"
state: latest
exclude: nvidia*
skip_broken: yes
- name: Check for reboot hint.
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 ...
command: shutdown -r now "Reboot required"
async: 0
poll: 0
ignore_errors: true
when: reboot_hint.stdout.find("reboot") != -1
register: rebooting
# - name: Wait for thing to reboot...
# 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