Do not allow handlers from dynamic includes to be notified (#78399)

* Do not allow handlers from dynamic includes to be notified
pull/78419/head
Martin Krizek 2 years ago committed by GitHub
parent f6d2b18322
commit ce6c9befb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- Do not allow handlers from dynamic includes to be notified (https://github.com/ansible/ansible/pull/78399)

@ -1028,7 +1028,6 @@ class StrategyBase:
# for every task in each block brought in by the include, add the list
# of hosts which included the file to the notified_handlers dict
for block in new_blocks:
iterator._play.handlers.append(block)
for task in block.block:
task_name = task.get_name()
display.debug("adding task '%s' included in handler '%s'" % (task_name, handler_name))

@ -118,3 +118,8 @@ grep out.txt -e "\[WARNING\]: Handler 'handler name with {{ test_var }}' is unus
# Test include_role and import_role cannot be used as handlers
ansible-playbook test_role_as_handler.yml "$@" 2>&1 | tee out.txt
grep out.txt -e "ERROR! Using 'include_role' as a handler is not supported."
# Test notifying a handler from within include_tasks does not work anymore
ansible-playbook test_notify_included.yml "$@" 2>&1 | tee out.txt
[ "$(grep out.txt -ce 'I was included')" = "1" ]
grep out.txt -e "ERROR! The requested handler 'handler_from_include' was not found in either the main handlers list nor in the listening handlers list"

@ -0,0 +1,3 @@
- name: handler_from_include
debug:
msg: I was included

@ -0,0 +1,16 @@
- name: This worked unintentionally, make sure it does not anymore
hosts: localhost
gather_facts: false
tasks:
- command: echo
notify:
- include_handler
- meta: flush_handlers
- command: echo
notify:
- handler_from_include
handlers:
- name: include_handler
include_tasks: test_notify_included-handlers.yml
Loading…
Cancel
Save