We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
In this task, if there was a pre-existing crontab it is considered a (non-fatal) failure mode:
- name: Get pre-existing crontab (if any) ansible.builtin.shell: "! crontab -l" changed_when: false register: missing_crontab ignore_errors: true # don't stop the rest of the playbook
We invert the return code (i.e. we want rc=0 when there is no existing crontab) using POSIX shell ! operator.
!
ansible-lint is unhappy and wants the task to use ansible.builtin.command instead of shell:
ansible.builtin.command
command-instead-of-shell: Use shell only when shell functionality is required.
The auto-fixer makes a suggestion which doesn't actually work:
- name: Get pre-existing crontab (if any) ansible.builtin.command: "! crontab -l" changed_when: false register: missing_crontab ignore_errors: true # don't stop the rest of the playbook
This "fixed" task fails, it appears to be trying to run a program called literally "!":
TASK [Get pre-existing crontab (if any)] *********************** fatal: [examplehost]: FAILED! => changed=false cmd: '''!'' crontab -l' msg: '[Errno 2] No such file or directory: b''!'': b''!''' rc: 2 stderr: '' stderr_lines: <omitted> stdout: '' stdout_lines: <omitted> ...ignoring
Workaround: use ansible.builtin.command: bash -c "! crontab -l"
ansible.builtin.command: bash -c "! crontab -l"
$ ansible-lint --version ansible-lint 24.9.2 using ansible-core:2.16.11 ansible-compat:24.9.1 ruamel-yaml:0.18.6 ruamel-yaml-clib:0.2.8
The text was updated successfully, but these errors were encountered:
@wimglenn Thanks for the bug, a PR would be welcome.
Sorry, something went wrong.
include ! as a shell word. closes ansible#4386
d59d09f
Added #4403. It failed because it doesn't have a label, but I don't seem to have permission to add labels.
2e5af42
No branches or pull requests
Summary
In this task, if there was a pre-existing crontab it is considered a (non-fatal) failure mode:
We invert the return code (i.e. we want rc=0 when there is no existing crontab) using POSIX shell
!
operator.ansible-lint is unhappy and wants the task to use
ansible.builtin.command
instead of shell:The auto-fixer makes a suggestion which doesn't actually work:
This "fixed" task fails, it appears to be trying to run a program called literally "!":
Workaround: use
ansible.builtin.command: bash -c "! crontab -l"
Issue Type
OS / ENVIRONMENT
The text was updated successfully, but these errors were encountered: