- name: Reboot host
shell: sleep 2 && shutdown -r now "Reboot initiated by Ansible"
async: 1
poll: 0
become: True
listen: reboot_host
- name: Pause until host is shutting down
local_action:
module: wait_for
timeout: 3
become: False
listen: reboot_host
- name: Wait until host is reachable
wait_for_connection:
become: False
listen: reboot_host
Last active
January 9, 2018 02:40
-
-
Save tho/c705b13e710954bb8952c95bc33755c8 to your computer and use it in GitHub Desktop.
Reboot host with Ansible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: all | |
gather_facts: no | |
tasks: | |
- name: Get uptime before reboot | |
command: uptime | |
register: uptime | |
- debug: var=uptime.stdout_lines | |
- debug: msg="Rebooting {{ inventory_hostname }}" | |
changed_when: True | |
notify: reboot_host | |
- meta: flush_handlers | |
- name: Get uptime after reboot | |
command: uptime | |
register: uptime | |
- debug: var=uptime.stdout_lines | |
handlers: | |
- name: Reboot host | |
shell: sleep 2 && shutdown -r now "Reboot initiated by Ansible" | |
async: 1 | |
poll: 0 | |
become: True | |
listen: reboot_host | |
- name: Pause until host is shutting down | |
local_action: | |
module: wait_for | |
timeout: 3 | |
become: False | |
listen: reboot_host | |
- name: Wait until host is reachable | |
wait_for_connection: | |
become: False | |
listen: reboot_host |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment