Ansible role for managing AWS VPCs
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Julien Dessaux ad3337c572
All checks were successful
main / test (push) Successful in 0s
chore(role): remove dubious defaults
2026-08-04 15:12:14 +02:00
.forgejo/workflows feat(ci): bootstrap forgejo workflow 2026-04-05 23:50:43 +02:00
defaults chore(role): remove dubious defaults 2026-08-04 15:12:14 +02:00
meta chore(role): remove dubious defaults 2026-08-04 15:12:14 +02:00
tasks chore(role): remove dubious defaults 2026-08-04 15:12:14 +02:00
tests chore(role): remove dubious defaults 2026-08-04 15:12:14 +02:00
vars chore(role): review and improve error handling 2026-07-31 21:35:05 +02:00
.ansible-lint fix(lint): add missing ansible lint exclusion 2026-07-29 14:30:23 +02:00
.gitignore feat(role): initial import 2026-03-30 01:24:52 +02:00
ansible.cfg chore(tooling): switch to a make script 2026-07-29 14:30:50 +02:00
CHANGELOG.md chore(role): remove dubious defaults 2026-08-04 15:12:14 +02:00
LICENSE feat(role): initial import 2026-03-30 01:24:52 +02:00
make.sh chore(role): add a final round of validation checks 2026-08-01 00:47:24 +02:00
pyproject.toml feat(role): initial import 2026-03-30 01:24:52 +02:00
README.md chore(role): remove dubious defaults 2026-08-04 15:12:14 +02:00
requirements.yaml chore(role): rename task files for consistency 2026-07-29 15:47:09 +02:00
uv.lock chore(role): update dependencies 2026-08-01 11:19:15 +02:00

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.