Shells that use pipes should set the pipefail option
37 local_action: ansible.builtin.command /usr/bin/take_out_of_pool {{ inventory_hostname }}
38
39 - name: shell with jinja filter
40 shell: echo {{ "hello"|upper }}41 changed_when: false
42
43
Shells that use pipes should set the pipefail option
23 revision: default
24
25 - name: fetch metadata as json
26 shell: cargo metadata | jq27 ignore_errors: false
28
29 - name: enable redshift service
Description
Without the pipefail option set, a shell command that implements a pipeline can fail and still return 0.
If any part of the pipeline other than the terminal command fails, the whole pipeline will still return 0, which may be considered a success by Ansible. Pipefail is available in the bash shell.
Bad practice
- name: Example task
shell: ls -ld /tmp | tr -d tmp
args:
executable: /usr/bin/bash
Recommended
It is recommended to use pipefail
with shell
commands that use pipes.
- name: Example task
shell: set -o pipefail && ls -ld /tmp | tr -d tmp
args:
executable: /usr/bin/bash