-
Notifications
You must be signed in to change notification settings - Fork 700
Description
Summary
When specifying cmd
and argv
in an ansible.builtin.command
, the inline-env-var rule will trigger, causing a confusing error (while still "detecting" a problematic task).
Issue Type
- Bug Report
OS / ENVIRONMENT
I tested this on the main branch, c89815b, installing everything in a fresh virtual environment in python 3.13.3 via pip install -e '.[test]'
.
$ ansible-lint --version
ansible-lint 25.1.3 using ansible-core:2.18.3 ansible-compat:25.1.4 ruamel-yaml:0.18.10 ruamel-yaml-clib:0.2.12
- ansible installation method: one of source, pip, OS package
- ansible-lint installation method: one of source, pip, OS package
STEPS TO REPRODUCE
The following task specification is wrong (cmd and argv are mutually exclusive, see also https://docs.ansible.com/ansible/latest/collections/ansible/builtin/command_module.html#parameter-argv):
- name: Command with cmd and argv
ansible.builtin.command:
cmd: my_command
argv:
- argument
It does not contain any =, environment variables, or anything – still, ansible-lint reports inline-env-var
. (You can add this to the SUCCESS_PLAY_TASKS
in test/rules/test_inline_env_var.py to test it:
> assert len(results) == 0
E assert 1 == 0
E + where 1 = len([[inline-env-var] (Command module does not accept setting environment variables inline.) matched /private/var/folders/sd/ng9xryz96pqct9xwg4dc34q80000gn/T/playbookx0toxpdp.yml:57 Task/Handler: Command with cmd and argv])
Desired Behavior
Maybe a report of "cmd and argv cannot be specified together"/"are mutually exclusive", but not an inline-env-var false-positive.
Actual Behavior
See above, the task spec can be added to test/rules/test_inline_env_var.py to trigger the behavior.
output of ansible-lint for such a task is:
inline-env-var: Command module does not accept setting environment variables inline.
roles/my_role/tasks/main.yml:1 Task/Handler: Command with cmd and argv
Read documentation for instructions on how to ignore specific rule violations.
# Rule Violation Summary
1 inline-env-var profile:basic tags:command-shell,idiom
Failed: 1 failure(s), 0 warning(s) on 1 files. Last profile that met the validation criteria was 'min'.
If you like, I can also offer a fix for this, but I wasn't sure how to resolve this.
I noticed that "expected_args" in src/ansiblelint/rules/inline_env_var.py does not include argv
, and adding that resolves this false-positive.
However, there are two things I was not sure about; first, there are already examples containing argv for which the rule does not trigger in the tests:
- name: Use argv to send the command as a list
command:
argv:
- /bin/echo
- Hello
- World
- name: Another use of argv
command:
args:
argv:
- echo
- testing
And second, maybe there should be a rule to warn about cmd + argv in a command task?
Metadata
Metadata
Assignees
Labels
Type
Projects
Status