End-to-End DevOps Pipeline with Terraform + Ansible + CI

In the modern DevOps world, just deploying an application is not enough. The entire infrastructure, configuration, and deployment processes are expected to be fully automated.
In this article, we'll walk through a real-world scenario: we'll provision infrastructure with Terraform, configure and deploy with Ansible, and run everything with a single git push using a GitHub Actions CI pipeline.
Scenario
The fully automated flow we're targeting works like this:
- Developer pushes code to GitHub
- CI pipeline is triggered
- Terraform creates the server on AWS
- Ansible connects to the server, installs Docker, and brings up the application
- Application runs in production
Terraform defines the infrastructure; Ansible configures that infrastructure. The two tools complement each other perfectly: Terraform answers "what exists," while Ansible answers "how is it configured."
1. Infrastructure Provisioning with Terraform
We create an EC2 instance on AWS and expose its public IP. Ansible will use this IP to connect to the server.
The output block passes the IP address to the pipeline for Ansible to use in the next steps.
2. Configuration and Deployment with Ansible
After Terraform creates the server, Ansible takes over. It installs Docker and starts the application container.
The playbook is idempotent; running the same playbook multiple times does not change the result. This is critical for enabling safe re-deployments.
3. CI — GitHub Actions Pipeline
The GitHub Actions workflow that ties everything together. It is automatically triggered on every push to the main branch.
Conclusion
When these three tools come together, a true "push to deploy" experience emerges. The developer only writes code; provisioning the infrastructure, preparing the server, and deploying the application all happen automatically.
- Terraform → Infrastructure (what exists?)
- Ansible → Configuration (how is it set up?)
- GitHub Actions → Orchestration (when and in what order?)
This pattern forms the foundation of a battle-tested DevOps infrastructure that scales from small startups to large enterprise teams.