Browse Source

make reboots work

master
parent
commit
6106666273
3 changed files with 14 additions and 19 deletions
  1. +2
    -5
      defaults/main.yml
  2. +1
    -0
      meta/main.yml
  3. +11
    -14
      tasks/main.yml

+ 2
- 5
defaults/main.yml View File

@@ -1,10 +1,7 @@
reboot_command: true reboot_command: true
reboot_pause: true
reboot_wait: true
reboot_check: true


reboot_command_after_seconds: 5
reboot_command_after_seconds: 10
reboot_pause_seconds: 120 reboot_pause_seconds: 120
reboot_wait_timeout_seconds: 300 reboot_wait_timeout_seconds: 300


reboot_uptime_max_seconds: "{{ reboot_delay + reboot_timeout }}"
reboot_uptime_max_seconds: "{{ reboot_pause_seconds - reboot_command_after_seconds + reboot_wait_timeout_seconds }}"

+ 1
- 0
meta/main.yml View File

@@ -0,0 +1 @@
allow_duplicates: yes

+ 11
- 14
tasks/main.yml View File

@@ -1,19 +1,17 @@
--- ---


- name: reboot - name: reboot
shell:
sleep {{reboot_command_after_seconds}} &&
logger "Reboot triggered by Ansible script" &&
command:
systemd-run --on-active={{reboot_command_after_seconds}}
shutdown -r now "Reboot triggered by Ansible script" shutdown -r now "Reboot triggered by Ansible script"
async: 1
poll: 0
#async: 1
#poll: 0
#ignore_errors: true #ignore_errors: true
when: reboot_command when: reboot_command


- name: let server reboot - name: let server reboot
pause: pause:
seconds: "{{ reboot_pause_seconds }}" seconds: "{{ reboot_pause_seconds }}"
when: reboot_pause


- name: wait for ssh - name: wait for ssh
local_action: wait_for local_action: wait_for
@@ -24,15 +22,14 @@
delay: 0 delay: 0
timeout: "{{ reboot_wait_timeout_seconds }}" timeout: "{{ reboot_wait_timeout_seconds }}"
state: started state: started
when: reboot_wait

- include_role:
name: ssh_host_key


- name: try to connect to ssh - name: try to connect to ssh
setup: setup:
when: reboot_check


- name: check uptime for sucsessfull reboot
fail:
msg: host did not reboot; uptime is {{ansible_uptime_seconds}} seconds
when:
- reboot_check
- ansible_uptime_seconds > reboot_uptime_max_seconds
- name: check uptime for successful reboot
set_fact:
reboot_uptime: "{{ ansible_uptime_seconds }}"
failed_when: ansible_uptime_seconds > reboot_uptime_max_seconds

Loading…
Cancel
Save