Have group/host var file loading check for YAML extensions too

Fixes #11132
This commit is contained in:
James Cammarata 2015-06-16 11:55:26 -04:00
parent 98e5f73f44
commit 30c1a2d861
2 changed files with 23 additions and 9 deletions

View file

@ -661,11 +661,11 @@ class Inventory(object):
if group and host is None:
# load vars in dir/group_vars/name_of_group
base_path = os.path.join(basedir, "group_vars/%s" % group.name)
self._variable_manager.add_group_vars_file(base_path, self._loader)
results = self._variable_manager.add_group_vars_file(base_path, self._loader)
elif host and group is None:
# same for hostvars in dir/host_vars/name_of_host
base_path = os.path.join(basedir, "host_vars/%s" % host.name)
self._variable_manager.add_host_vars_file(base_path, self._loader)
results = self._variable_manager.add_host_vars_file(base_path, self._loader)
# all done, results is a dictionary of variables for this particular host.
return results

View file

@ -272,9 +272,17 @@ class VariableManager:
data = self._combine_vars(data, results)
else:
data = loader.load_from_file(path)
if data is None:
data = dict()
file_name, ext = os.path.splitext(path)
data = None
if not ext:
for ext in ('', '.yml', '.yaml'):
new_path = path + ext
if loader.path_exists(new_path):
data = loader.load_from_file(new_path)
break
else:
if loader.path_exists(path):
data = loader.load_from_file(path)
name = self._get_inventory_basename(path)
return (name, data)
@ -286,9 +294,12 @@ class VariableManager:
the extension, for matching against a given inventory host name
'''
if loader.path_exists(path):
(name, data) = self._load_inventory_file(path, loader)
(name, data) = self._load_inventory_file(path, loader)
if data:
self._host_vars_files[name] = data
return data
else:
return dict()
def add_group_vars_file(self, path, loader):
'''
@ -297,9 +308,12 @@ class VariableManager:
the extension, for matching against a given inventory host name
'''
if loader.path_exists(path):
(name, data) = self._load_inventory_file(path, loader)
(name, data) = self._load_inventory_file(path, loader)
if data:
self._group_vars_files[name] = data
return data
else:
return dict()
def set_host_facts(self, host, facts):
'''