This task aims to automate the provisioning of infrastructure and deployment of applications across multiple cloud platforms (AWS, Azure, and GCP) using Ansible. The automation will cover instance provisioning, networking, storage, and application deployment, ensuring a consistent, scalable, and reproducible environment.
ansible-galaxy collection install amazon.aws google.cloud azure.azcollection
Create a dynamic inventory file for AWS, Azure, and GCP.
aws.yml
)
plugin: amazon.aws.aws_ec2
regions:
- us-east-1
filters:
instance-state-name: running
keyed_groups:
- key: tags['Environment']
prefix: aws
azure.yml
)
plugin: azure.azcollection.azure_rm
auth_source: cli
include_vm_resource_groups:
- myResourceGroup
gcp.yml
)
plugin: google.cloud.gcp_compute
auth_kind: serviceaccount
project_id: my-gcp-project
filters:
- status = RUNNING
We create Ansible Playbooks to provision infrastructure and deploy applications.
- name: Provision AWS EC2 Instance
hosts: localhost
gather_facts: no
tasks:
- name: Launch EC2 Instance
amazon.aws.ec2_instance:
name: "MultiCloud-Server"
region: "us-east-1"
instance_type: "t2.micro"
image_id: "ami-0abcdef1234567890"
key_name: "my-key"
network:
assign_public_ip: true
security_groups: ["multi-cloud-security"]
tags:
Environment: "Production"
register: aws_instance
- name: Display Instance Public IP
debug:
msg: "AWS Instance Public IP: {{ aws_instance.instances[0].public_ip_address }}"
- name: Provision Azure VM
hosts: localhost
tasks:
- name: Create Azure VM
azure.azcollection.azure_rm_virtualmachine:
resource_group: "myResourceGroup"
name: "MultiCloudAzureVM"
vm_size: "Standard_B1s"
admin_username: "azureuser"
admin_password: "Password123!"
image:
offer: "UbuntuServer"
publisher: "Canonical"
sku: "18.04-LTS"
version: "latest"
- name: Provision GCP Instance
hosts: localhost
tasks:
- name: Create a GCP Instance
google.cloud.gcp_compute_instance:
name: "multicloud-gcp-instance"
zone: "us-central1-a"
machine_type: "n1-standard-1"
boot_disk:
initialize_params:
image: "projects/debian-cloud/global/images/debian-10"
network_interfaces:
- network: "default"
access_configs:
- name: "External NAT"
type: "ONE_TO_ONE_NAT"
After provisioning, we deploy an Nginx-based web application across all instances.
- name: Install and Start Nginx
hosts: all
become: yes
tasks:
- name: Install Nginx
package:
name: nginx
state: present
- name: Start Nginx
service:
name: nginx
state: started
enabled: yes
- name: Copy index.html
copy:
src: files/index.html
dest: /var/www/html/index.html
Configure Prometheus & Grafana for monitoring.
To ensure continuous deployment, we integrate Jenkins with Ansible.
pipeline {
agent any
stages {
stage('Provision Infrastructure') {
steps {
sh 'ansible-playbook provision-infra.yml'
}
}
stage('Deploy Application') {
steps {
sh 'ansible-playbook deploy-nginx.yml'
}
}
}
}
This project provides a scalable, automated, and secure way to deploy applications in a multi-cloud environment using Ansible. 🚀