BacklogZero®

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.

YAML
---
- 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/true

How 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

Built for every Ansible use case in every organization

BacklogZero can generate this kind of automation in your environment, just like it did here.

Get BacklogZero today

Related guides

Back to Ansible in a Minute

Use shell or true to accept a non-zero exit · Level Up Labs