How do I use drift detection with a custom plan mode on an Ansible stack?
Last updated: October 29, 2026
Spacelift's drift detection for Ansible works by running ansible-playbook in check mode (--check) during the plan phase. A custom plan mode bypasses this entirely, and there is currently no way to submit an external state file or diff to Spacelift's drift detection engine — there's no ingestion point for external input of this kind.
Workaround: before_plan hook
You can approximate drift detection behavior by running your own diff logic in a before_plan hook:
Implement your diff logic (e.g. collecting actual config and comparing it against desired state) as a script that can run inside the Spacelift run environment.
Add the script as a
before_planhook on your stack. Hooks can be configured through the web interface, via thespacelift_stackTerraform resource, or in.spacelift/config.yml.Have the script exit non-zero when drift is detected. Spacelift will surface this as a failed proposed run.
Set up alerting on failed proposed runs so your team is notified when drift occurs.
This gives you a visible signal in Spacelift when drift happens, similar to native drift detection.
Richer output for standard check mode
If you're not using a fully custom plan mode, Spacelift already runs Ansible in check mode during the plan phase. You can enrich that output by setting an environment variable on the stack:
SPACELIFT_ANSIBLE_CLI_ARGS_plan="--diff"This only applies to Spacelift's built-in check mode, not to a fully custom plan mode.
Feature request
If native support for custom state or diff ingestion matters to your workflow, submit a request at feedback.spacelift.io.