Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible-playbook: directly run handler

Is there a way to directly run handler by ansible-playbook?

For example, i have handler restart service in my role and sometimes i want just trigger it directly without deploying whole app.

like image 964
rootatdarkstar Avatar asked Oct 19 '16 19:10

rootatdarkstar


People also ask

How is a handler invoked in Ansible?

In a nutshell, handlers are special tasks that only get executed when triggered via the notify directive. Handlers are executed at the end of the play, once all tasks are finished. In Ansible, handlers are typically used to start, reload, restart, and stop services.

How do I control Ansible playbook only on specific hosts?

Using the --limit parameter of the ansible-playbook command is the easiest option to limit the execution of the code to only one host. The advantage is that you don't need to edit the Ansible Playbook code before executing to only one host.

What is difference between tasks and handlers in Ansible?

In Ansible, handlers are just like any regular tasks. The difference between handlers and regular tasks is that handlers only run when 'notified' using the notify directive.

How do I run a single task in Ansible playbook?

The easiest way to run only one task in Ansible Playbook is using the tags statement parameter of the “ansible-playbook” command. The default behavior is to execute all the tags in your Playbook with --tags all .


1 Answers

There are a number of options answered in a similar post on ServerFault. In summary:

Options for triggering a particular handler:

  • Use a no-op command to trigger it
  • Use a debug with changed_when: true to trigger it

Options for triggering all handlers:

  • Run with --force-handlers
  • Use a meta: flush_handlers task

Options for re-architecting:

  • Use a task instead
like image 198
Xiong Chiamiov Avatar answered Nov 13 '22 07:11

Xiong Chiamiov