My playbook
---
- name: Nuovo server GV
gather_facts: no
hosts:
- new-gv.vm
roles:
- ssh_configuration
handlers:
- name: Restart sshd
service:
name: sshd
state: restarted
In the ssh_configuration
tasks file there is this
- name: Setup alternate SSH port
become: yes
become_method: su
become_user: root
lineinfile:
dest: "/etc/ssh/sshd_config"
regexp: "^Port"
line: "Port {{ configured_port }}"
notify:
- Restart sshd
The problem is that Restart sshd is NOT executed.
I tried and retried a lot of times a clean restart and I am sure: the addition of the "Port 1122" line is added into remote host file.
I ask you how to diagnose the problem, I cannot understand if handler is not fired or is broken for some reason.
I also tried adding
- name: Ensure SSH is reloaded if need be
meta: flush_handlers
In the -vvvv
mode I can see ONLY
META: ran handlers
But I expected a section "RUN HANDLER", if I am not remembering wrong
I'm sure this is not an Ansible Bug, it's only due to my inexperience
include_tasks
step. It is not needed. I think you are mixing up scopes here. What you are trying is to use a handler from a play in a role, which won't work. However you can use a handler from a role in a play where you are using that role.