Category: ansible Generated on 2016-03-10
source: https://coderwall.com/p/0nckqg/ansible-reboot-ubuntu-if-needed source: http://elnur.pro/rebooting-servers-one-by-one-with-ansible/
Reboot your ansible inventory one host by one if needed by system upgrade.
This is valid for Ubuntu.
Ansible playbook:
---
- hosts: all # all hosts
serial: 1 # one by one
sudo: yes # shutdown requires sudo
tasks:
- name: Reboot system if required
command: shutdown -r now 'Rebooting to complete system upgrade' removes=/var/run/reboot-required
- name: Wait for the server to reboot
local_action: wait_for host= port=22