Browse Source

better uptime check time handling

master
parent
commit
46ec462687
3 changed files with 28 additions and 6 deletions
  1. +6
    -3
      defaults/main.yml
  2. +21
    -3
      tasks/main.yml
  3. +1
    -0
      vars/main.yaml

+ 6
- 3
defaults/main.yml View File

@@ -1,7 +1,10 @@
reboot_command: true reboot_command: true


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


reboot_uptime_max_seconds: "{{ reboot_pause_seconds - reboot_command_after_seconds + reboot_wait_timeout_seconds }}"
reboot_pause_seconds: 60

reboot_wait_for_ssh_close_timeout_seconds: 300
reboot_wait_for_ssh_open_timeout_seconds: 300

reboot_uptime_max_seconds: "{{ (_current_timestamp | int) - (_reboot_shutdown_timestamp | int) }}"

+ 21
- 3
tasks/main.yml View File

@@ -9,18 +9,36 @@
#ignore_errors: true #ignore_errors: true
when: reboot_command when: reboot_command


- name: let server reboot
- name: wait for ssh port to be closed
wait_for:
host: "{{ ansible_host | default(inventory_hostname) }}"
port: 22
search_regex: OpenSSH
timeout: "{{ reboot_wait_for_ssh_close_timeout_seconds }}"
state: absent
vars:
ansible_connection: local
register: _reboot_wait_for_ssh_port_closed

- name: note the shutdown time
set_fact:
_reboot_shutdown_timestamp: "{{ _current_timestamp }}"

- name: pause to let host reboot
pause: pause:
seconds: "{{ reboot_pause_seconds }}" seconds: "{{ reboot_pause_seconds }}"
register: _reboot_pause


- name: wait for ssh port
- name: wait for ssh port to be open again
wait_for: wait_for:
host: "{{ ansible_host | default(inventory_hostname) }}" host: "{{ ansible_host | default(inventory_hostname) }}"
port: 22 port: 22
search_regex: OpenSSH search_regex: OpenSSH
timeout: "{{ reboot_wait_timeout_seconds }}"
timeout: "{{ reboot_wait_for_ssh_open_timeout_seconds }}"
state: present
vars: vars:
ansible_connection: local ansible_connection: local
register: _reboot_wait_for_ssh_port_open


- include_role: - include_role:
name: ssh_host_key name: ssh_host_key


+ 1
- 0
vars/main.yaml View File

@@ -0,0 +1 @@
_current_timestamp: "{{ lookup('pipe','date +%s') }}"

Loading…
Cancel
Save