AutoJenkins: CI/CD Deployment with Terraform & Ansible on AWS
π Website / Demo
http://YOUR_EC2_PUBLIC_IP:8080 (replace with real IP)
π Short Description
We automated the full deployment of Jenkins on AWS using Infrastructure as Code (IaC) with Terraform and Ansible. In just one command, an EC2 instance is created, secured, configured with SSH, and provisioned with a fully working Jenkins CI server β without ever logging into the instance.
π‘ Inspiration
Manually launching cloud infrastructure and setting up CI/CD tools is time-consuming and error-prone. We wanted a fully automated, repeatable solution that reflects real-world DevOps practices, using industry-standard tools like Terraform and Ansible.
π§ What It Does
-
Terraform provisions:
- A new AWS EC2 Ubuntu instance
- A security group with SSH & Jenkins ports open
- An SSH key for secure access
-
Ansible configures the instance by:
- Installing OpenJDK 17
- Adding the Jenkins APT repo & GPG key
- Installing Jenkins
- Ensuring the Jenkins service is enabled and running
π§ How We Built It
- Used Terraform to define infrastructure as code in
main.tf
- Used Ansible to define the configuration in
playbook.yaml
- Automatically passed the EC2 public IP from Terraform to Ansible
-
Ran everything from a single terminal with:
terraform apply -auto-approve ansible-playbook -i inventory playbook.yaml
Debugged service failures by parsing logs with Ansible (not SSH)
π§© Challenges We Ran Into
- Jenkins failed to start with Java 11. We read logs via
journalctl
using Ansible and discovered Jenkins now requires Java 17+ - EC2 SSH keys had to be managed properly to avoid permission errors
- Jenkins port (8080) had to be opened in the security group
β Accomplishments We're Proud Of
- Zero SSH login required throughout the project
- Clean separation of infrastructure (Terraform) and config (Ansible)
- Used proper logging and error handling via Ansible
- Debugged systemd failures using
journalctl
inside playbooks
π Whatβs Next
- Add DNS and HTTPS (via Route 53 + Letβs Encrypt)
- Integrate GitHub Webhooks to trigger Jenkins jobs automatically
- Use S3 and CloudWatch for backups and monitoring
π Built With
- βοΈ AWS EC2
- π§± Terraform
- βοΈ Ansible
- π§ Ubuntu 22.04
- π» Jenkins
π₯ Team
- Muhirwa β DevOps Engineer & Builder
GitHub - muhirwaJD/Terraform-and-Ansible
Top comments (0)