2022-11-13 18:27:45 +00:00
|
|
|
---
|
|
|
|
- name: Check if SSH port is already configured
|
|
|
|
wait_for:
|
|
|
|
port: 19022
|
2022-11-13 20:42:52 +00:00
|
|
|
host: "{{ ansible_host }}"
|
2022-11-13 18:27:45 +00:00
|
|
|
connect_timeout: 5
|
|
|
|
timeout: 10
|
|
|
|
become: false
|
|
|
|
delegate_to: localhost
|
|
|
|
ignore_errors: true
|
|
|
|
register: ssh_configured
|
|
|
|
|
|
|
|
# If we're running in Vagrant, ansible_port is 2222
|
|
|
|
- name: Change Ansible port to 22 if needed
|
|
|
|
set_fact:
|
|
|
|
ansible_port: 22
|
|
|
|
when: ssh_configured is defined and
|
|
|
|
(ssh_configured.state is undefined or
|
|
|
|
(ssh_configured.state is defined and
|
|
|
|
ssh_configured.state != "started")) and
|
|
|
|
ansible_port != 2222
|
|
|
|
|
|
|
|
- name: Change SSH port
|
|
|
|
lineinfile:
|
|
|
|
dest: "/etc/ssh/sshd_config"
|
|
|
|
regexp: "^#?Port"
|
|
|
|
line: "Port 19022"
|
|
|
|
register: ssh_changed
|
|
|
|
notify: "Restart sshd"
|
|
|
|
when: ssh_configured is defined and
|
|
|
|
(ssh_configured.state is undefined or
|
|
|
|
(ssh_configured.state is defined and
|
|
|
|
ssh_configured.state != "started"))
|
|
|
|
|
|
|
|
- name: Ensure sshd is reloaded if needed
|
|
|
|
meta: flush_handlers
|
|
|
|
|
2022-11-13 20:42:52 +00:00
|
|
|
- name: Change Ansible port to 19022
|
2022-11-13 18:27:45 +00:00
|
|
|
set_fact:
|
|
|
|
ansible_port: 19022
|
|
|
|
when: ssh_changed is defined
|