Ansible in a Minute · Ansible Core ·
Use shell or true to accept a non-zero exit
Short answer
Append || /bin/true to a shell command when a non-zero exit code should still count as success.
Subscribe for updates
Get an email whenever we publish new guides and blog posts. Unsubscribe anytime.
By subscribing you agree we may email you about Ansible in a Minute and related Level Up Labs updates. We store your address in the same lead sheet as our contact form.
Request
run a shell command that may exit non-zero and still succeed
Example
A quick heads-up: Every environment is different. Review and test this example before you run it on systems you care about.
---
- name: Accept a non-zero exit from a shell command
hosts: all
gather_facts: false
tasks:
- name: Run this command and ignore the result
ansible.builtin.shell: /usr/bin/somecommand || /bin/trueHow it works
command and shell treat a non-zero return code as failure. Appending || /bin/true makes the shell statement succeed even when somecommand exits non-zero.
When to use it
- Commands that return non-zero on soft conditions you can ignore
- Quick success masking when failed_when is not required
Requirements
- Ansible: >=2.14
Validation
- Syntax validated
- Not execution-tested
- Last verified 2026-09-16
Notes
Prefer failed_when when you must decide failure from stdout or stderr. || /bin/true hides all non-zero exits from the shell statement. Pair with changed_when when the command should not report changed.
Reference
- Ensuring success for command and shell (Ansible docs)
Built for every Ansible use case in every organization
BacklogZero can generate this kind of automation in your environment, just like it did here.