Skip to content

nicoghezzi/ansible-integration-with-jenkins

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 CI/CD Pipeline: Jenkins → Ansible → AWS EC2

CI/CD: Jenkins Config Mgmt: Ansible Cloud: AWS Compute: EC2 Security: SSH

An automated DevOps pipeline that integrates Jenkins with Ansible to provision and configure AWS EC2 instances through secure, multi-stage remote execution.


📌 Overview

This project demonstrates an end-to-end deployment workflow:

  • Pulls infrastructure/configuration code from GitLab
  • Prepares a remote Ansible control node
  • Executes Ansible playbooks against AWS EC2 instances
  • Handles secure credential management across multiple hops

⚙️ Pipeline Workflow

1. Source Code Sync

  • Jenkins pulls latest configuration from GitLab
  • Synchronizes project files to Ansible control node

2. Control Node Preparation

  • Installs dependencies (Ansible, boto3) via Bash
  • Ensures environment is ready for execution

3. Secure Credential Handling

  • Injects SSH keys using Jenkins Credentials
  • Applies strict permissions (chmod 400)
  • Transfers AWS .pem key securely at runtime

4. Ansible Execution

  • Runs playbooks from control node
  • Configures AWS EC2 instances
  • Ensures consistent infrastructure state

🧰 Tech Stack

  • Jenkins (CI/CD, Declarative Pipelines): I used Jenkins because it was the default tool at the workplace. I would've used GitHub Actions or GitLab CI.
  • Ansible (Configuration Management)
  • AWS EC2 (Cloud Compute)
  • GitLab (Version Control)
  • Bash (Automation Scripting)
  • SSH Agent + Jenkins Credentials (Security)

💡 Key Skills Demonstrated

  • Multi-hop SSH authentication (Jenkins → Ansible → EC2)
  • Pipeline as Code using Jenkinsfile (Groovy + Declarative syntax)
  • Dynamic inventory handling for AWS EC2
  • Linux automation for dependency installation
  • Secure credential management and secret handling

⚠️ Challenges & Fixes

  • JSch authentication errors → Switched to native OpenSSH with sshagent
  • Credential ID mismatches → Aligned Jenkins credentials with pipeline variables
  • Interactive shell blocking (apt) → Used DEBIAN_FRONTEND=noninteractive
  • Missing SSH key at runtime → Injected .pem via withCredentials

✅ Outcome

  • ✔ Fully automated, one-click deployment pipeline
  • ✔ Secure multi-stage credential handling
  • ✔ Consistent EC2 configuration via Ansible
  • ✔ Repeatable infrastructure provisioning workflow

🧪 Takeaway

This project demonstrates how to integrate CI/CD pipelines with configuration management tools to achieve secure, automated infrastructure deployment. It highlights real-world challenges in authentication, remote execution, and environment setup—along with practical solutions for building reliable DevOps systems.

Evidence

Step 1: Jenkins Server Lighthouse Report

Step 2: Ansible Server Lighthouse Report

Step 3: Jenkins Configuration Pipeline Lighthouse Report

Step 4: Jenkins Adjust Credentials Lighthouse Report

Step 5: Test Connection with the 2 EC2 instances Lighthouse Report

Step 6: Successfull Run Pipeline Lighthouse Report

About

Built a one-click CI/CD pipeline where a code push to GitLab automatically triggers Jenkins to sync the Ansible project, install dependencies, deploy the AWS SSH key, and execute the playbook to configure EC2 instances on Amazon Web Services.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors