Skip to content

Commit

Permalink
Fix missing required arguments issue from args rule (#3402)
Browse files Browse the repository at this point in the history
  • Loading branch information
audgirka authored May 7, 2023
1 parent 6921d99 commit fb4298f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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

0 comments on commit fb4298f

Please sign in to comment.