mirror of
https://github.com/thegeeklab/ansible-later.git
synced 2024-11-25 06:10:42 +00:00
feat: add config option to exclude modules from native yaml check (#236)
This commit is contained in:
parent
b0271ef29b
commit
440aaea5b1
@ -11,12 +11,12 @@ class CheckNamedTask(StandardBase):
|
|||||||
|
|
||||||
def check(self, candidate, settings):
|
def check(self, candidate, settings):
|
||||||
tasks, errors = self.get_normalized_tasks(candidate, settings)
|
tasks, errors = self.get_normalized_tasks(candidate, settings)
|
||||||
nameless_tasks = settings["ansible"]["named-task"]["exclude"]
|
exclude_modules = settings["ansible"]["named-task"]["exclude"]
|
||||||
|
|
||||||
if not errors:
|
if not errors:
|
||||||
for task in tasks:
|
for task in tasks:
|
||||||
module = task["action"]["__ansible_module__"]
|
module = task["action"]["__ansible_module__"]
|
||||||
if ("name" not in task or not task["name"]) and module not in nameless_tasks:
|
if ("name" not in task or not task["name"]) and module not in exclude_modules:
|
||||||
errors.append(
|
errors.append(
|
||||||
self.Error(task["__line__"], self.helptext.format(module=module))
|
self.Error(task["__line__"], self.helptext.format(module=module))
|
||||||
)
|
)
|
||||||
|
@ -11,26 +11,31 @@ class CheckNativeYaml(StandardBase):
|
|||||||
|
|
||||||
def check(self, candidate, settings):
|
def check(self, candidate, settings):
|
||||||
tasks, errors = self.get_action_tasks(candidate, settings)
|
tasks, errors = self.get_action_tasks(candidate, settings)
|
||||||
|
exclude_modules = settings["ansible"]["native-yaml"]["exclude"]
|
||||||
|
|
||||||
if not errors:
|
if not errors:
|
||||||
for task in tasks:
|
for task in tasks:
|
||||||
normal_form, error = self.get_normalized_task(task, candidate, settings)
|
normal_form, error = self.get_normalized_task(task, candidate, settings)
|
||||||
|
|
||||||
if error:
|
if error:
|
||||||
errors.extend(error)
|
errors.extend(error)
|
||||||
break
|
break
|
||||||
|
|
||||||
action = normal_form["action"]["__ansible_module__"]
|
module = normal_form["action"]["__ansible_module__"]
|
||||||
arguments = [
|
arguments = [
|
||||||
bytes(x, "utf-8").decode("utf8", "ignore")
|
bytes(x, "utf-8").decode("utf8", "ignore")
|
||||||
for x in normal_form["action"]["__ansible_arguments__"]
|
for x in normal_form["action"]["__ansible_arguments__"]
|
||||||
]
|
]
|
||||||
# Cope with `set_fact` where task["set_fact"] is None
|
|
||||||
if not task.get(action):
|
if module in exclude_modules:
|
||||||
continue
|
continue
|
||||||
if isinstance(task[action], dict):
|
# Cope with `set_fact` where task["set_fact"] is None
|
||||||
|
if not task.get(module):
|
||||||
|
continue
|
||||||
|
if isinstance(task[module], dict):
|
||||||
continue
|
continue
|
||||||
# strip additional newlines off task[action]
|
# strip additional newlines off task[action]
|
||||||
task_action = bytes(task[action].strip(), "utf-8").decode("utf8", "ignore")
|
task_action = bytes(task[module].strip(), "utf-8").decode("utf8", "ignore")
|
||||||
if list(filter(lambda a: a != "\\", task_action.split())) != arguments:
|
if list(filter(lambda a: a != "\\", task_action.split())) != arguments:
|
||||||
errors.append(self.Error(task["__line__"], self.helptext))
|
errors.append(self.Error(task["__line__"], self.helptext))
|
||||||
return self.Result(candidate.path, errors)
|
return self.Result(candidate.path, errors)
|
||||||
|
@ -148,6 +148,9 @@ class Settings(object):
|
|||||||
"include_vars",
|
"include_vars",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
"native-yaml": {
|
||||||
|
"exclude": [],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"yamllint": {
|
"yamllint": {
|
||||||
"empty-lines": {
|
"empty-lines": {
|
||||||
|
@ -28,9 +28,9 @@ ansible:
|
|||||||
- "yes"
|
- "yes"
|
||||||
- "no"
|
- "no"
|
||||||
|
|
||||||
# List of tasks that don't need to be named (ANSIBLE0006).
|
# List of modules that don't need to be named (ANSIBLE0006).
|
||||||
# You have to specify every single task type, globs or wildcard will not work!
|
# You must specify each individual module name, globs or wildcards do not work!
|
||||||
named-task
|
named-task:
|
||||||
exclude:
|
exclude:
|
||||||
- "meta"
|
- "meta"
|
||||||
- "debug"
|
- "debug"
|
||||||
@ -41,6 +41,11 @@ ansible:
|
|||||||
- "import_role"
|
- "import_role"
|
||||||
- "import_tasks"
|
- "import_tasks"
|
||||||
|
|
||||||
|
# List of modules that are allowed to use the key=value format instead of the native YAML format (LINT0008).
|
||||||
|
# You must specify each individual module name, globs or wildcards do not work!
|
||||||
|
native-yaml:
|
||||||
|
exclude: []
|
||||||
|
|
||||||
# Global logging configuration
|
# Global logging configuration
|
||||||
# If you would like to force colored output (e.g. non-tty)
|
# If you would like to force colored output (e.g. non-tty)
|
||||||
# set environment variable `PY_COLORS=1`
|
# set environment variable `PY_COLORS=1`
|
||||||
|
@ -13,7 +13,7 @@ Reviews are useless without some rules or standards to check against. ansible-la
|
|||||||
| CheckYamlColons | LINT0005 | YAML should use consistent number of spaces around colons. | {colons: {max-spaces-before: 0, max-spaces-after: 1}} |
|
| CheckYamlColons | LINT0005 | YAML should use consistent number of spaces around colons. | {colons: {max-spaces-before: 0, max-spaces-after: 1}} |
|
||||||
| CheckYamlFile | LINT0006 | Roles file should be in YAML format. | |
|
| CheckYamlFile | LINT0006 | Roles file should be in YAML format. | |
|
||||||
| CheckYamlHasContent | LINT0007 | Files should contain useful content. | |
|
| CheckYamlHasContent | LINT0007 | Files should contain useful content. | |
|
||||||
| CheckNativeYaml | LINT0008 | Use YAML format for tasks and handlers rather than key=value. | |
|
| CheckNativeYaml | LINT0008 | Use YAML format for tasks and handlers rather than key=value. | {native-yaml: {exclude: []}} |
|
||||||
| CheckYamlDocumentEnd | LINT0009 | YAML should contain document end marker. | {document-end: {present: true}} |
|
| CheckYamlDocumentEnd | LINT0009 | YAML should contain document end marker. | {document-end: {present: true}} |
|
||||||
| CheckLineBetweenTasks | ANSIBLE0001 | Single tasks should be separated by an empty line. | |
|
| CheckLineBetweenTasks | ANSIBLE0001 | Single tasks should be separated by an empty line. | |
|
||||||
| CheckMetaMain | ANSIBLE0002 | Meta file should contain a basic subset of parameters. | author, description, min_ansible_version, platforms, dependencies |
|
| CheckMetaMain | ANSIBLE0002 | Meta file should contain a basic subset of parameters. | author, description, min_ansible_version, platforms, dependencies |
|
||||||
|
Loading…
Reference in New Issue
Block a user