diff --git a/CHANGELOG.md b/CHANGELOG.md index 9dee29f..06652f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +- DEPRECATE + - the tag 'skip_ansible_lint' to skip tasks is deprecated + use 'skip_ansible_later' instead +- ENHANCEMENT + - add a non-enforcement rule for deprecated features + if you use a custom standards file you may have to enable `check_deprecate` - BUGFIX - ANSIBLE0010 - allow `shell` module if `args.executable` is used as this parameter is no longer support by command module diff --git a/ansiblelater/data/standards.py b/ansiblelater/data/standards.py index 6f77703..0839be3 100644 --- a/ansiblelater/data/standards.py +++ b/ansiblelater/data/standards.py @@ -1,5 +1,6 @@ """Example standards definition.""" +from ansiblelater.rules.deprecated import check_deprecated from ansiblelater.rules.ansiblefiles import check_become_user from ansiblelater.rules.ansiblefiles import check_braces_spaces from ansiblelater.rules.ansiblefiles import check_command_has_changes @@ -27,6 +28,15 @@ from ansiblelater.rules.yamlfiles import check_yaml_hyphens from ansiblelater.rules.yamlfiles import check_yaml_indent from ansiblelater.standard import Standard +deprecated_features = Standard( + dict( + id="ANSIBLE9999", + name="Deprecated features should not be used", + check=check_deprecated, + types=["playbook", "task", "handler"] + ) +) + tasks_should_be_separated = Standard( dict( id="ANSIBLE0001", @@ -296,6 +306,7 @@ standards = [ literal_bool_should_be_formatted, use_become_with_become_user, use_spaces_around_filters, + deprecated_features, # Lint files_should_not_contain_unnecessarily_empty_lines, files_should_be_indented, diff --git a/ansiblelater/rules/deprecated.py b/ansiblelater/rules/deprecated.py new file mode 100644 index 0000000..6d87b75 --- /dev/null +++ b/ansiblelater/rules/deprecated.py @@ -0,0 +1,21 @@ +"""Checks related to ansible specific best practices.""" + +from ansiblelater.command.candidates import Error +from ansiblelater.command.candidates import Result +from ansiblelater.utils.rulehelper import get_normalized_tasks + + +def check_deprecated(candidate, settings): + tasks, errors = get_normalized_tasks(candidate, settings, full=True) + description = "'{old}' is deprecated and should not be used anymore. Use '{new}' instead." + + if not errors: + for task in tasks: + if "skip_ansible_lint" in task.get("tags"): + errors.append( + Error( + task["__line__"], + description.format(old="skip_ansible_lint", new="skip_ansible_later") + ) + ) + return Result(candidate.path, errors) diff --git a/ansiblelater/utils/rulehelper.py b/ansiblelater/utils/rulehelper.py index 64c4146..6ac1586 100644 --- a/ansiblelater/utils/rulehelper.py +++ b/ansiblelater/utils/rulehelper.py @@ -64,7 +64,7 @@ def get_normalized_task(task, candidate, settings): return normalized, errors -def get_normalized_tasks(candidate, settings): +def get_normalized_tasks(candidate, settings, full=False): normalized = [] errors = [] try: @@ -77,9 +77,16 @@ def get_normalized_tasks(candidate, settings): # An empty `tags` block causes `None` to be returned if # the `or []` is not present - `task.get("tags", [])` # does not suffice. - if "skip_ansible_lint" in (task.get("tags") or []): + + # Deprecated. + if "skip_ansible_lint" in (task.get("tags") or []) and not full: # No need to normalize_task if we are skipping it. continue + + if "skip_ansible_later" in (task.get("tags") or []) and not full: + # No need to normalize_task if we are skipping it. + continue + normalized.append( normalize_task(task, candidate.path, settings["ansible"]["custom_modules"]) )