Skip to content

Commit

Permalink
Fix conditionally notified include handlers (#79804) (#79807)
Browse files Browse the repository at this point in the history
Fixes #79776

(cherry picked from commit 10eda58)
  • Loading branch information
mkrizek committed Feb 15, 2023
1 parent b2f362e commit 65366f6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
@@ -0,0 +1,2 @@
bugfixes:
- Fix conditionally notifying ``include_tasks` handlers when ``force_handlers`` is used (https://github.com/ansible/ansible/issues/79776)
6 changes: 1 addition & 5 deletions lib/ansible/plugins/strategy/linear.py
Expand Up @@ -314,11 +314,7 @@ def run(self, iterator, play_context):
included_tasks.extend(final_block.get_tasks())

for host in hosts_left:
# handlers are included regardless of _hosts so noop
# tasks do not have to be created for lockstep,
# not notified handlers are then simply skipped
# in the PlayIterator
if host in included_file._hosts or is_handler:
if host in included_file._hosts:
all_blocks[host].append(final_block)

display.debug("done iterating over new_blocks loaded from include file")
Expand Down
2 changes: 2 additions & 0 deletions test/integration/targets/handlers/79776-handlers.yml
@@ -0,0 +1,2 @@
- debug:
msg: "Handler for {{ inventory_hostname }}"
10 changes: 10 additions & 0 deletions test/integration/targets/handlers/79776.yml
@@ -0,0 +1,10 @@
- hosts: A,B
gather_facts: false
force_handlers: true
tasks:
- command: echo
notify: handler1
when: inventory_hostname == "A"
handlers:
- name: handler1
include_tasks: 79776-handlers.yml
2 changes: 2 additions & 0 deletions test/integration/targets/handlers/runme.sh
Expand Up @@ -170,3 +170,5 @@ ansible-playbook test_flush_handlers_rescue_always.yml -i inventory.handlers "$@
ansible-playbook test_fqcn_meta_flush_handlers.yml -i inventory.handlers "$@" 2>&1 | tee out.txt
grep out.txt -e "handler ran"
grep out.txt -e "after flush"

ansible-playbook 79776.yml -i inventory.handlers "$@"

0 comments on commit 65366f6

Please sign in to comment.