mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00:00
Added code to allow insertion of boilerplate into modules to make them able to share lots of code, the result
should be a huge reduction of total ansible source, at a slight cost of difficulty in original module development. We need to apply this now to all modules, but may need to have some exemptions to things like command, which should subclass this module.
This commit is contained in:
@@ -36,6 +36,7 @@ import ansible.constants as C
|
||||
import ansible.inventory
|
||||
from ansible import utils
|
||||
from ansible import errors
|
||||
from ansible import module_common
|
||||
import poller
|
||||
import connection
|
||||
from ansible import callbacks as ans_callbacks
|
||||
@@ -721,16 +722,20 @@ class Runner(object):
|
||||
|
||||
# use the correct python interpreter for the host
|
||||
host_variables = self.inventory.get_variables(conn.host)
|
||||
|
||||
module_data = ""
|
||||
with open(in_path) as f:
|
||||
module_data = f.read()
|
||||
module_data = module_data.replace(module_common.REPLACER, module_common.MODULE_COMMON)
|
||||
|
||||
if 'ansible_python_interpreter' in host_variables:
|
||||
interpreter = host_variables['ansible_python_interpreter']
|
||||
with open(in_path) as f:
|
||||
module_lines = f.readlines()
|
||||
module_lines = module_data.split('\n')
|
||||
if '#!' and 'python' in module_lines[0]:
|
||||
module_lines[0] = "#!%s" % interpreter
|
||||
self._transfer_str(conn, tmp, module, '\n'.join(module_lines))
|
||||
else:
|
||||
conn.put_file(in_path, out_path)
|
||||
module_data = "\n".join(module_lines)
|
||||
|
||||
self._transfer_str(conn, tmp, module, module_data)
|
||||
return out_path
|
||||
|
||||
# *****************************************************
|
||||
|
||||
Reference in New Issue
Block a user