From 7669a0b275639c46b847d9a6703d25298adb27b3 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Tue, 21 Apr 2015 12:02:32 -0500 Subject: [PATCH] Fixing some v2 bugs --- v2/ansible/parsing/__init__.py | 2 +- v2/ansible/plugins/action/set_fact.py | 2 +- v2/ansible/vars/__init__.py | 20 ++++++++++++++------ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/v2/ansible/parsing/__init__.py b/v2/ansible/parsing/__init__.py index bce5b2b667..bf96fba842 100644 --- a/v2/ansible/parsing/__init__.py +++ b/v2/ansible/parsing/__init__.py @@ -120,7 +120,7 @@ class DataLoader(): return os.path.isdir(path) def list_directory(self, path): - return os.path.listdir(path) + return os.listdir(path) def _safe_load(self, stream, file_name=None): ''' Implements yaml.safe_load(), except using our custom loader class. ''' diff --git a/v2/ansible/plugins/action/set_fact.py b/v2/ansible/plugins/action/set_fact.py index a7ddf10b47..6086ee6e8b 100644 --- a/v2/ansible/plugins/action/set_fact.py +++ b/v2/ansible/plugins/action/set_fact.py @@ -35,4 +35,4 @@ class ActionModule(ActionBase): if isinstance(v, basestring) and v.lower() in ('true', 'false', 'yes', 'no'): v = boolean(v) facts[k] = v - return dict(changed=True, ansible_facts=facts) + return dict(changed=False, ansible_facts=facts) diff --git a/v2/ansible/vars/__init__.py b/v2/ansible/vars/__init__.py index 183116ea2d..f30d52b7a3 100644 --- a/v2/ansible/vars/__init__.py +++ b/v2/ansible/vars/__init__.py @@ -29,6 +29,7 @@ except ImportError: from sha import sha as sha1 from ansible import constants as C +from ansible.errors import * from ansible.parsing import DataLoader from ansible.plugins.cache import FactCache from ansible.template import Templar @@ -78,14 +79,19 @@ class VariableManager: def set_inventory(self, inventory): self._inventory = inventory + def _validate_both_dicts(self, a, b): + ''' + Validates that both arguments are dictionaries, or an error is raised. + ''' + if not (isinstance(a, dict) and isinstance(b, dict)): + raise AnsibleError("failed to combine variables, expected dicts but got a '%s' and a '%s'" % (type(a).__name__, type(b).__name__)) + def _combine_vars(self, a, b): ''' Combines dictionaries of variables, based on the hash behavior ''' - # FIXME: do we need this from utils, or should it just - # be merged into this definition? - #_validate_both_dicts(a, b) + self._validate_both_dicts(a, b) if C.DEFAULT_HASH_BEHAVIOUR == "merge": return self._merge_dicts(a, b) @@ -100,9 +106,7 @@ class VariableManager: result = dict() - # FIXME: do we need this from utils, or should it just - # be merged into this definition? - #_validate_both_dicts(a, b) + self._validate_both_dicts(a, b) for dicts in a, b: # next, iterate over b keys and values @@ -183,6 +187,8 @@ class VariableManager: try: vars_file = templar.template(vars_file) data = loader.load_from_file(vars_file) + if data is None: + data = dict() all_vars = self._combine_vars(all_vars, data) except: # FIXME: get_vars should probably be taking a flag to determine @@ -258,6 +264,8 @@ class VariableManager: else: data = loader.load_from_file(path) + if data is None: + data = dict() name = self._get_inventory_basename(path) return (name, data)