Skip to content

Commit

Permalink
Incorporate suggestions from @felixfontein
Browse files Browse the repository at this point in the history
Make the loop trigger even more explicit.
  • Loading branch information
lod committed Oct 16, 2024
1 parent a12ff54 commit 1b6123a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion docs/docsite/rst/playbook_guide/playbooks_handlers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,16 @@ Notifying and loops

Tasks can use loops to notify handlers. This is particularly useful when combined with variables to trigger multiple dynamic notifications.

Note that the handlers are triggered if the task as a whole is changed. When a loop is used the changed state is set if any of the loop items are changed. That is, any change triggers all of the handlers.

.. code-block:: yaml
tasks:
- name: Template services
ansible.builtin.template:
src: "{{ item }}.j2"
dest: /etc/systemd/system/{{ item }}.service
# Note: if *any* loop iteration triggers a change, *all* handlers are run
notify: Restart {{ item }}
loop:
- memcached
Expand All @@ -107,7 +110,6 @@ Tasks can use loops to notify handlers. This is particularly useful when combine
name: apache
state: restarted
Note that the handlers are triggered if the task as a whole is changed, for loops that is if any loop item changes.
In the above example both memcached and apache will be restarted if either template file is changed, neither will be restarted if no file changes.


Expand Down

0 comments on commit 1b6123a

Please sign in to comment.