Repository: ansible/ansible

Issue:
Add "<<INCLUDE_ANSIBLE_MODULE_JSON_ARGS>>" replacer for non-Python modules.
In v2, the module-arguments file are no more passed to any modules, even if the style of the modules are `non_native_want_json` or `old`.
So, we have to embed `<<INCLUDE_ANSIBLE_MODULE_WINDOWS_ARGS>>` replacer in non-Python (nor PS1) modules to pass module-arguments.
It seems the name of the replacer is some kind of confusing, and adding the new replacer `<<INCLUDE_ANSIBLE_MODULE_JSON_ARGS>>`, the alias of `<<INCLUDE_ANSIBLE_MODULE_WINDOWS_ARGS>>`, would be helpful.



Discussion:

Resolving patch:
diff --git a/lib/ansible/executor/module_common.py b/lib/ansible/executor/module_common.py
--- a/lib/ansible/executor/module_common.py
+++ b/lib/ansible/executor/module_common.py
@@ -33,12 +33,13 @@
 from ansible.parsing.utils.jsonify import jsonify
 from ansible.utils.unicode import to_bytes
 
-REPLACER         = "#<<INCLUDE_ANSIBLE_MODULE_COMMON>>"
-REPLACER_ARGS    = "\"<<INCLUDE_ANSIBLE_MODULE_ARGS>>\""
-REPLACER_COMPLEX = "\"<<INCLUDE_ANSIBLE_MODULE_COMPLEX_ARGS>>\""
-REPLACER_WINDOWS = "# POWERSHELL_COMMON"
-REPLACER_WINARGS = "<<INCLUDE_ANSIBLE_MODULE_WINDOWS_ARGS>>"
-REPLACER_VERSION = "\"<<ANSIBLE_VERSION>>\""
+REPLACER          = "#<<INCLUDE_ANSIBLE_MODULE_COMMON>>"
+REPLACER_ARGS     = "\"<<INCLUDE_ANSIBLE_MODULE_ARGS>>\""
+REPLACER_COMPLEX  = "\"<<INCLUDE_ANSIBLE_MODULE_COMPLEX_ARGS>>\""
+REPLACER_WINDOWS  = "# POWERSHELL_COMMON"
+REPLACER_WINARGS  = "<<INCLUDE_ANSIBLE_MODULE_WINDOWS_ARGS>>"
+REPLACER_JSONARGS = "<<INCLUDE_ANSIBLE_MODULE_JSON_ARGS>>"
+REPLACER_VERSION  = "\"<<ANSIBLE_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


Test patch: