ansible/roles/ubuntu_base/tasks/ssh.yml

43 lines
1.1 KiB
YAML
Raw Normal View History

---
- name: Check if SSH port is already configured
wait_for:
port: 19022
host: "{{ ansible_host }}"
2022-11-13 21:03:45 +00:00
search_regex: "OpenSSH"
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
2022-11-13 21:03:45 +00:00
- name: Change SSH port on host
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
- name: Change Ansible port to 19022
set_fact:
ansible_port: 19022
when: ssh_changed is defined