From 95f884ce1f8c4ac14db1c4f593f8a182263a1126 Mon Sep 17 00:00:00 2001 From: Markus Katharina Brechtel Date: Fri, 13 Oct 2017 09:51:22 +0000 Subject: [PATCH] new style reboot --- defaults/main.yml | 13 ++++++++++--- tasks/main.yml | 42 +++++++++++++++++++++--------------------- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index b49a113..0a9abca 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,3 +1,10 @@ -reboot_delay: 120 -reboot_timeout: 300 -reboot_state: rebooted +reboot_command: true +reboot_pause: true +reboot_wait: true +reboot_check: true + +reboot_command_after_seconds: 5 +reboot_pause_seconds: 120 +reboot_wait_timeout_seconds: 300 + +reboot_uptime_max_seconds: "{{ reboot_delay + reboot_timeout }}" diff --git a/tasks/main.yml b/tasks/main.yml index 590f948..c8b62e0 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,38 +1,38 @@ --- - name: reboot - command: shutdown --no-wall -r +1 - async: 0 + shell: + sleep {{reboot_command_after_seconds}} && + logger "Reboot triggered by Ansible script" && + shutdown -r now "Reboot triggered by Ansible script" + async: 1 poll: 0 - ignore_errors: true - when: - reboot_state == "rebooted" or - reboot_state == "started" + #ignore_errors: true + when: reboot_command - name: let server reboot pause: - seconds: "{{ reboot_delay }}" - when: - reboot_state == "rebooted" or - reboot_state == "reachable" + seconds: "{{ reboot_pause_seconds }}" + when: reboot_pause - name: wait for ssh - local_action: wait_for host={{ ansible_host | default(inventory_hostname) }} port=22 search_regex=OpenSSH delay=0 timeout={{ reboot_timeout }} state=started - when: - reboot_state == "rebooted" or - reboot_state == "reachable" or - reboot_state == "finished" + local_action: wait_for + args: + host: "{{ ansible_host | default(inventory_hostname) }}" + port: 22 + search_regex: OpenSSH + delay: 0 + timeout: "{{ reboot_wait_timeout_seconds }}" + state: started + when: reboot_wait - name: try to connect to ssh setup: - when: - reboot_state == "rebooted" or - reboot_state == "finished" + when: reboot_check - name: check uptime for sucsessfull reboot fail: msg: host did not reboot; uptime is {{ansible_uptime_seconds}} seconds when: - - reboot_state == "rebooted" or - reboot_state == "finished" - - ansible_uptime_seconds > reboot_delay + reboot_timeout + - reboot_check + - ansible_uptime_seconds > reboot_uptime_max_seconds