diff options
author | Martin Krizek <martin.krizek@gmail.com> | 2023-02-15 20:32:48 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-15 13:32:48 -0600 |
commit | 65366f663de7d044f42ae6dd53368fd4c1f88b35 (patch) | |
tree | b4c4014e9c51de9ed30dfb24ea52ad1f1f001e07 | |
parent | b2f362e6f1cd1acaa9d3d5443ead50440ff468f2 (diff) | |
download | ansible-65366f663de7d044f42ae6dd53368fd4c1f88b35.tar.gz |
Fix conditionally notified include handlers (#79804) (#79807)
Fixes #79776
(cherry picked from commit 10eda5801ad11f66985251b5c3de481e7b917d3c)
-rw-r--r-- | changelogs/fragments/79776-fix-force_handlers-cond-include.yml | 2 | ||||
-rw-r--r-- | lib/ansible/plugins/strategy/linear.py | 6 | ||||
-rw-r--r-- | test/integration/targets/handlers/79776-handlers.yml | 2 | ||||
-rw-r--r-- | test/integration/targets/handlers/79776.yml | 10 | ||||
-rwxr-xr-x | test/integration/targets/handlers/runme.sh | 2 |
5 files changed, 17 insertions, 5 deletions
diff --git a/changelogs/fragments/79776-fix-force_handlers-cond-include.yml b/changelogs/fragments/79776-fix-force_handlers-cond-include.yml new file mode 100644 index 0000000000..8e94a6ed34 --- /dev/null +++ b/changelogs/fragments/79776-fix-force_handlers-cond-include.yml @@ -0,0 +1,2 @@ +bugfixes: + - Fix conditionally notifying ``include_tasks` handlers when ``force_handlers`` is used (https://github.com/ansible/ansible/issues/79776) diff --git a/lib/ansible/plugins/strategy/linear.py b/lib/ansible/plugins/strategy/linear.py index dc34e097bb..a3c91c2942 100644 --- a/lib/ansible/plugins/strategy/linear.py +++ b/lib/ansible/plugins/strategy/linear.py @@ -314,11 +314,7 @@ class StrategyModule(StrategyBase): 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") diff --git a/test/integration/targets/handlers/79776-handlers.yml b/test/integration/targets/handlers/79776-handlers.yml new file mode 100644 index 0000000000..639c9cad06 --- /dev/null +++ b/test/integration/targets/handlers/79776-handlers.yml @@ -0,0 +1,2 @@ +- debug: + msg: "Handler for {{ inventory_hostname }}" diff --git a/test/integration/targets/handlers/79776.yml b/test/integration/targets/handlers/79776.yml new file mode 100644 index 0000000000..08d222724b --- /dev/null +++ b/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 diff --git a/test/integration/targets/handlers/runme.sh b/test/integration/targets/handlers/runme.sh index e2d521805f..887a82db47 100755 --- a/test/integration/targets/handlers/runme.sh +++ b/test/integration/targets/handlers/runme.sh @@ -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 "$@" |