Fix multiple var files combining (followup to #36357)
This commit is contained in:
parent
cadbd6ea9c
commit
2e62e36590
2 changed files with 23 additions and 1 deletions
|
@ -262,7 +262,7 @@ class Role(Base, Become, Conditional, Taggable):
|
|||
data = combine_vars(data, new_data)
|
||||
else:
|
||||
data = new_data
|
||||
return data
|
||||
return data
|
||||
elif main is not None:
|
||||
raise AnsibleParserError("Could not find specified file in role: %s/%s" % (subdir, main))
|
||||
return None
|
||||
|
|
|
@ -249,6 +249,28 @@ class TestRole(unittest.TestCase):
|
|||
self.assertEqual(r._default_vars, dict(foo='bar'))
|
||||
self.assertEqual(r._role_vars, dict(foo='bam'))
|
||||
|
||||
@patch('ansible.playbook.role.definition.unfrackpath', mock_unfrackpath_noop)
|
||||
def test_load_role_with_vars_nested_dirs_combined(self):
|
||||
|
||||
fake_loader = DictDataLoader({
|
||||
"/etc/ansible/roles/foo_vars/defaults/main/foo/bar.yml": """
|
||||
foo: bar
|
||||
a: 1
|
||||
""",
|
||||
"/etc/ansible/roles/foo_vars/defaults/main/bar/foo.yml": """
|
||||
foo: bam
|
||||
b: 2
|
||||
""",
|
||||
})
|
||||
|
||||
mock_play = MagicMock()
|
||||
mock_play.ROLE_CACHE = {}
|
||||
|
||||
i = RoleInclude.load('foo_vars', play=mock_play, loader=fake_loader)
|
||||
r = Role.load(i, play=mock_play)
|
||||
|
||||
self.assertEqual(r._default_vars, dict(foo='bar', a=1, b=2))
|
||||
|
||||
@patch('ansible.playbook.role.definition.unfrackpath', mock_unfrackpath_noop)
|
||||
def test_load_role_with_vars_dir_vs_file(self):
|
||||
|
||||
|
|
Loading…
Reference in a new issue