This repository demonstrates a multi-environment deployment strategy using Terraform and Ansible. Terraform handles cloud infrastructure provisioning across different environments (e.g., dev, staging, production), while Ansible is used for post-provisioning configuration and software deployment.
- Multi-Environment Support: Manage deployments for
dev
,staging
, andproduction
environments. - Terraform for Infrastructure Provisioning: Automates resource creation, such as EC2 instances, S3 buckets, and more.
- Ansible for Configuration Management: Configures servers, installs software (e.g., Nginx), and deploys web applications.
- Scalability and Reusability: Modular design for scalable infrastructure management.
- Secure Configuration: Sensitive data is excluded from the repository using
.gitignore
.
.
├── ansible/ # Ansible playbooks and roles
│ ├── inventories/ # Environment-specific inventory files
│ │ ├── dev # Dev environment inventory
│ │ ├── staging # Staging environment inventory
│ │ └── production # Production environment inventory
│ ├── playbooks/ # Main Ansible playbooks
│ │ ├── install_nginx.yml # Playbook to install and configure Nginx
│ │ ├── update_inventories.sh# Script to manage dynamic inventories
│ ├── roles/ # Ansible roles for modular configuration
│ └── nginx-role/ # Role to configure Nginx
│ ├── tasks/ # Tasks for the Nginx role
│ ├── handlers/ # Handlers for restarting services
│ ├── templates/ # Templates for configuration files
│ ├── files/ # Static files (e.g., index.html)
│ ├── vars/ # Role-specific variables
│ ├── defaults/ # Default variables for the role
├── terraform/ # Terraform configurations
│ ├── infra/ # Specific resource configurations
│ ├── main.tf # Main Terraform configuration
│ ├── providers.tf # Provider configurations
│ ├── variables.tf # Input variables for environments
│ ├── .gitignore # Excludes sensitive files and unnecessary directories
├── LICENSE # License for the project
Before starting, ensure the following tools are installed:
- Terraform: Install Terraform
- Ansible: Install Ansible
- AWS CLI: Install AWS CLI
- Git: Install Git
git clone https://github.com/kush-shah05/Multi-Environment-Deployment-with-Terraform-and-Ansible.git
cd Multi-Environment-Deployment-with-Terraform-and-Ansible
-
Navigate to the Terraform Directory:
cd terraform
-
Initialize Terraform:
terraform init
-
Set Environment Variables: Export environment-specific variables, e.g.:
export TF_VAR_environment="dev"
-
Plan the Deployment:
terraform plan
-
Apply the Configuration:
terraform apply
-
Note the Outputs: Terraform will output information (e.g., IP addresses) needed for Ansible configuration.
-
Update Ansible Inventory: Update
ansible/inventories/<environment>
with the IP addresses of the provisioned instances. -
Run Ansible Playbook: Execute the playbook to configure the instances:
ansible-playbook -i ansible/inventories/dev ansible/playbooks/install_nginx.yml
- Private Keys: Ensure private keys are excluded using
.gitignore
. - State Files: Avoid committing Terraform state files (
terraform.tfstate
) as they may contain sensitive information. - Ansible Vault: Use Ansible Vault to encrypt sensitive variables.
This project is licensed under the MIT License.
Contributions are welcome! Please open an issue or submit a pull request for improvements.
Kush Shah
GitHub Profile