2023-01-15 15:52:26 +00:00
|
|
|
---
|
2023-04-06 08:15:24 +00:00
|
|
|
- name: Determine SSH port
|
2023-01-15 15:52:26 +00:00
|
|
|
hosts: all
|
|
|
|
gather_facts: no
|
|
|
|
tasks:
|
|
|
|
- name: "Check port {{ ansible_port }}"
|
|
|
|
wait_for:
|
|
|
|
port: "{{ ansible_port }}"
|
|
|
|
state: "started"
|
|
|
|
host: "{{ ansible_host }}"
|
|
|
|
connect_timeout: "5"
|
|
|
|
timeout: "5"
|
|
|
|
delegate_to: "localhost"
|
|
|
|
ignore_errors: "yes"
|
|
|
|
register: ssh_port
|
|
|
|
|
|
|
|
- name: "Check port 22"
|
|
|
|
wait_for:
|
|
|
|
port: "22"
|
|
|
|
state: "started"
|
|
|
|
host: "{{ ansible_host }}"
|
|
|
|
connect_timeout: "5"
|
|
|
|
timeout: "5"
|
|
|
|
delegate_to: "localhost"
|
|
|
|
ignore_errors: "yes"
|
|
|
|
register: ssh_port_default
|
|
|
|
when:
|
|
|
|
- ssh_port is defined
|
|
|
|
- ssh_port.state is undefined
|
|
|
|
|
|
|
|
- name: Set SSH port to 22
|
|
|
|
set_fact:
|
|
|
|
ansible_port: "22"
|
|
|
|
when: ssh_port_default.state is defined
|