Skip to content

Commit

Permalink
Allow empty yaml vars files
Browse files Browse the repository at this point in the history
  • Loading branch information
jimi-c committed Jul 5, 2014
1 parent 51e014d commit ff04b2b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions lib/ansible/inventory/vars_plugins/group_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ def _load_vars_from_path(path, results, vault_password=None):
# regular file
elif stat.S_ISREG(pathstat.st_mode):
data = utils.parse_yaml_from_file(path, vault_password=vault_password)
if type(data) != dict:
raise errors.AnsibleError(
"%s must be stored as a dictionary/hash" % path)

if data and type(data) != dict:
raise errors.AnsibleError("%s must be stored as a dictionary/hash" % path)
elif data is None:
data = {}
# combine vars overrides by default but can be configured to do a
# hash merge in settings
results = utils.combine_vars(results, data)
Expand Down
1 change: 0 additions & 1 deletion lib/ansible/playbook/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ def _load_role_defaults(self, defaults_files):
if new_default_vars:
if type(new_default_vars) != dict:
raise errors.AnsibleError("%s must be stored as dictionary/hash: %s" % (filename, type(new_default_vars)))

default_vars = utils.combine_vars(default_vars, new_default_vars)

return default_vars
Expand Down
4 changes: 3 additions & 1 deletion lib/ansible/runner/action_plugins/include_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ def run(self, conn, tmp, module_name, module_args, inject, complex_args=None, **

if os.path.exists(source):
data = utils.parse_yaml_from_file(source, vault_password=self.runner.vault_pass)
if type(data) != dict:
if data and type(data) != dict:
raise errors.AnsibleError("%s must be stored as a dictionary/hash" % source)
elif data is None:
data = {}
result = dict(ansible_facts=data)
return ReturnData(conn=conn, comm_ok=True, result=result)
else:
Expand Down

0 comments on commit ff04b2b

Please sign in to comment.