--- - name: Restart sshd ansible.builtin.systemd: name: sshd state: restarted listen: Restart sshd - name: Update ansible port ansible.builtin.set_fact: ansible_port: "{{ ssh_new_port }}" listen: Update ansible port - name: Wait for new SSH port ansible.builtin.wait_for: port: "{{ ssh_new_port }}" host: "{{ ansible_host }}" delay: 5 timeout: 60 delegate_to: localhost become: false listen: Wait for new SSH port