mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-26 14:41:23 -07:00
Have group/host var file loading check for YAML extensions too
Fixes #11132
This commit is contained in:
parent
98e5f73f44
commit
30c1a2d861
2 changed files with 23 additions and 9 deletions
|
@ -661,11 +661,11 @@ class Inventory(object):
|
||||||
if group and host is None:
|
if group and host is None:
|
||||||
# load vars in dir/group_vars/name_of_group
|
# load vars in dir/group_vars/name_of_group
|
||||||
base_path = os.path.join(basedir, "group_vars/%s" % group.name)
|
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:
|
elif host and group is None:
|
||||||
# same for hostvars in dir/host_vars/name_of_host
|
# same for hostvars in dir/host_vars/name_of_host
|
||||||
base_path = os.path.join(basedir, "host_vars/%s" % host.name)
|
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.
|
# all done, results is a dictionary of variables for this particular host.
|
||||||
return results
|
return results
|
||||||
|
|
|
@ -272,9 +272,17 @@ class VariableManager:
|
||||||
data = self._combine_vars(data, results)
|
data = self._combine_vars(data, results)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
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)
|
data = loader.load_from_file(path)
|
||||||
if data is None:
|
|
||||||
data = dict()
|
|
||||||
|
|
||||||
name = self._get_inventory_basename(path)
|
name = self._get_inventory_basename(path)
|
||||||
return (name, data)
|
return (name, data)
|
||||||
|
@ -286,9 +294,12 @@ class VariableManager:
|
||||||
the extension, for matching against a given inventory host name
|
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
|
self._host_vars_files[name] = data
|
||||||
|
return data
|
||||||
|
else:
|
||||||
|
return dict()
|
||||||
|
|
||||||
def add_group_vars_file(self, path, loader):
|
def add_group_vars_file(self, path, loader):
|
||||||
'''
|
'''
|
||||||
|
@ -297,9 +308,12 @@ class VariableManager:
|
||||||
the extension, for matching against a given inventory host name
|
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
|
self._group_vars_files[name] = data
|
||||||
|
return data
|
||||||
|
else:
|
||||||
|
return dict()
|
||||||
|
|
||||||
def set_host_facts(self, host, facts):
|
def set_host_facts(self, host, facts):
|
||||||
'''
|
'''
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue