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.
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.
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.
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.
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 .
There are a number of options answered in a similar post on ServerFault. In summary:
Options for triggering a particular handler:
command
to trigger itdebug
with changed_when: true
to trigger itOptions for triggering all handlers:
--force-handlers
meta: flush_handlers
taskOptions for re-architecting:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With