-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathsetup_vpc_subnets.yml
62 lines (47 loc) · 1.78 KB
/
setup_vpc_subnets.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
---
- name: "setup VPC"
hosts: localhost
gather_facts: no
vars:
aws_region: us-west-2 # If not specified then the value of the EC2_REGION environment variable, if any, is used.
# prefix for naming
prefix: dev
top_cidr: 10.0.0.0/16
subnet_block_1: 10.0.0.0/24
subnet_block_2: 10.0.1.0/24
# availability zone
az0: a
az1: b
# --purpose choices=['internal', 'external'], help='Purpose of the subnet'
purpose_subnet: internal
# --target , choices=['ec2', 'elb'], help='Type of subnet: ec2 or elb.'
target_subnet: elb
tasks:
- name: create vpc
local_action:
module: ec2_vpc
region: "{{ aws_region }}"
cidr_block: "{{ top_cidr }}"
resource_tags: '{"Name":"{{ prefix }}_vpc"}'
subnets:
- cidr: "{{ subnet_block_1 }}"
az: "{{ aws_region }}{{ az0 }}"
resource_tags: '{"Name":"subnet_public","immutable_metadata":"{\"purpose\":\"external\",\"target\":\"{{ target_subnet }}\"}"}'
- cidr: "{{ subnet_block_2 }}"
az: "{{ aws_region }}{{ az1 }}"
resource_tags: '{"Name":"subnet_private","immutable_metadata":"{\"purpose\":\"{{ purpose_subnet }}\",\"target\":\"{{ target_subnet }}\"}"}'
internet_gateway: yes
route_tables:
- subnets:
- "{{ subnet_block_1 }}"
routes:
- dest: 0.0.0.0/0
gw: igw
register: vpc
- name: write vpc id to group_vars/all file
local_action: shell echo "vpc_id:" "{{ vpc.vpc_id }}"
>> group_vars/all
- name: write subnets id to group_vars/all file
local_action: shell echo "{{ item.resource_tags.Name }}"":" "{{ item.id }}"
>> group_vars/all
with_items: vpc.subnets