Skip to main content

Terraform and Ansible Handoff Pattern

Terraform provisions infrastructure; Ansible configures it. This guide explains how to pass Terraform output directly into Ansible as an inventory — the handoff pattern used across all NetActuate Terraform repos.

Why Separate Them

Terraform excels at creating and tracking cloud resources. Ansible excels at configuring what is running on them. Combining them in one tool creates complexity without benefit. The handoff is the clean boundary between the two.

Step 1: Provision with Terraform

git clone https://github.com/netactuate/netactuate-ansible-terraform-compute
cd netactuate-terraform-compute
cp terraform.tfvars.example terraform.tfvars
# edit terraform.tfvars
terraform init
terraform apply

Step 2: Export the Ansible Inventory

Every NetActuate Terraform repo outputs a ready-to-use Ansible inventory block:

terraform output -raw ansible_inventory

Example output:

[nodes]
worker-LAX.example.com ansible_host=192.0.2.10 ansible_user=root
worker-AMS.example.com ansible_host=192.0.2.11 ansible_user=root

Write it to a file:

terraform output -raw ansible_inventory > inventory.ini

Step 3: Run Ansible Against It

git clone https://github.com/netactuate/netactuate-ansible-bgp-bird2
cd netactuate-ansible-bgp-bird2
# edit group_vars/all with BGP variables
ansible-playbook bgp.yaml -i ../netactuate-terraform-compute/inventory.ini

Full Example

Complete sequence from zero to BGP anycast cluster:

# 1. Provision with Terraform
git clone https://github.com/netactuate/netactuate-terraform-bgp
cd netactuate-terraform-bgp
cp terraform.tfvars.example terraform.tfvars
# (edit terraform.tfvars)
terraform init && terraform apply
terraform output -raw ansible_inventory > inventory.ini

# 2. Configure BGP with Ansible
cd ..
git clone https://github.com/netactuate/netactuate-ansible-bgp-bird2
cd netactuate-ansible-bgp-bird2
# (edit group_vars/all with BGP variables)
ansible-playbook bgp.yaml -i ../netactuate-terraform-bgp/inventory.ini

# 3. Validate
ssh root@FIRST_NODE_IP "birdc show protocols"

Need Help?

If you need assistance, visit our support page.