Flowm/piot-ansible

fwdc handler with variable in name does not work

RupertAmann opened this issue · 3 comments

TASK [fwdc : Copy fwdc service] ****************************************************************************************
ERROR! The requested handler 'Enable fwdc service' was not found in either the main handlers list nor in the listening handlers list

task:

- name: Copy fwdc service
  template:
    src: "fwdc.service.j2"
    dest: "/etc/systemd/system/{{ fwdc_service_name }}.service"
    owner: "root"
    group: "root"
    mode: 0644
  notify:
    - Enable fwdc service

Handler:

---
- name: "Enable {{ fwdc_service_name }} service"
  systemd:
    name: "{{ fwdc_service_name }}"
    enabled: yes
    state: restarted
    daemon_reload: yes

The handler variable needs to be included, but this still won't work (ansible/ansible#24194).
Why using the variable in the task name, shouldn't it be enough to have it in the systemd part?

additionally, the handler always fails, when being executed via the autossh connection:

RUNNING HANDLER [fwdc : Enable autossh service] ************************************************************************************************
fatal: [eridanus-xxx]: FAILED! => {"msg": "Failed to connect to the host via ssh: ssh: connect to host xxxx: Connection refused"}

obviously, because during the restart the ansible connection is closed as well.

during testing though, the variable in the handler name worked. will make a pull request.

Flowm commented

Thanks for looking into this! Looks good to me 👍