Skip to content

Commit

Permalink
Do not emit fqcn[action-core] when ansible.legacy is used for builtin…
Browse files Browse the repository at this point in the history
… modules (#2634)

Co-authored-by: Sorin Sbarnea <ssbarnea@redhat.com>
  • Loading branch information
felixfontein and ssbarnea committed Oct 30, 2022
1 parent e064262 commit 3383579
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/ansiblelint/rules/fqcn.py
Expand Up @@ -117,17 +117,21 @@ def matchtask(
self.module_aliases[target] = target

if module != self.module_aliases[module]:
module_alias = self.module_aliases.get(module, "")
module_alias = self.module_aliases[module]
if module_alias.startswith("ansible.builtin"):
result.append(
self.create_matcherror(
message=f"Use FQCN for builtin module actions ({module}).",
details=f"Use `ansible.builtin.{module}` or `ansible.legacy.{module}` instead.",
filename=file,
linenumber=task["__line__"],
tag="fqcn[action-core]",
)
legacy_module = module_alias.replace(
"ansible.builtin.", "ansible.legacy.", 1
)
if module != legacy_module:
result.append(
self.create_matcherror(
message=f"Use FQCN for builtin module actions ({module}).",
details=f"Use `{module_alias}` or `{legacy_module}` instead.",
filename=file,
linenumber=task["__line__"],
tag="fqcn[action-core]",
)
)
else:
if module.count(".") < 2:
result.append(
Expand Down Expand Up @@ -172,6 +176,8 @@ def matchtask(
community.general.system.sudoers:
name: should-not-be-here
state: absent
- name: Command with legacy FQCN
ansible.legacy.command: echo This rule should not get matched by the fqcn rule
"""

FAIL_PLAY = """
Expand Down

0 comments on commit 3383579

Please sign in to comment.