Ansible role for managing AWS VPCs
- Shell 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
|
||
| .forgejo/workflows | ||
| defaults | ||
| meta | ||
| tasks | ||
| tests | ||
| vars | ||
| .ansible-lint | ||
| .gitignore | ||
| ansible.cfg | ||
| CHANGELOG.md | ||
| LICENSE | ||
| make.sh | ||
| pyproject.toml | ||
| README.md | ||
| requirements.yaml | ||
| uv.lock | ||
AWS VPC Ansible role
This ansible role handles the setup and teardown of an AWS VPC.
Requirements
uv.
Dependencies
See pyproject.toml for the python dependencies and requirements.yaml for the ansible galaxy dependencies.
Role Variables
Required Variables
| Variable | Description | Example |
|---|---|---|
aws_vpc_name |
Name or name prefix for all resources | ansible-role-aws_vpc |
Optional Variables
Optional variables and their defaults are in defaults/main.yaml.
aws_vpc_profile and aws_vpc_region are unset by default, meaning that the
standard AWS resolution chain applies. Set them explicitly to pin the role to a
specific profile or region.
Note that aws_vpc_cidr_block cannot be changed on an existing VPC: AWS does
not support resizing a VPC primary CIDR block.
Role Results
The create tasks set an aws_vpc_result fact for consumption by subsequent
tasks and roles:
| Key | Type | Description |
|---|---|---|
availability_zone_names |
list | Availability zone names, in the same order as the subnet ids |
cidr_block |
str | IPv4 CIDR block of the VPC |
internet_gateway_id |
str | Internet gateway id |
ipv6_cidr_block |
str | Amazon-provided IPv6 CIDR block of the VPC |
public_route_table_id |
str | Public route table id |
public_subnet_ids |
list | Public subnet ids, one per availability zone |
public_subnet_ids_by_az |
dict | Availability zone name to public subnet id |
public_subnet_ipv4_cidrs_by_az |
dict | Availability zone name to public subnet IPv4 CIDR block |
public_subnet_ipv6_cidrs_by_az |
dict | Availability zone name to public subnet IPv6 CIDR block |
vpc_id |
str | VPC id |
Example Playbooks
Create
---
- name: 'Bootstrap the role test environment'
hosts: 'localhost'
gather_facts: false
tasks:
- name: 'Execute the role main tasks'
ansible.builtin.include_role:
name: 'aws_vpc'
tasks_from: 'create.yaml'
vars:
aws_vpc_name: 'ansible-role-aws_vpc'
- name: 'Use the role result'
ansible.builtin.debug:
msg: 'Deploying into subnets {{ aws_vpc_result.public_subnet_ids | join(", ") }}'
Destroy
---
- name: 'Destroy the test environment'
hosts: 'localhost'
gather_facts: false
tasks:
- name: 'Execute the role cleanup tasks'
ansible.builtin.include_role:
name: 'aws_vpc'
tasks_from: 'destroy.yaml'
vars:
aws_vpc_name: 'ansible-role-aws_vpc'
Testing
Run ./make.sh check for linting and ./make.sh test for ansible playbook
testing.