Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing required arguments issue from args rule #3402

Merged
merged 1 commit into from
May 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions examples/playbooks/rule-args-module-pass.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,10 @@
ansible.windows.win_file:
path: "c:\\test_dir"
state: directory

- name: Ansible-lint for args rule should succeed (Bug - 3199)
vars:
copy_vars:
src: "args.json"
action: ansible.builtin.copy
args: "{{ copy_vars }}" # since, we're unable to analyze jinja, we skip this kind of checks
12 changes: 11 additions & 1 deletion src/ansiblelint/rules/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def matchtask( # noqa: C901
task: Task,
file: Lintable | None = None,
) -> list[MatchError]:
# pylint: disable=too-many-branches,too-many-locals
# pylint: disable=too-many-branches,too-many-locals,too-many-return-statements
results: list[MatchError] = []
module_name = task["action"]["__ansible_module_original__"]
failed_msg = None
Expand All @@ -124,6 +124,16 @@ def matchtask( # noqa: C901
for key, value in task["action"].items()
if not key.startswith("__")
}

# Return if 'args' is jinja string
# https://github.com/ansible/ansible-lint/issues/3199
if (
"args" in task.raw_task
and isinstance(task.raw_task["args"], str)
and has_jinja(task.raw_task["args"])
):
return []

if loaded_module.resolved_fqcn in workarounds_inject_map:
module_args.update(workarounds_inject_map[loaded_module.resolved_fqcn])
if loaded_module.resolved_fqcn in workarounds_drop_map:
Expand Down