A fully automated, self-healing, multi-region deployment pipeline that provisions infrastructure and deploys a containerized web application using Jenkins, Terraform, Docker, Ansible, and AWS.
It ensures zero downtime, automatic failover, and global accessibility via AWS Global Accelerator.
Whenever code is pushed to the repository, Jenkins automatically:
- Builds and tests the app
- Builds and pushes a Docker image to DockerHub
- Provisions AWS infrastructure using Terraform
- Configures EC2 instances using Ansible
- Deploys the containerized web app
- Performs health checks and auto-heals failed containers
GitHub → Jenkins → Terraform → AWS → Ansible → Docker → AutoHeal
- Stores app code, Dockerfile, Terraform, and Ansible files.
- Pulls latest code
- Runs Python syntax tests
- Builds & pushes Docker image to DockerHub
- Triggers Terraform for infra creation
- Runs Ansible to configure and deploy containers
- Performs health checks and auto-healing
- Provisions multi-region AWS infrastructure:
- EC2 (Auto Scaling Groups)
- Application Load Balancers (ALB)
- Global Accelerator for single IP + failover
- VPCs, subnets, security groups, and key pairs
- Stores state remotely in S3 with DynamoDB locking
- Installs Docker on EC2
- Pulls app image from DockerHub
- Runs and maintains web containers
- Supports primary and secondary region groups
- The Flask app is containerized with a simple HTML frontend
- Image hosted on DockerHub:
anant2005ch/autoheal-cloud
- Multi-region, high-availability deployment
- Global Accelerator routes traffic to the nearest healthy region
- Auto Scaling + ALB handles load and replacement
AutoHeal-Cloud/
├── ansible/
│ ├── inventory.ini
│ ├── playbook.yml
│ └── roles/
│ └── deploy_app/
│ ├── tasks/main.yml
│ ├── templates/index.html
│ └── vars/main.yml
├── app/
│ ├── app.py
│ ├── Dockerfile
│ ├── index.html
│ └── requirements.txt
├── jenkinsfile
├── remote-backend-s3/
│ ├── main.tf
│ └── readme
├── scripts/
│ └── generate_inventory.py
└── terraform/
├── main.tf
├── outputs.tf
├── provider.tf
├── terraform.tfvars
└── variables.tf
- Install Dependencies
- Checkout Code
- Test App
- Build & Push Docker Image
- Terraform Remote Backend
- Archive Backend State File
- Terraform Main Apply
- Generate Ansible Inventory
- Configure EC2 Instances
- Health Check & Auto-Healing
| Stage | Description |
|---|---|
| 1. Install Dependencies | Installs Terraform, Ansible, AWS CLI, Docker, Python deps inside the Jenkins container. |
| 2. Checkout Code | Pulls latest source from GitHub. |
| 3. Test App | Runs syntax tests on the Python (Flask) app. |
| 4. Build & Push Docker Image | Builds image → pushes to DockerHub using credentials. |
| 5. Terraform Remote Backend | Creates S3 bucket + DynamoDB for Terraform state. |
| 6. Terraform Apply (Main) | Provisions AWS infra across two regions. |
| 7. Generate Ansible Inventory | Uses a Python script to generate inventory from Terraform outputs. |
| 8. Configure EC2s with Ansible | Installs Docker, deploys app containers on both regions. |
| 9. Health Check & AutoHeal | Verifies app health; restarts containers if any fail. |
- Jenkins performs periodic health checks after deployment.
- If any EC2 or container fails:
- ASG replaces the unhealthy EC2
- Ansible redeploys the container
- Global Accelerator reroutes traffic automatically to a healthy region
- The pipeline ensures zero downtime and automatic recovery.
Once the deployment is complete, you can access your live web application using the Global Accelerator IP address.
No matter which AWS region or instance goes down, this single IP will always route traffic to a healthy region automatically — ensuring your project stays online 24×7.
http://<GLOBAL_ACCELERATOR_IP>
- ✅ Fully automated end-to-end CI/CD pipeline
- ✅ Multi-region, high-availability infrastructure
- ✅ Self-healing using Jenkins + Ansible + ASG
- ✅ Zero manual steps — push code → full deployment
- ✅ Containerized application for portability
| Credential ID | Type | Description |
|---|---|---|
aws-creds |
AWS Credentials | Used by Terraform |
docker-cred |
Username & Password | DockerHub login |
github-creds |
SSH Key | To clone private repo (optional) |
- Navigate to the terraform directory:
terraform destroy -auto-approve
- To remove the backend (S3 + DynamoDB):
cd remote-backend-s3 terraform destroy -auto-approve
The Jenkins stage "Archive Backend State File" saves the latest S3 backend state (remote-backend-s3/terraform.tfstate) as an artifact.
You can download it from Jenkins → Build Artifacts → terraform.
- ✅ Fully automated CI/CD pipeline
- ✅ Self-healing multi-region deployment
- ✅ Single global IP with automatic failover
- ✅ Complete infrastructure + configuration automation
- ✅ Perfect portfolio-level DevOps project
Anant Chaudhary — DevOps Engineer in progress 🚀
Passionate about automation, cloud architecture, and scalable deployment pipelines.
- GitHub: github.com/Anantch2005
- LinkedIn: linkedin.com/in/anant-chaudhary-b743a52a3