Ansible is a powerful automation tool that can manage infrastructure across multiple cloud providers. With its agentless architecture and extensive collection of cloud modules, Ansible enables you to provision, configure, and manage cloud resources consistently across different platforms.
Ansible supports automation for a wide range of cloud providers through collections. The major platforms include:
| Platform | Collection | Key Services |
|---|---|---|
| 🟠 AWS | amazon.aws |
EC2, S3, RDS, VPC, IAM, Lambda |
| 🔵 Azure | azure.azcollection |
VMs, Storage, SQL, VNet, AKS |
| 🔴 GCP | google.cloud |
Compute Engine, Cloud Storage, GKE, Cloud SQL |
| 🟣 DigitalOcean | community.digitalocean |
Droplets, Spaces, Load Balancers |
| 🟢 Linode | community.linode |
Instances, NodeBalancers, Volumes |
| 🔷 Oracle Cloud | oracle.oci |
Compute, VCN, Load Balancer, Object Storage |
| 🔵 IBM Cloud | ibm.cloud |
VSI, VPC, Cloud Object Storage |
| 🟠 VMware | community.vmware |
vSphere, ESXi, vCenter |
| 🦊 Proxmox | community.proxmox |
KVM VMs, LXC Containers |
| 🔷 OpenStack | openstack.cloud |
Nova, Neutron, Cinder, Swift |
Guide to managing AWS infrastructure with Ansible.
Topics covered:
Example use case:
- name: Launch EC2 instance
amazon.aws.ec2_instance:
name: web-server-01
instance_type: t3.medium
image_id: ami-0c55b159cbfafe1f0
key_name: my-keypair
region: us-east-1
wait: true
tags:
Environment: Production
Application: WebServer
Complete guide to automating Azure resources with Ansible.
Topics covered:
Example use case:
- name: Create Azure VM
azure.azcollection.azure_rm_virtualmachine:
resource_group: my-rg
name: web-server-01
vm_size: Standard_DS2_v2
admin_username: azureuser
image:
offer: UbuntuServer
publisher: Canonical
sku: 2204-LTS
tags:
Environment: Production
Application: WebServer
Detailed guide for managing GCP infrastructure with Ansible.
Topics covered:
Example use case:
- name: Create GCP instance
google.cloud.gcp_compute_instance:
name: web-server-01
machine_type: e2-medium
zone: us-central1-a
project: my-project-id
disks:
- boot: true
initialize_params:
source_image: debian-11
network_interfaces:
- network:
name: default
Guide covering additional cloud providers and private cloud platforms.
Platforms covered:
Example use case (DigitalOcean):
- name: Create DigitalOcean Droplet
community.digitalocean.digital_ocean_droplet:
state: present
name: web-server-01
oauth_token: "{{ do_token }}"
size: s-1vcpu-1gb
region: nyc3
image: ubuntu-22-04-x64
tags:
- webserver
- production
→ Read the full guide on other platforms
# AWS
ansible-galaxy collection install amazon.aws
# Azure
ansible-galaxy collection install azure.azcollection
pip install azure-cli azure-mgmt-compute azure-mgmt-network
# GCP
ansible-galaxy collection install google.cloud
pip install google-auth
# DigitalOcean
ansible-galaxy collection install community.digitalocean
# Linode
ansible-galaxy collection install community.linode
# Oracle Cloud
ansible-galaxy collection install oracle.oci
# IBM Cloud
ansible-galaxy collection install ibm.cloud
# VMware
ansible-galaxy collection install community.vmware
pip install pyvmomi
# Proxmox
ansible-galaxy collection install community.proxmox
pip install proxmoxer requests
# OpenStack
ansible-galaxy collection install openstack.cloud
pip install openstacksdk
Each cloud provider has its own authentication method:
export AWS_ACCESS_KEY_ID="your_access_key"
export AWS_SECRET_ACCESS_KEY="your_secret_key"
export AWS_REGION="us-east-1"
az login
# Or use service principal
export AZURE_CLIENT_ID="xxx"
export AZURE_SECRET="xxx"
export AZURE_TENANT_ID="xxx"
export AZURE_SUBSCRIPTION_ID="xxx"
gcloud auth application-default login
# Or use service account
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/service-account.json"
export DO_API_TOKEN="your_digitalocean_api_token"
export LINODE_API_TOKEN="your_linode_api_token"
Ansible supports dynamic inventory for cloud providers, allowing you to automatically discover and manage instances:
# aws_ec2.yml
plugin: amazon.aws.aws_ec2
regions:
- us-east-1
- us-west-2
filters:
tag:Environment: Production
instance-state-name: running
keyed_groups:
- key: tags.Application
prefix: app
- key: placement.region
prefix: region
# azure_rm.yml
plugin: azure.azcollection.azure_rm
include_powerstate: yes
groups:
production: "'Production' in tags.Environment"
webserver: "'WebServer' in tags.Role"
keyed_groups:
- key: location
prefix: location
- key: tags.Application
prefix: app
# gcp_compute.yml
plugin: google.cloud.gcp_compute
projects:
- my-project-id
filters:
- status = RUNNING
keyed_groups:
- key: labels.environment
prefix: env
- key: labels.application
prefix: app
# List inventory
ansible-inventory -i aws_ec2.yml --list
# Run playbook with dynamic inventory
ansible-playbook -i aws_ec2.yml deploy.yml
All cloud modules support idempotency. Use state: present or state: absent:
- name: Ensure instance exists
amazon.aws.ec2_instance:
name: web-server
state: present
- name: Ensure old instance is removed
amazon.aws.ec2_instance:
name: old-server
state: absent
tags:
Name: "{{ app_name }}-{{ role }}-{{ env }}"
Environment: "{{ env }}"
Application: "{{ app_name }}"
ManagedBy: Ansible
CostCenter: "12345"
For resources that need time to provision:
- name: Create RDS instance
amazon.aws.rds_instance:
# ... parameters ...
wait: true
wait_timeout: 900
- name: Create instance with retry
amazon.aws.ec2_instance:
# ... parameters ...
register: instance
retries: 3
delay: 10
until: instance.instances[0].state.name == 'running'
vars:
aws_region: us-east-1
instance_type: t3.medium
environment: production
tasks:
- name: Launch instance
amazon.aws.ec2_instance:
region: "{{ aws_region }}"
instance_type: "{{ instance_type }}"
tags:
Environment: "{{ environment }}"
Create reusable roles for common infrastructure patterns:
roles/
├── aws-webserver/
│ ├── tasks/
│ ├── vars/
│ └── defaults/
├── azure-webserver/
│ ├── tasks/
│ ├── vars/
│ └── defaults/
└── gcp-webserver/
├── tasks/
├── vars/
└── defaults/
Deploy across multiple clouds for redundancy:
- name: Deploy multi-cloud infrastructure
hosts: localhost
tasks:
# AWS deployment
- include_tasks: deploy-aws.yml
tags: aws
# Azure deployment
- include_tasks: deploy-azure.yml
tags: azure
# GCP deployment
- include_tasks: deploy-gcp.yml
tags: gcp
Design roles that work across providers:
# roles/webserver/tasks/main.yml
- name: Include cloud-specific tasks
include_tasks: "{{ cloud_provider }}.yml"
vars:
cloud_provider: "{{ target_cloud }}"
Authentication failures
Module not found
ansible-galaxy collection install <collection>Rate limiting
wait parameters appropriatelyResource quotas
Any questions?
Feel free to contact us. Find all contact information on our contact page.