From 77e404b90d9cbf38a321d1ce6e4d512bd155194f Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Sun, 8 Feb 2026 15:48:16 +0100 Subject: [PATCH] chore(ansible): force notify handlers --- snippets/ansible/tasks/control flows.yml | 21 +++++++++++++++++-- .../tasks/delegate tasks to other hosts.yml | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/snippets/ansible/tasks/control flows.yml b/snippets/ansible/tasks/control flows.yml index 82469d1..e2435bd 100644 --- a/snippets/ansible/tasks/control flows.yml +++ b/snippets/ansible/tasks/control flows.yml @@ -1,7 +1,11 @@ --- - name: Do nothing - tags: noop + # this really does nothing; it also *cannot* be considered 'changed', 'failed', or 'skipped' + tags: + - do nothing + - noop + - pass ansible.builtin.meta: noop - name: Execute long-running tasks @@ -49,7 +53,20 @@ fail_msg: What to say if any of the above conditions fail success_msg: What to say if all of the above conditions succeed -- name: Force execution of *notified* handlers +- name: Notify handlers + tags: notify_handlers + delegate_to: localhost + connection: local + ansible.builtin.command: 'true' + changed_when: + # the 'command' module currently always registers as 'changed' + # this is only here to ensure the task notifies the handlers in the event "command"'s behaviour changes in time + true + notify: + - some handler + - some other handler + +- name: Force execution of handlers that have been *notified* up to now tags: force_handlers ansible.builtin.meta: flush_handlers diff --git a/snippets/ansible/tasks/delegate tasks to other hosts.yml b/snippets/ansible/tasks/delegate tasks to other hosts.yml index 7ca69ee..797bd99 100644 --- a/snippets/ansible/tasks/delegate tasks to other hosts.yml +++ b/snippets/ansible/tasks/delegate tasks to other hosts.yml @@ -4,7 +4,7 @@ # No groups - name: Forcefully run on the controller - delegate_to: 127.0.0.1 + delegate_to: 127.0.0.1 # or 'localhost' connection: local changed_when: false ansible.builtin.command: hostname