Permalink
Browse files

Tweaked merge_hash to also affect Runner behavior

  • Loading branch information...
laggyluke committed Mar 9, 2013
1 parent c4aa72f commit db6ae6b035dfb09243d94c053681aa0d065407a7
Showing with 18 additions and 21 deletions.
  1. +2 −10 lib/ansible/inventory/vars_plugins/group_vars.py
  2. +9 −9 lib/ansible/runner/__init__.py
  3. +7 −2 lib/ansible/utils/__init__.py
@@ -49,22 +49,14 @@ def run(self, host):
data = utils.parse_yaml_from_file(path)
if type(data) != dict:
raise errors.AnsibleError("%s must be stored as a dictionary/hash" % path)
- if C.DEFAULT_HASH_BEHAVIOUR == "merge":
- # let data content override results if needed
- results = utils.merge_hash(results, data)
- else:
- results.update(data)
+ results = utils.combine_vars(results, data);
# load vars in playbook_dir/group_vars/name_of_host
path = os.path.join(basedir, "host_vars/%s" % host.name)
if os.path.exists(path):
data = utils.parse_yaml_from_file(path)
if type(data) != dict:
raise errors.AnsibleError("%s must be stored as a dictionary/hash" % path)
- if C.DEFAULT_HASH_BEHAVIOUR == "merge":
- # let data content override results if needed
- results = utils.merge_hash(results, data)
- else:
- results.update(data)
+ results = utils.combine_vars(results, data);
return results
@@ -173,7 +173,7 @@ def __init__(self,
# ensure we are using unique tmp paths
random.seed()
-
+
# *****************************************************
def _complex_args_hack(self, complex_args, module_args):
@@ -326,9 +326,9 @@ def _executor_internal(self, host):
port = self.remote_port
inject = {}
- inject.update(host_variables)
- inject.update(self.module_vars)
- inject.update(self.setup_cache[host])
+ inject = utils.combine_vars(inject, host_variables)
+ inject = utils.combine_vars(inject, self.module_vars)
+ inject = utils.combine_vars(inject, self.setup_cache[host])
inject['hostvars'] = HostVars(self.setup_cache, self.inventory)
inject['group_names'] = host_variables.get('group_names', [])
inject['groups'] = self.inventory.groups_list()
@@ -478,7 +478,7 @@ def _executor_internal_inner(self, host, module_name, module_args, inject, port,
# all modules get a tempdir, action plugins get one unless they have NEEDS_TMPPATH set to False
if getattr(handler, 'NEEDS_TMPPATH', True):
tmp = self._make_tmp_path(conn)
-
+
result = handler.run(conn, tmp, module_name, module_args, inject, complex_args)
conn.close()
@@ -610,8 +610,8 @@ def _copy_module(self, conn, tmp, module_name, module_args, inject, complex_args
module_data = f.read()
if module_common.REPLACER in module_data:
is_new_style=True
-
- complex_args_json = utils.jsonify(complex_args)
+
+ complex_args_json = utils.jsonify(complex_args)
encoded_args = "\"\"\"%s\"\"\"" % module_args.replace("\"","\\\"")
encoded_lang = "\"\"\"%s\"\"\"" % C.DEFAULT_MODULE_LANG
encoded_complex = "\"\"\"%s\"\"\"" % complex_args_json.replace("\\", "\\\\")
@@ -620,7 +620,7 @@ def _copy_module(self, conn, tmp, module_name, module_args, inject, complex_args
module_data = module_data.replace(module_common.REPLACER_ARGS, encoded_args)
module_data = module_data.replace(module_common.REPLACER_LANG, encoded_lang)
module_data = module_data.replace(module_common.REPLACER_COMPLEX, encoded_complex)
-
+
if is_new_style:
facility = C.DEFAULT_SYSLOG_FACILITY
if 'ansible_syslog_facility' in inject:
@@ -722,7 +722,7 @@ def run(self):
# run once per hostgroup, rather than pausing once per each
# host.
p = utils.plugins.action_loader.get(self.module_name, self)
-
+
if p and getattr(p, 'BYPASS_HOST_LOOP', None):
# Expose the current hostgroup to the bypassing plugins
@@ -300,7 +300,7 @@ def merge_hash(a, b):
for k, v in b.iteritems():
if k in a and isinstance(a[k], dict):
# if this key is a hash and exists in a
- # we recursively call ourselves with
+ # we recursively call ourselves with
# the key value of b
a[k] = merge_hash(a[k], v)
else:
@@ -655,8 +655,13 @@ def get_diff(diff):
return ">> the files are different, but the diff library cannot compare unicode strings"
def is_list_of_strings(items):
- for x in items:
+ for x in items:
if not isinstance(x, basestring):
return False
return True
+def combine_vars(a, b):
+ if C.DEFAULT_HASH_BEHAVIOUR == "merge":
+ return merge_hash(a, b)
+ else:
+ return a.update(b)

0 comments on commit db6ae6b

Please sign in to comment.