Allow '.yml'/'.yaml' extension on group_vars files.
Look for a file with the base name of the group/host, first without a file extension, then with a '.yml' extension, and, finally, with a '.yaml' extension, loading vars from only the first one found.
This commit is contained in:
parent
454076590c
commit
863cb50530
1 changed files with 19 additions and 13 deletions
|
@ -44,7 +44,9 @@ class VarsModule(object):
|
|||
|
||||
# load vars in inventory_dir/group_vars/name_of_group
|
||||
for x in groups:
|
||||
path = os.path.join(basedir, "group_vars/%s" % x)
|
||||
p = os.path.join(basedir, "group_vars/%s" % x)
|
||||
paths = [p, '.'.join([p, 'yml']), '.'.join([p, 'yaml'])]
|
||||
for path in paths:
|
||||
if os.path.exists(path):
|
||||
data = utils.parse_yaml_from_file(path)
|
||||
if type(data) != dict:
|
||||
|
@ -54,9 +56,12 @@ class VarsModule(object):
|
|||
results = utils.merge_hash(results, data)
|
||||
else:
|
||||
results.update(data)
|
||||
break
|
||||
|
||||
# load vars in inventory_dir/hosts_vars/name_of_host
|
||||
path = os.path.join(basedir, "host_vars/%s" % host.name)
|
||||
p = os.path.join(basedir, "host_vars/%s" % host.name)
|
||||
paths = [p, '.'.join([p, 'yml']), '.'.join([p, 'yaml'])]
|
||||
for path in paths:
|
||||
if os.path.exists(path):
|
||||
data = utils.parse_yaml_from_file(path)
|
||||
if type(data) != dict:
|
||||
|
@ -66,5 +71,6 @@ class VarsModule(object):
|
|||
results = utils.merge_hash(results, data)
|
||||
else:
|
||||
results.update(data)
|
||||
break
|
||||
return results
|
||||
|
||||
|
|
Loading…
Reference in a new issue