Skip to content

Commit

Permalink
reboot: not correctly checking host reachability.
Browse files Browse the repository at this point in the history
Come across the issue where after that the reboot has completed host was
not yet reachable. This is because the host was still booting hence
refusing SSH connection even if SSH service was up and running. wait_for
is the old way to check host reachability and it produced unreliable
results, because the system needs to be booted and we need to make sure
we can execute command over it before continuing the next task.

wait_for_connection does that pretty automatically, it wait for the host
to be reachable and ensure we can run command on it.

Signed-off-by: Lionel H <lionel.hubaut@tessares.net>
  • Loading branch information
lion24 authored and Gertjan Roggemans committed Mar 25, 2019
1 parent 3e23b26 commit 01e7ab0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 23 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ A role for rebooting hosts.
|---------------------------|-----------------------------------------------------------|--------------------------------------------|
| `reboot_message` | Reboot message for the logs | 'Reboot by Ansible' |
| `reboot_wait` | Wait for hosts to come back online? | 'yes' |
| `reboot_connect_timeout` | Connection timeout before retrying. | 20 |
| `reboot_wait_host` | Host to check | `ansible_ssh_host` or `inventory_hostname` |
| `reboot_wait_port` | Port to check | `ansible_ssh_port` or 22 |
| `reboot_wait_regex` | String to match in the socket connection. (ex. `OpenSSH`) | / |
Expand Down
5 changes: 4 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ reboot_message: 'Reboot by Ansible'
# Wait for host?
reboot_wait: 'yes'

# Maximum number of seconds to wait for a connection to happen before closing and retrying.
reboot_connect_timeout: 20

# Time to wait before polling the host
reboot_wait_delay: 10

Expand All @@ -20,4 +23,4 @@ reboot_wait_ctimeout: 5
reboot_interval: 'no'

# Interval before next task
reboot_interval_seconds: 0
reboot_interval_seconds: 0
25 changes: 3 additions & 22 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,12 @@
poll: 0
ignore_errors: yes

# Make sure ansible_ssh_host has the correct value inside the local_action module
- name: Set default reboot_wait_host
become: no
set_fact:
reboot_wait_host: "{{ ansible_ssh_host | default(inventory_hostname) }}"
when: (reboot_wait|bool) and reboot_wait_host is undefined

# Make sure ansible_ssh_port has the correct value inside the local_action module
- name: Set default reboot_wait_port
become: no
set_fact:
reboot_wait_port: "{{ ansible_ssh_port | default(22) }}"
when: (reboot_wait|bool) and reboot_wait_port is undefined

- name: Wait for host
become: no
wait_for:
host: "{{ reboot_wait_host }}"
port: "{{ reboot_wait_port }}"
state: started
wait_for_connection:
connect_timeout: "{{ reboot_connect_timeout }}"
sleep: "{{ reboot_wait_ctimeout }}"
delay: "{{ reboot_wait_delay }}"
timeout: "{{ reboot_wait_timeout }}"
search_regex: "{{ reboot_wait_regex | default(omit) }}"
connect_timeout: "{{ reboot_wait_ctimeout }}"
delegate_to: localhost
when: reboot_wait|bool

- name: Interval before next task
Expand Down

0 comments on commit 01e7ab0

Please sign in to comment.