Problems finding handler after updating 2.7.10 to 2.8.0

21 views
Skip to first unread message

Jan-Philipp Bolle

unread,
Jun 3, 2019, 8:19:05 AM6/3/19
to Ansible Project

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

Matt Martz

unread,
Jun 3, 2019, 9:49:49 AM6/3/19
to ansible...@googlegroups.com
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

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/4eb2e371-d949-4ca4-a292-20faa1634803%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Matt Martz
@sivel
sivel.net

Jan-Philipp Bolle

unread,
Jun 4, 2019, 2:06:20 AM6/4/19
to Ansible Project
Hi Matt 
thanks so much with include_tasks it works.

Best regards
Philipp
Reply all
Reply to author
Forward
0 new messages