Commit 3865c505 by Brian Coca

Merge pull request #11058 from srvg/bug/11017

limit extensions for files in group/host_vars dir
parents c87586e9 b92d70c5
...@@ -1617,7 +1617,9 @@ def _load_vars_from_folder(folder_path, results, vault_password=None): ...@@ -1617,7 +1617,9 @@ def _load_vars_from_folder(folder_path, results, vault_password=None):
names.sort() names.sort()
# do not parse hidden files or dirs, e.g. .svn/ # do not parse hidden files or dirs, e.g. .svn/
paths = [os.path.join(folder_path, name) for name in names if not name.startswith('.')] paths = [os.path.join(folder_path, name) for name in names
if not name.startswith('.')
and os.path.splitext(name)[1] in C.YAML_FILENAME_EXTENSIONS]
for path in paths: for path in paths:
_found, results = _load_vars_from_path(path, results, vault_password=vault_password) _found, results = _load_vars_from_path(path, results, vault_password=vault_password)
return results return results
......
...@@ -56,7 +56,7 @@ class TestInventory(unittest.TestCase): ...@@ -56,7 +56,7 @@ class TestInventory(unittest.TestCase):
'thrudgelmir0', 'thrudgelmir1', 'thrudgelmir2', 'thrudgelmir0', 'thrudgelmir1', 'thrudgelmir2',
'thrudgelmir3', 'thrudgelmir4', 'thrudgelmir5', 'thrudgelmir3', 'thrudgelmir4', 'thrudgelmir5',
'Hotep-a', 'Hotep-b', 'Hotep-c', 'Hotep-a', 'Hotep-b', 'Hotep-c',
'BastC', 'BastD', 'neptun', ] 'BastC', 'BastD', 'neptun', 'goldorak', ]
##################################### #####################################
### Empty inventory format tests ### Empty inventory format tests
...@@ -222,6 +222,11 @@ class TestInventory(unittest.TestCase): ...@@ -222,6 +222,11 @@ class TestInventory(unittest.TestCase):
inventory.subset('@' + os.path.join(self.test_dir, 'restrict_pattern')) inventory.subset('@' + os.path.join(self.test_dir, 'restrict_pattern'))
self.assertEqual(sorted(inventory.list_hosts()), sorted(['thor','odin'])) self.assertEqual(sorted(inventory.list_hosts()), sorted(['thor','odin']))
def test_vars_yaml_extension(self):
inventory = self.simple_inventory()
vars = inventory.get_variables('goldorak')
assert vars['YAML_FILENAME_EXTENSIONS_TEST']
@raises(errors.AnsibleError) @raises(errors.AnsibleError)
def testinvalid_entry(self): def testinvalid_entry(self):
Inventory('1234') Inventory('1234')
......
---
YAML_FILENAME_EXTENSIONS_TEST: False
---
YAML_FILENAME_EXTENSIONS_TEST: False
---
YAML_FILENAME_EXTENSIONS_TEST: True
...@@ -20,3 +20,9 @@ Bast[C:D] ...@@ -20,3 +20,9 @@ Bast[C:D]
[auth] [auth]
neptun auth="YWRtaW46YWRtaW4=" neptun auth="YWRtaW46YWRtaW4="
[parse:children]
noparse
[noparse]
goldorak
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment