Problems finding handler after updating 2.7.10 to 2.8.0

Hi,

In my roles I use the following Handler definition:

`

  • name: restart prometheus
    include: “roles/common/tasks/restart-service.yml service_name=prometheus”
    `

This works fine in 2.7.10.

After updating to 2.8.0 I got the following error:

ERROR! The requested handler ‘restart prometheus’ was not found in either the main handlers list nor in the listening handlers list

I have tried several variants:

`

  • name: restart prometheus
    import_tasks: roles/common/tasks/restart-service.yml
    vars:
    service_name: prometheus
    `

Same Problem.

If I use a simple debug statement it works:

`

  • name: restart prometheus
    debug:
    msg: System {{ inventory_hostname }} has uuid {{ ansible_product_uuid }}

`

I realize that you should avoid dependencies between roles but repeating a block of code over and over doesn’t seem to be a good solution either.

Any idea?

Regards Philipp

You have a few issues, one you have already attempted to address.

  1. Don’t use include as it has behavior that cannot be easily reasoned and understood in many cases
  2. A change was made in Ansible 2.8 that is documented in the porting guide, preventing you from using a static include or import_tasks as a handler itself. This is described in more detail at https://docs.ansible.com/ansible/latest/porting_guides/porting_guide_2.8.html#imports-as-handlers

Effectively, what you need is to switch to include_tasks:

  • name: restart prometheus
    include_tasks: roles/common/tasks/restart-service.yml
    vars:
    service_name: prometheus

Hi Matt
thanks so much with include_tasks it works.

Best regards
Philipp