Fixing some v2 bugs

This commit is contained in:
James Cammarata 2015-04-21 12:02:32 -05:00
parent d996a2c216
commit 7669a0b275
3 changed files with 16 additions and 8 deletions

View file

@ -120,7 +120,7 @@ class DataLoader():
return os.path.isdir(path) return os.path.isdir(path)
def list_directory(self, path): def list_directory(self, path):
return os.path.listdir(path) return os.listdir(path)
def _safe_load(self, stream, file_name=None): def _safe_load(self, stream, file_name=None):
''' Implements yaml.safe_load(), except using our custom loader class. ''' ''' Implements yaml.safe_load(), except using our custom loader class. '''

View file

@ -35,4 +35,4 @@ class ActionModule(ActionBase):
if isinstance(v, basestring) and v.lower() in ('true', 'false', 'yes', 'no'): if isinstance(v, basestring) and v.lower() in ('true', 'false', 'yes', 'no'):
v = boolean(v) v = boolean(v)
facts[k] = v facts[k] = v
return dict(changed=True, ansible_facts=facts) return dict(changed=False, ansible_facts=facts)

View file

@ -29,6 +29,7 @@ except ImportError:
from sha import sha as sha1 from sha import sha as sha1
from ansible import constants as C from ansible import constants as C
from ansible.errors import *
from ansible.parsing import DataLoader from ansible.parsing import DataLoader
from ansible.plugins.cache import FactCache from ansible.plugins.cache import FactCache
from ansible.template import Templar from ansible.template import Templar
@ -78,14 +79,19 @@ class VariableManager:
def set_inventory(self, inventory): def set_inventory(self, inventory):
self._inventory = 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): def _combine_vars(self, a, b):
''' '''
Combines dictionaries of variables, based on the hash behavior Combines dictionaries of variables, based on the hash behavior
''' '''
# FIXME: do we need this from utils, or should it just self._validate_both_dicts(a, b)
# be merged into this definition?
#_validate_both_dicts(a, b)
if C.DEFAULT_HASH_BEHAVIOUR == "merge": if C.DEFAULT_HASH_BEHAVIOUR == "merge":
return self._merge_dicts(a, b) return self._merge_dicts(a, b)
@ -100,9 +106,7 @@ class VariableManager:
result = dict() result = dict()
# FIXME: do we need this from utils, or should it just self._validate_both_dicts(a, b)
# be merged into this definition?
#_validate_both_dicts(a, b)
for dicts in a, b: for dicts in a, b:
# next, iterate over b keys and values # next, iterate over b keys and values
@ -183,6 +187,8 @@ class VariableManager:
try: try:
vars_file = templar.template(vars_file) vars_file = templar.template(vars_file)
data = loader.load_from_file(vars_file) data = loader.load_from_file(vars_file)
if data is None:
data = dict()
all_vars = self._combine_vars(all_vars, data) all_vars = self._combine_vars(all_vars, data)
except: except:
# FIXME: get_vars should probably be taking a flag to determine # FIXME: get_vars should probably be taking a flag to determine
@ -258,6 +264,8 @@ class VariableManager:
else: else:
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)