fix block var inheritance (#75287) (#76897)

* updated tests to conform to new block inheritance

Co-authored-by: Brian Scholer <1260690+briantist@users.noreply.github.com>
Co-authored-by: Sloane Hertel <19572925+s-hertel@users.noreply.github.com>
(cherry picked from commit b1d6750e8b)
pull/77061/head
Brian Coca 3 years ago committed by GitHub
parent 6916e152ff
commit ee112d9984
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- correctly inherit vars from parent in block (https://github.com/ansible/ansible/issues/75286).

@ -79,11 +79,13 @@ class Block(Base, Conditional, CollectionSearch, Taggable):
of a role or task include which does, so return those if present.
'''
all_vars = self.vars.copy()
all_vars = {}
if self._parent:
all_vars.update(self._parent.get_vars())
all_vars.update(self.vars.copy())
return all_vars
@staticmethod

@ -26,4 +26,4 @@
- assert:
that:
- test_role_output.msg == test_role_input
- non_coll_role_to_call_test_role_output.msg == test_role_input

@ -1,7 +1,7 @@
- debug:
msg: '{{ test_role_input | default("(undefined)") }}'
register: test_role_output
register: non_coll_role_to_call_test_role_output
- assert:
that:
- test_role_input is not defined or test_role_input == test_role_output.msg
- 'non_coll_role_to_call_test_role_output.msg == "include another non-coll role"'

@ -0,0 +1,2 @@
shippable/posix/group4
context/controller

@ -0,0 +1,16 @@
- name: outer
vars:
myvar: abc
block:
- assert:
that:
- "myvar == 'abc'"
- name: inner block
vars:
myvar: 123
block:
- assert:
that:
- myvar|int == 123
Loading…
Cancel
Save