mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 21:32:49 +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:
@@ -31,6 +31,7 @@ import os
|
||||
import subprocess
|
||||
import traceback
|
||||
from ansible import utils
|
||||
from ansible import module_common
|
||||
|
||||
try:
|
||||
import json
|
||||
@@ -54,6 +55,23 @@ argsfile = open(argspath, 'w')
|
||||
argsfile.write(args)
|
||||
argsfile.close()
|
||||
|
||||
module_fh = open(modfile)
|
||||
module_data = module_fh.read()
|
||||
included_boilerplate = module_data.find(module_common.REPLACER) != -1
|
||||
module_fh.close()
|
||||
|
||||
if included_boilerplate:
|
||||
module_data = module_data.replace(module_common.REPLACER, module_common.MODULE_COMMON)
|
||||
modfile2_path = os.path.expanduser("~/.ansible_module_generated")
|
||||
print "* including generated source, if any, saving to: %s" % modfile2_path
|
||||
print "* this will offset any line numbers in tracebacks!"
|
||||
modfile2 = open(modfile2_path, 'w')
|
||||
modfile2.write(module_data)
|
||||
modfile2.close()
|
||||
modfile = modfile2_path
|
||||
else:
|
||||
print "* module boilerplate substitution not requested in module, tracebacks will be unaltered"
|
||||
|
||||
os.system("chmod +x %s" % modfile)
|
||||
cmd = subprocess.Popen("%s %s" % (modfile, argspath),
|
||||
shell=True,
|
||||
|
||||
Reference in New Issue
Block a user