Properly handle group/host_var files with dots in them

Fixes #12245
pull/10527/merge
James Cammarata 9 years ago
parent 1eb5b42705
commit ac6f61ec7f

@ -317,9 +317,9 @@ class VariableManager:
else:
file_name, ext = os.path.splitext(path)
data = None
if not ext:
for ext in C.YAML_FILENAME_EXTENSIONS:
new_path = path + ext
if not ext or ext not in C.YAML_FILENAME_EXTENSIONS:
for test_ext in C.YAML_FILENAME_EXTENSIONS:
new_path = path + test_ext
if loader.path_exists(new_path):
data = loader.load_from_file(new_path)
break

@ -75,6 +75,9 @@ class TestVariableManager(unittest.TestCase):
foo: bam
baa: bat
""",
"host_vars/host.name.yml": """
host_with_dots: true
""",
})
v = VariableManager()
@ -92,6 +95,9 @@ class TestVariableManager(unittest.TestCase):
self.assertEqual(v.get_vars(loader=fake_loader, host=mock_host, use_cache=False).get("foo"), "bam")
self.assertEqual(v.get_vars(loader=fake_loader, host=mock_host, use_cache=False).get("baa"), "bat")
v.add_host_vars_file("host_vars/host.name", loader=fake_loader)
self.assertEqual(v._host_vars_files["host.name"], [dict(host_with_dots=True)])
def test_variable_manager_group_vars_file(self):
fake_loader = DictDataLoader({
"group_vars/all.yml": """
@ -102,7 +108,10 @@ class TestVariableManager(unittest.TestCase):
""",
"other_path/group_vars/somegroup.yml": """
baa: bat
"""
""",
"group_vars/some.group.yml": """
group_with_dots: true
""",
})
v = VariableManager()
@ -128,6 +137,9 @@ class TestVariableManager(unittest.TestCase):
self.assertEqual(vars.get("foo"), "bar")
self.assertEqual(vars.get("baa"), "bat")
v.add_group_vars_file("group_vars/some.group", loader=fake_loader)
self.assertEqual(v._group_vars_files["some.group"], [dict(group_with_dots=True)])
def test_variable_manager_play_vars(self):
fake_loader = DictDataLoader({})

Loading…
Cancel
Save