Templating overhaul, implement Data Tagging (#84621)

Co-authored-by: Matt Davis <mrd@redhat.com>
Co-authored-by: Matt Clay <matt@mystile.com>
This commit is contained in:
Matt Davis
2025-04-14 08:54:36 -07:00
committed by GitHub
co-authored by Matt Davis Matt Clay
parent 6fc592df9b
commit 35750ed321
793 changed files with 29627 additions and 12505 deletions
+33 -6
View File
@@ -40,10 +40,10 @@ import shutil
from pathlib import Path
from ansible.module_utils.common.messages import PluginInfo
from ansible.release import __version__
import ansible.utils.vars as utils_vars
from ansible.parsing.dataloader import DataLoader
from ansible.parsing.utils.jsonify import jsonify
from ansible.parsing.splitter import parse_kv
from ansible.plugins.loader import init_plugin_loader
from ansible.executor import module_common
@@ -89,6 +89,22 @@ def parse():
return options, args
def jsonify(result, format=False):
""" format JSON output (uncompressed or uncompressed) """
if result is None:
return "{}"
indent = None
if format:
indent = 4
try:
return json.dumps(result, sort_keys=True, indent=indent, ensure_ascii=False)
except UnicodeDecodeError:
return json.dumps(result, sort_keys=True, indent=indent)
def write_argsfile(argstring, json=False):
""" Write args to a file for old-style module's use. """
argspath = Path("~/.ansible_test_module_arguments").expanduser()
@@ -152,16 +168,27 @@ def boilerplate_module(modfile, args, interpreters, check, destfile):
if check:
complex_args['_ansible_check_mode'] = True
modfile = os.path.abspath(modfile)
modname = os.path.basename(modfile)
modname = os.path.splitext(modname)[0]
(module_data, module_style, shebang) = module_common.modify_module(
modname,
modfile,
complex_args,
Templar(loader=loader),
plugin = PluginInfo(
requested_name=modname,
resolved_name=modname,
type='module',
)
built_module = module_common.modify_module(
module_name=modname,
plugin=plugin,
module_path=modfile,
module_args=complex_args,
templar=Templar(loader=loader),
task_vars=task_vars
)
module_data, module_style = built_module.b_module_data, built_module.module_style
if module_style == 'new' and '_ANSIBALLZ_WRAPPER = True' in to_native(module_data):
module_style = 'ansiballz'