Skip to content

Commit

Permalink
include_role: expose vars from parent roles to role's handlers (ansib…
Browse files Browse the repository at this point in the history
…le#81524)

* include_role: expose vars from parent roles to role's handlers

Fixes ansible#80459
  • Loading branch information
mkrizek committed Aug 17, 2023
1 parent a2673cb commit 98f1627
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelogs/fragments/80459-handlers-nested-includes-vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- include_role - expose variables from parent roles to role's handlers (https://github.com/ansible/ansible/issues/80459)
2 changes: 1 addition & 1 deletion lib/ansible/playbook/role_include.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def get_block_list(self, play=None, variable_manager=None, loader=None):
b.collections = actual_role.collections

# updated available handlers in play
handlers = actual_role.get_handler_blocks(play=myplay)
handlers = actual_role.get_handler_blocks(play=myplay, dep_chain=dep_chain)
for h in handlers:
h._parent = p_block
myplay.handlers = myplay.handlers + handlers
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v: foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- include_role:
name: r2-dep_chain-vars
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: h
assert:
that:
- v is defined
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- command: echo
notify: h
2 changes: 2 additions & 0 deletions test/integration/targets/handlers/runme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,5 @@ ansible-playbook test_include_role_handler_once.yml -i inventory.handlers "$@" 2

ansible-playbook test_listen_role_dedup.yml "$@" 2>&1 | tee out.txt
[ "$(grep out.txt -ce 'a handler from a role')" = "1" ]

ansible localhost -m include_role -a "name=r1-dep_chain-vars" "$@"

0 comments on commit 98f1627

Please sign in to comment.