Merge pull request #36 from xoxys/fix-meta

fix issue with conflicting action statements
This commit is contained in:
Robert Kaussow 2020-09-26 14:50:29 +02:00 committed by GitHub
commit 9926c53289
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 4 deletions

View File

@ -1,2 +1,3 @@
- BUGFIX
- fix issue if `tags` is not defined for a task object
- fix metadata handling to prevent parsing issues
on Ansible upstream functions (#35)

View File

@ -396,16 +396,26 @@ def _kv_to_dict(v):
def normalize_task(task, filename, custom_modules=[]):
"""Ensure tasks have an action key and strings are converted to python objects."""
ansible_action_type = task.get("__ansible_action_type__", "task")
ansible_action_meta = task.get("__ansible_action_meta__", dict())
if "__ansible_action_type__" in task:
del (task["__ansible_action_type__"])
# temp. extract metadata
ansible_meta = dict()
for key in ["__line__", "__file__", "__ansible_action_meta__"]:
default = None
if key == "__ansible_action_meta__":
default = dict()
ansible_meta[key] = task.pop(key, default)
normalized = dict()
# TODO: Workaround for custom modules
builtin = list(ansible.parsing.mod_args.BUILTIN_TASKS)
builtin = list(set(builtin + custom_modules))
ansible.parsing.mod_args.BUILTIN_TASKS = frozenset(builtin)
mod_arg_parser = ModuleArgsParser(task)
try:
action, arguments, normalized["delegate_to"] = mod_arg_parser.parse()
except AnsibleParserError as e:
@ -435,7 +445,12 @@ def normalize_task(task, filename, custom_modules=[]):
normalized[FILENAME_KEY] = filename
normalized["__ansible_action_type__"] = ansible_action_type
normalized["__ansible_action_meta__"] = ansible_action_meta
# add back extracted metadata
for (k, v) in ansible_meta.items():
if v:
normalized[k] = v
return normalized