Why does ansible-playbook receive a -i inventory flag on tracked/proposed runs but not on tasks?
Last updated: October 29, 2026
Context
When running Ansible-based stacks in Spacelift, you may notice that ansible-playbook is automatically passed a -i /mnt/workspace/source/inventory flag during tracked and proposed runs, but this flag is not included when running Tasks. This can cause Tasks to fail if they rely on an inventory directory being present, while tracked and proposed runs continue to work as expected.
Answer
The difference in behavior is due to how each run type invokes ansible-playbook:
Tracked and proposed runs use ansible-runner under the hood. When ansible-runner detects an
inventorydirectory at the root of your project workspace, it automatically appends-i $(pwd)/inventoryto theansible-playbookcommand.Tasks call
ansible-playbookdirectly, bypassing ansible-runner entirely. As a result, the automatic inventory detection does not occur, and the-iflag is not added.
To ensure consistent inventory resolution across all run types, you can use one of the following approaches:
Pass
-i inventoryexplicitly in your task commands:
For example:ansible-playbook -i inventory -v your-playbook.yamlSet the
ANSIBLE_INVENTORYenvironment variable on your stack or context (e.g.,ANSIBLE_INVENTORY=inventory). Ansible will pick this up automatically without requiring changes to individual task commands. This is the recommended approach if you run many tasks.
If you use the ANSIBLE_INVENTORY environment variable, make sure the path and filename are correct (e.g., inventory/inventory.yml), as a typo in the path can cause tasks to silently fall back to other inventory resolution methods.