summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToshio Kuratomi <toshio@fedoraproject.org>2015-09-21 01:46:29 -0700
committerToshio Kuratomi <toshio@fedoraproject.org>2015-09-21 01:46:29 -0700
commit2a614c1c0fa522eb7dbf9354826264465a6464de (patch)
treee6e7ff6228fc7a20db9be151e8fa80c37e27e612
parent3f5ea43fb8c33694a4ef9343de7c069e45a4f224 (diff)
downloadansible-close-module-path.tar.gz
Close module file once we're done reading from itclose-module-path
-rw-r--r--lib/ansible/executor/module_common.py74
1 files changed, 37 insertions, 37 deletions
diff --git a/lib/ansible/executor/module_common.py b/lib/ansible/executor/module_common.py
index c66cd2e3be..c7e0b1ef08 100644
--- a/lib/ansible/executor/module_common.py
+++ b/lib/ansible/executor/module_common.py
@@ -156,49 +156,49 @@ def modify_module(module_path, module_args, task_vars=dict(), strip_comments=Fal
# minifier output)
# * Only split into lines and recombine into strings once
# * Cache the modified module? If only the args are different and we do
- # that as the last step we could cache sll the work up to that point.
+ # that as the last step we could cache all the work up to that point.
with open(module_path) as f:
# read in the module source
module_data = f.read()
- (module_data, module_style) = _find_snippet_imports(module_data, module_path, strip_comments)
-
- 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, 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
- if 'ansible_syslog_facility' in task_vars:
- facility = task_vars['ansible_syslog_facility']
- module_data = module_data.replace('syslog.LOG_USER', "syslog.%s" % facility)
-
- lines = module_data.split(b"\n", 1)
- shebang = None
- if lines[0].startswith(b"#!"):
- shebang = lines[0].strip()
- args = shlex.split(str(shebang[2:]))
- interpreter = args[0]
- interpreter_config = 'ansible_%s_interpreter' % os.path.basename(interpreter)
-
- if interpreter_config in task_vars:
- interpreter = to_bytes(task_vars[interpreter_config], errors='strict')
- lines[0] = shebang = b"#!{0} {1}".format(interpreter, b" ".join(args[1:]))
-
- if os.path.basename(interpreter).startswith('python'):
- lines.insert(1, ENCODING_STRING)
- else:
- # No shebang, assume a binary module?
- pass
+ (module_data, module_style) = _find_snippet_imports(module_data, module_path, strip_comments)
+
+ 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, 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
+ if 'ansible_syslog_facility' in task_vars:
+ facility = task_vars['ansible_syslog_facility']
+ module_data = module_data.replace('syslog.LOG_USER', "syslog.%s" % facility)
+
+ lines = module_data.split(b"\n", 1)
+ shebang = None
+ if lines[0].startswith(b"#!"):
+ shebang = lines[0].strip()
+ args = shlex.split(str(shebang[2:]))
+ interpreter = args[0]
+ interpreter_config = 'ansible_%s_interpreter' % os.path.basename(interpreter)
+
+ if interpreter_config in task_vars:
+ interpreter = to_bytes(task_vars[interpreter_config], errors='strict')
+ lines[0] = shebang = b"#!{0} {1}".format(interpreter, b" ".join(args[1:]))
+
+ if os.path.basename(interpreter).startswith('python'):
+ lines.insert(1, ENCODING_STRING)
+ else:
+ # No shebang, assume a binary module?
+ pass
- module_data = b"\n".join(lines)
+ module_data = b"\n".join(lines)
- return (module_data, module_style, shebang)
+ return (module_data, module_style, shebang)