I set up my servers with non-standard ssh port. I would like to find a way to build an indempotent master playbook, but I seem to have trouble with an UNREACHABLE
error while gathering facts.
I have been trying to use this post as a guide: https://dmsimard.com/2016/03/15/changing-the-ssh-port-with-ansible/
However, I am not even able to get to that first step if my port is configured differently.
My master playbook looks like this:
# master playbook
---
- name: Install all the packages for a server
hosts: test-collection-01
vars_files:
- vars/test_collection.yml
remote_user: foo_user
roles:
- debugger
Then, the debug playbook contains pretty much what the aforementioned blog post contains.
---
- name: DEBUG FACTS
debug:
msg: 'ansible port: {{ ansible_port }}\,Configured Hostname: {{ inventory_hostname }}'
- name: Try initial ssh port
set_fact:
ansible_port: 22
...
However, If my server has already had its ssh
port changed to something else, the playbook wont even run and it fails in the "Gathering Facts" step.
TASK [Gathering Facts]
***
fatal: [198.199.x.x]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 198.199.x.x port 22: Connection refused\r\n", "unreachable": true}
Is there a way to run the port checking code during "Gathering Facts" or before?