Sam A.
57ca1e9233
- Added a separate role that first configures SSH, and after that gathers the ansible_virtualization_role fact, due to gathering facts requiring an SSH connection - Renamed ssl_certs_enabled to letsencrypt_enabled and moved that and the vagrant variable to the be supplied directly to the last two roles in playbook.yml - Added tags base_only and setup_services to the new role ssh_and_vagrant so that it will always be run before anything else when using deploy.sh
39 lines
938 B
YAML
39 lines
938 B
YAML
---
|
|
- name: Check if SSH port is already configured
|
|
wait_for:
|
|
port: 19022
|
|
host: "{{ ansible_host }}"
|
|
search_regex: "OpenSSH"
|
|
connect_timeout: 5
|
|
timeout: 10
|
|
become: false
|
|
delegate_to: localhost
|
|
ignore_errors: true
|
|
register: ssh_configured
|
|
|
|
# If running in Vagrant, ansible_port is always 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 and
|
|
ansible_port != 2222
|
|
|
|
- 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
|
|
|
|
- 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
|