From 04da466c7b9a1279ca4e107a20672521cc28d2b0 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Wed, 27 Aug 2014 10:20:07 -0500 Subject: [PATCH] Fixing up serialize_args utility function --- lib/ansible/runner/__init__.py | 6 ------ lib/ansible/utils/__init__.py | 21 +++++++++++++-------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index 67638e19b9..afff26071e 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -49,7 +49,6 @@ from ansible.module_common import ModuleReplacer from ansible.module_utils.splitter import split_args from ansible.cache import FactCache from ansible.utils import update_hash -from ansible.utils import OMIT_PLACE_HOLDER module_replacer = ModuleReplacer(strip_comments=False) @@ -629,13 +628,8 @@ class Runner(object): inject['vars'] = self.module_vars inject['defaults'] = self.default_vars inject['environment'] = self.environment -<<<<<<< HEAD inject['playbook_dir'] = os.path.abspath(self.basedir) - inject['omit'] = OMIT_PLACE_HOLDER -======= - inject['playbook_dir'] = self.basedir inject['omit'] = self.omit_token ->>>>>>> Additional fixes for the new omit parameter variable # template this one is available, callbacks use this delegate_to = self.module_vars.get('delegate_to') diff --git a/lib/ansible/utils/__init__.py b/lib/ansible/utils/__init__.py index a2500c407d..aa0a1b8ee7 100644 --- a/lib/ansible/utils/__init__.py +++ b/lib/ansible/utils/__init__.py @@ -545,6 +545,18 @@ def parse_json(raw_data, from_remote=False, from_inventory=False): return results +def serialize_args(args): + ''' + Flattens a dictionary args to a k=v string + ''' + module_args = "" + for (k,v) in args.iteritems(): + if isinstance(v, basestring): + module_args = "%s=%s %s" % (k, pipes.quote(v), module_args) + elif isinstance(v, bool): + module_args = "%s=%s %s" % (k, str(v), module_args) + return module_args.strip() + def merge_module_args(current_args, new_args): ''' merges either a dictionary or string of k=v pairs with another string of k=v pairs, @@ -559,14 +571,7 @@ def merge_module_args(current_args, new_args): elif isinstance(new_args, basestring): new_args_kv = parse_kv(new_args) final_args.update(new_args_kv) - # then we re-assemble into a string - module_args = "" - for (k,v) in final_args.iteritems(): - if isinstance(v, basestring): - module_args = "%s=%s %s" % (k, pipes.quote(v), module_args) - elif isinstance(v, bool): - module_args = "%s=%s %s" % (k, str(v), module_args) - return module_args.strip() + return serialize_args(final_args) def parse_yaml(data, path_hint=None): ''' convert a yaml string to a data structure. Also supports JSON, ssssssh!!!'''