Interview Prep/Ansible/Modules, Idempotency and Handlers

`curl ... | tar xz` fails on the host but the `shell` task reports success

IntermediateTroubleshootingModules, Idempotency and Handlers
Answer

Likely causes → Without pipefail, a pipeline returns the exit code of its last command. curl can fail (404, DNS) while tar exits 0 on empty input, or the other way round.

Fix →

- ansible.builtin.shell: |
    set -o pipefail
    curl -fsSL https://example.com/app.tgz | tar xz -C /opt/app
  args:
    executable: /bin/bash
    creates: /opt/app/bin/app

/bin/sh on Debian is dash, which only supports pipefail in recent versions, so set executable: /bin/bash. Even better, split the work into get_url and unarchive.

Prevent → ansible-lint rule risky-shell-pipe flags pipelines without pipefail. Use curl -f so HTTP errors give a non-zero exit code.

All Ansible questions Roadmap: Ansible

More on Modules, Idempotency and Handlers