Skip to content

Confusing output the first time a shell or command task has a non-zero return code ignored by failed_when #85505

@flowerysong

Description

@flowerysong

Ansible Version

ansible [core 2.19.0rc2.post0] (detached HEAD 66eb3e7589) last updated 2025/07/17 16:25:24 (GMT -400)
  config file = None
  configured module search path = ['/home/ezekielh/ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/ezekielh/ansible/lib/ansible
  ansible collection location = /home/ezekielh/ansible/collections:/usr/share/ansible/collections
  executable location = /home/ezekielh/ansible/bin/ansible
  python version = 3.11.2 (main, Nov 29 2023, 19:37:19) [GCC 11.3.1 20221121 (Red Hat 11.3.1-4)] (/home/ezekielh/.pyenv/versions/3.11.2/bin/python)
  jinja version = 3.1.2
  pyyaml version = 6.0.1 (with libyaml v0.2.5)

Summary

- hosts: localhost
  gather_facts: false
  tasks:
    - shell: exit {{ item }}
      loop: "{{ range(0, 5) | list }}"
      failed_when: false

Outputs:

TASK [shell] *******************************************************************
changed: [localhost] => (item=0)
[ERROR]: non-zero return code
changed: [localhost] => (item=1)
changed: [localhost] => (item=2)
changed: [localhost] => (item=3)
changed: [localhost] => (item=4)

I've experimented with various permutations of tasks and task placement and this extraneous error output appears to occur only once per playbook run, even if there are multiple hosts or plays involved.

Metadata

Metadata

Labels

affects_2.19bugThis issue/PR relates to a bug.pre_releaseThis issue relates to a pre-release version.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions