From cd478a76fc57b6f3d02637cb8d56ae7e9c6e5225 Mon Sep 17 00:00:00 2001 From: h-hirokawa Date: Mon, 7 Sep 2015 12:01:26 +0900 Subject: [PATCH] Add the new module replacer <>. Fixes #12266 --- lib/ansible/executor/module_common.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/ansible/executor/module_common.py b/lib/ansible/executor/module_common.py index 11ee68e7b6d..22f8c2213ba 100644 --- a/lib/ansible/executor/module_common.py +++ b/lib/ansible/executor/module_common.py @@ -33,12 +33,13 @@ from ansible.errors import AnsibleError from ansible.parsing.utils.jsonify import jsonify from ansible.utils.unicode import to_bytes -REPLACER = "#<>" -REPLACER_ARGS = "\"<>\"" -REPLACER_COMPLEX = "\"<>\"" -REPLACER_WINDOWS = "# POWERSHELL_COMMON" -REPLACER_WINARGS = "<>" -REPLACER_VERSION = "\"<>\"" +REPLACER = "#<>" +REPLACER_ARGS = "\"<>\"" +REPLACER_COMPLEX = "\"<>\"" +REPLACER_WINDOWS = "# POWERSHELL_COMMON" +REPLACER_WINARGS = "<>" +REPLACER_JSONARGS = "<>" +REPLACER_VERSION = "\"<>\"" # We could end up writing out parameters with unicode characters so we need to # specify an encoding for the python source file @@ -68,6 +69,8 @@ def _find_snippet_imports(module_data, module_path, strip_comments): module_style = 'new' elif REPLACER_WINDOWS in module_data: module_style = 'new' + elif REPLACER_JSONARGS in module_data: + module_style = 'new' elif 'from ansible.module_utils.' in module_data: module_style = 'new' elif 'WANT_JSON' in module_data: @@ -162,13 +165,14 @@ def modify_module(module_path, module_args, task_vars=dict(), strip_comments=Fal (module_data, module_style) = _find_snippet_imports(module_data, module_path, strip_comments) - module_args_json = json.dumps(module_args) - encoded_args = repr(module_args_json.encode('utf-8')) + module_args_json = json.dumps(module_args).encode('utf-8') + python_repred_args = repr(module_args_json) # these strings should be part of the 'basic' snippet which is required to be included module_data = module_data.replace(REPLACER_VERSION, repr(__version__)) - module_data = module_data.replace(REPLACER_COMPLEX, encoded_args) - module_data = module_data.replace(REPLACER_WINARGS, module_args_json.encode('utf-8')) + module_data = module_data.replace(REPLACER_COMPLEX, python_repred_args) + module_data = module_data.replace(REPLACER_WINARGS, module_args_json) + module_data = module_data.replace(REPLACER_JSONARGS, module_args_json) if module_style == 'new': facility = C.DEFAULT_SYSLOG_FACILITY