-
-
Notifications
You must be signed in to change notification settings - Fork 57
Description
Describe the bug
The following task is executed on managed hosts (remote host)
- name: Wait for port to be available
ansible.builtin.wait_for:
port: "{{ ansible_port | default('22') }}"
timeout: "{{ bootstrap_timeout }}"
become: false
when:
- ansible_connection is defined
- ansible_connection not in [ "container", "docker", "community.docker.docker" ]
- ansible_connection is not none
- bootstrap_wait_for_host
With default port value 22 I get
TASK [bootstrap : Wait for port to be available] *******************************
│ fatal: [dev064]: **UNREACHABLE**! => changed=false
when the managed host (a VM) is still booting, port 22 is not yet open, so the task fails and the playbook stops. The bootstrap_timeout is not taken in to account in this case.
In ansible documentation the way to check SSH availability is using local connection
# Do not assume the inventory_hostname is resolvable and delay 10 seconds at start
- name: Wait 300 seconds for port 22 to become open and contain "OpenSSH"
ansible.builtin.wait_for:
port: 22
host: '{{ (ansible_ssh_host|default(ansible_host))|default(inventory_hostname) }}'
search_regex: OpenSSH
delay: 10
connection: local
# Same as above but you normally have ansible_connection set in inventory, which overrides 'connection'
- name: Wait 300 seconds for port 22 to become open and contain "OpenSSH"
ansible.builtin.wait_for:
port: 22
host: '{{ (ansible_ssh_host|default(ansible_host))|default(inventory_hostname) }}'
search_regex: OpenSSH
delay: 10
vars:
ansible_connection: local
Playbook
Please paste the playbook you are using. (Consider requirements.yml and
optionally the command you've invoked.)
Requirements
- src: robertdebock.bootstrap
version: "7.1.0"
name: bootstrap---
- hosts: demo
gather_facts: false
tasks:
- name: Include bootstrap role.
ansible.builtin.include_role:
name: bootstrap
apply:
tags: "always"
vars:
- bootstrap_wait_for_host: yes
- bootstrap_timeout: 30
tags: "always"Output
│ TASK [bootstrap : Wait for port to be available] *******************************
│ fatal: [dev064]: UNREACHABLE! => changed=false
│ msg: |-
│ Failed to connect to the host via ssh: kex_exchange_identification: Connection closed by remote host
│ Connection closed by UNKNOWN port 65535
│ unreachable: true
Environment
- Control node OS: "Ubuntu 22.04.5 LTS"
- Control node Ansible version: 2.16.13
- Managed node OS: Rocky Linux release 9.5
Please consider sponsoring me.