ansible/roles/ubuntu_base/tasks/ssh-port.yml
Sam A. 6e383d6afa
Simplify SSH configuration
Now that the Vagrantfile supplies SSH port information to Ansible, we no
longer need to figure it out in Ansible. Also, since gather_facts (which
requires an SSH connection) is set to true in playbook.yml, one needs to
supply --extra-vars "ansible_port=22" on the commandline when
provisioning for the first time on real hardware, because the port is
hardcoded in the inventory file.
2022-11-17 22:15:26 +01:00

22 lines
447 B
YAML

---
- name: Change SSH port on host
lineinfile:
dest: "/etc/ssh/sshd_config"
regexp: "^#?Port "
line: "Port 19022"
register: ssh_changed
notify: "Restart sshd"
- name: Restart sshd
service:
name: sshd
state: restarted
when: ssh_changed is defined and
ssh_changed.changed
- name: Change Ansible port to 19022
set_fact:
ansible_port: 19022
when: ssh_changed is defined and
ssh_changed.changed