From 2e62e3659030d6ce1c9a0a7c43f29631aa4286a9 Mon Sep 17 00:00:00 2001 From: Andrey Laguta <13280256+laevilgenius@users.noreply.github.com> Date: Wed, 20 Jun 2018 23:49:34 +0300 Subject: [PATCH] Fix multiple var files combining (followup to #36357) --- lib/ansible/playbook/role/__init__.py | 2 +- test/units/playbook/role/test_role.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/ansible/playbook/role/__init__.py b/lib/ansible/playbook/role/__init__.py index 51ee5a0b58..b3b04976f6 100644 --- a/lib/ansible/playbook/role/__init__.py +++ b/lib/ansible/playbook/role/__init__.py @@ -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 diff --git a/test/units/playbook/role/test_role.py b/test/units/playbook/role/test_role.py index 3730b43d56..b902aeca75 100644 --- a/test/units/playbook/role/test_role.py +++ b/test/units/playbook/role/test_role.py @@ -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):