Run Handlers like a task

We have playbook that didn’t have the force_handlers directive. They ended up failing and of course, they re-run instead and the handlers never got run for completed tasks.

I’ve searched but couldn’t find something related to run a specific tasks which would be the handler itself. Something nice would be :

ansible-playbook book.yml --run-handler “My handler”

Anything similar to do that?

Thanks.

no, but you can try something like this:

- debug: msg="execute {{handler}}"
  changed_when: True
  when: handler is defined
  notify: "{{handler}}"
  tags: ['handler']

then use `--tags 'handler' -e 'handler="name of handler"' ` on the command line

Thanks, that can be useful.