Skip to content

Instantly share code, notes, and snippets.

@conleym
Last active July 26, 2016 19:02
Show Gist options
  • Save conleym/8815513d20ad437311366bbf533f0ceb to your computer and use it in GitHub Desktop.
Save conleym/8815513d20ad437311366bbf533f0ceb to your computer and use it in GitHub Desktop.
Tasks to find the default VPC and its subnets
- name: Find default VPC for region
command: "aws ec2 describe-vpcs --region={{ region }} --output=json --filters=Name=isDefault,Values=true --query=Vpcs[0].VpcId"
register: default_vpc
- name: Set default_vpc_id fact
set_fact:
default_vpc_id: "{{ default_vpc.stdout | from_json }}"
- name: Find availability zones in the default VPC
ec2_vpc_subnet_facts:
region: "{{ region }}"
filters:
defaultForAz: "true"
state: "available"
vpc-id: "{{ default_vpc_id }}"
register: default_subnets
- name: Set subnet_ids fact
set_fact:
subnet_ids: "{{ default_subnets.subnets | map(attribute='id') | list }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment