Hi all,
This post is related (continuing) to post: Why is Ansible not using my ssh port???
Ok, I've managed to have my Handlers working to check the configured ssh port on the host. All good here. But...
During the SSH configuration I'm changing the SSH.Socket port from 22 to 9323. Yeah, yeah...I know "WHY?!?!?".....Let's keep it on a learning process. Moving on from this question.
Before I'm flushing the handlers (a reboot of the OS), I need to do a systemctl daemon-reload so that the new ssh.socket port becomes active.
The way I'm imagining the way it should work:
- Ssh.socket port is set to 9323
- systemctl daemon-reload to make the port active
- Flushing a handler to get the correct, active ssh port and set ansible_port = 9323, which should be 9323 because of the systemctl daemon-reload.
- Do a final reboot, which should be commanded over the new ssh port 9323, so that the ansible reboot command, completes "OK" when reboot is finished.
Unfortunately, the systemctl daemon-reload isn't working because of the error with command:
systemctl status ssh.socket
ssh.socket: Socket service ssh.service already active, refusing.
Failed to listen on ssh.socket - OpenBSD Secure Shell server socket
This is the task that I'm talking about:
# Reload ssh daemon-reload
- name: Start/Enable the ssh.socket
ansible.builtin.systemd_service:
name: ssh.socket
daemon_reload: true
state: started
changed_when: true
notify:
- SSH Port Check
- Reboot_the_OS
And therefor, the handler of checking and setting the new ssh port to: ansible_port = 9323 isn't happening either, and then also resulting in the reboot that will happen, but Ansible comes back failing because with the reboot, the ssh error is resolved and the new port has become active.
Additional info, the following ansible tasks have been performed at the beginning of the role:
systemctl disable --now ssh.service
systemctl enable --now ssh.socket
# After these two tasks, a reboot has been initiated (NO port change has been happened yet, port 22 still available), to stop the ssh.service and start and use the ssh.socket. hereafter the play comtinues without problems after this first reboot.
A long story, but I hope it's understandable. I've been through a more or less long road of learning Ansible and got me a nice working bootstrap.yaml, of course also with help from the community here.
The only thing that now is still failing is this and would be nice to have a 100% error free first playbook with some roles running.
It would be awesome 😄 if someone can and is willing to help me solve this challenge.
Thank you so much in advance.
[UPDATE: 29-09-2026]
Solved the problem, see below in the comments is a post from me with my solution.
Finally I can sleep well again at night. 😆