`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.
More on Modules, Idempotency and Handlers
`ERROR! The requested handler 'Restart nginx' was not found in either the main handlers list nor in the listening handlers list`BeginnerA handler named `restart {{ app_service }}` is never found when notified as `restart myapp`AdvancedA `command` task reports `changed` on every run, and the Molecule idempotence check failsBeginner`lineinfile` appends the same line again on every runIntermediate`lineinfile` with `backrefs: true` reports `ok` but the line was never addedIntermediateA `template` task reports `changed` and restarts the service on every runIntermediate