From ff04b2b53270688f28adf13e9a692b72e289148b Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Fri, 4 Jul 2014 22:59:00 -0500 Subject: [PATCH] Allow empty yaml vars files Fixes #7843 --- lib/ansible/inventory/vars_plugins/group_vars.py | 8 ++++---- lib/ansible/playbook/play.py | 1 - lib/ansible/runner/action_plugins/include_vars.py | 4 +++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/ansible/inventory/vars_plugins/group_vars.py b/lib/ansible/inventory/vars_plugins/group_vars.py index 93edceeecb5..96a24318bdd 100644 --- a/lib/ansible/inventory/vars_plugins/group_vars.py +++ b/lib/ansible/inventory/vars_plugins/group_vars.py @@ -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) diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py index bdf71ab5857..9ed12d1e190 100644 --- a/lib/ansible/playbook/play.py +++ b/lib/ansible/playbook/play.py @@ -332,7 +332,6 @@ class Play(object): 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 diff --git a/lib/ansible/runner/action_plugins/include_vars.py b/lib/ansible/runner/action_plugins/include_vars.py index 6c5adac3ee1..d6ce52cf00a 100644 --- a/lib/ansible/runner/action_plugins/include_vars.py +++ b/lib/ansible/runner/action_plugins/include_vars.py @@ -44,8 +44,10 @@ class ActionModule(object): 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: