This project automates the setup of a CI/CD pipeline for deploying applications to web servers using Jenkins and Ansible. It supports rolling updates and version rollbacks in case of failed deployments.
Here's an enhanced Project Structure section for your README.md file:
/ansible-ci-cd-pipeline
│
├── Jenkinsfile # Jenkins pipeline configuration
├── ansible.cfg # Ansible configuration file
├── playbooks/
│ ├── deploy.yml # Ansible playbook for application deployment
│ ├── rollback.yml # Ansible playbook for version rollback
│ └── update.yml # Ansible playbook for rolling updates
├── inventory/
│ ├── production # Inventory file for production servers
│ └── staging # Inventory file for staging servers
├── roles/
│ ├── setup/
│ │ ├── tasks/
│ │ │ └── main.yml # Tasks to set up the environment (install dependencies, configure services)
│ │ ├── handlers/
│ │ │ └── main.yml # Handlers to restart services after deployment
│ │ ├── templates/
│ │ │ └── apache.conf.j2 # Template for Apache configuration (if applicable)
│ │ └── vars/
│ │ └── main.yml # Variables for environment setup
│ ├── deploy/
│ │ ├── tasks/
│ │ │ └── main.yml # Tasks for application deployment (copy files, restart services)
│ │ └── vars/
│ │ └── main.yml # Variables related to application deployment
│ ├── rollback/
│ │ ├── tasks/
│ │ │ └── main.yml # Tasks for version rollback (restore previous version, restart services)
│ │ └── vars/
│ │ └── main.yml # Variables related to version rollback
│ └── update/
│ ├── tasks/
│ │ └── main.yml # Tasks for rolling updates (deploy updates incrementally)
├── vars/
│ └── global.yml # Global variables used across playbooks and roles
├── README.md # Documentation and instructions for the project
└── .gitignore # Ignore unnecessary files (logs, environment files, etc.)
deploy.yml
: Handles the deployment of the application.rollback.yml
: Executes a version rollback if needed.update.yml
: Performs rolling updates of the application.setup/
: Configures the environment, installs packages, and ensures services are running.deploy/
: Handles the tasks required for deploying the application.rollback/
: Restores the previous version in case of a failed deployment.update/
: Handles rolling updates across servers for minimal downtime.Clone this repository:
git clone https://github.com/yourusername/ansible-ci-cd-pipeline.git
Configure your inventory files (inventory/staging
, inventory/production
) with the necessary hosts.
Set up the necessary credentials for Jenkins to access the servers.
Run the Jenkins pipeline, and it will automatically trigger Ansible playbooks for deployment and updates.
playbooks/deploy.yml
: Deploys the application to web servers.playbooks/rollback.yml
: Rolls back the application to a previous version.playbooks/update.yml
: Performs a rolling update across web servers.