浏览代码

better uptime check time handling

master
父节点
当前提交
46ec462687
共有 3 个文件被更改,包括 28 次插入6 次删除
  1. +6
    -3
      defaults/main.yml
  2. +21
    -3
      tasks/main.yml
  3. +1
    -0
      vars/main.yaml

+ 6
- 3
defaults/main.yml 查看文件

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

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 查看文件

@@ -9,18 +9,36 @@
#ignore_errors: true
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:
seconds: "{{ reboot_pause_seconds }}"
register: _reboot_pause

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

- include_role:
name: ssh_host_key


+ 1
- 0
vars/main.yaml 查看文件

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

正在加载...
取消
保存