ansible-later/ansiblelater/rules/CheckNativeYaml.py
Robert Kaussow 43d7edca32
refactor plugin system to use a class-based approach (#68)
* refactor plugin system to use a class-based approach

* disable some docstring linter errors and fix imports

* cleanup

* fix docs

* add metavars to cli arguments for better helptext

* add option to disable buildin rules

* remove print

* remove dead code
2021-01-30 16:52:48 +01:00

37 lines
1.5 KiB
Python

from ansiblelater.standard import StandardBase
class CheckNativeYaml(StandardBase):
sid = "LINT0008"
description = "Use YAML format for tasks and handlers rather than key=value"
helptext = "task arguments appear to be in key value rather than YAML format"
version = "0.1"
types = ["playbook", "task", "handler"]
def check(self, candidate, settings):
tasks, errors = self.get_action_tasks(candidate, settings)
if not errors:
for task in tasks:
normal_form, error = self.get_normalized_task(task, candidate, settings)
if error:
errors.extend(error)
break
action = normal_form["action"]["__ansible_module__"]
arguments = [
bytes(x, "utf-8").decode("unicode_escape")
for x in normal_form["action"]["__ansible_arguments__"]
]
# Cope with `set_fact` where task["set_fact"] is None
if not task.get(action):
continue
if isinstance(task[action], dict):
continue
# strip additional newlines off task[action]
task_action = bytes(task[action].strip(), "utf-8").decode("unicode_escape")
if task_action.split() != arguments:
errors.append(self.Error(task["__line__"], self.helptext))
return self.Result(candidate.path, errors)