Using a single Ansible stack to handle multiple Tofu stacks

Last updated: December 19, 2025

If you're managing multiple EC2/Tofu stacks and want to avoid creating separate Ansible stacks for each one, you can use a dynamic inventory approach to have a single Ansible stack handle multiple Tofu stacks.

Dynamic Inventory Solution

Instead of maintaining separate Ansible stacks for each EC2/Tofu stack, dynamic inventory can automatically pull in the right hosts at runtime. This eliminates the limitation of requiring individual Ansible stacks for each Tofu stack.

Dynamic inventory works by querying your infrastructure at runtime to build the inventory of hosts that Ansible should manage, rather than maintaining static inventory files.

Implementation with Spacelift

Spacelift supports dynamic inventory setups that can connect OpenTofu-managed infrastructure with Ansible. You can use the tofusible plugin to bridge your OpenTofu stacks with your Ansible automation.

This approach allows you to:

  • Maintain a single Ansible stack that can work with multiple Tofu stacks

  • Automatically discover and manage hosts from different infrastructure stacks

  • Reduce the complexity of managing multiple stack dependencies

Additional Resources

For detailed implementation guidance, refer to these Spacelift blog posts:

These resources provide step-by-step instructions for setting up dynamic inventory in your Spacelift environment.