Double-click on the image to zoom-out ...Larger.
To return to Home page: Refresh Page or Take ESC Button on Keyboard
The difference between tasks and handlers with reference to Ansible playbook
In Ansible playbooks, tasks and handlers serve distinct purposes:
Tasks:
- Tasks are the basic units of work in an Ansible playbook. They define the actions that should be executed on the managed nodes.
- Each task specifies a module (e.g.,
apt
,yum
,copy
,file
, etc.) and the parameters required for that module to perform the desired operation. - Tasks run sequentially, and they are always executed when the playbook is run, unless conditions such as
when
statements orchanged_when
are used to control execution.
Example:
Handlers:
- Handlers are special types of tasks that are only executed when notified by other tasks.
- A handler is typically used for tasks that should only run if something has changed, such as restarting a service after a configuration file has been modified.
- Handlers are defined in the
handlers
section of a playbook and are triggered by other tasks using thenotify
directive.
Example:
Key Differences:
- Execution: Tasks always run when the playbook is executed,
- whereas, handlers run only when they are notified by other tasks.
- Purpose: Tasks define the main actions to be performed (e.g., install software),
- Meanwhile, handlers typically perform actions triggered by changes (e.g., restart a service after a configuration change).
No comments:
Post a Comment