-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcreate_aws_vpc.yml
133 lines (119 loc) · 3.65 KB
/
create_aws_vpc.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
---
- name: Provision AWS instances
hosts: localhost
connection: local
gather_facts: False
# load AWS variables from this group vars file
vars_files:
- group_vars/all
tasks:
- name: Verify that you have set a value for user_name before running
assert:
that:
- user_name is defined
fail_msg: "You must define your user_name in extra_vars"
success_msg: "user_name set to {{user_name}}"
- name: create a VPC with dedicated tenancy and a couple of tags
ec2_vpc_net:
name: "{{ ec2_vpc_net_name }}"
cidr_block: "{{ ec2_cidr }}"
region: "{{ ec2_region }}"
tags:
Name: "{{ ec2_vpc_net_name }}"
ansible_group: "{{ ec2_ansible_group }}"
Contact: "{{ my_email_address }}"
DeleteBy: Never
tenancy: default
register: my_vpc
- name: dump vpc info for my_vpc
debug:
var: my_vpc
when: debug_flag is defined
- name: create security group "{{ ec2_security_group_name }}"
ec2_group:
name: "{{ ec2_security_group_name }}"
description: security group with rule descriptions
vpc_id: "{{ my_vpc.vpc.id }}"
region: "{{ ec2_region }}"
tags:
Name: "{{ ec2_security_group_name }}"
ansible_group: "{{ ec2_ansible_group }}"
Contact: "{{ my_email_address }}"
DeleteBy: Never
rules:
- proto: icmp
from_port: 8 # icmp type, -1 = any type
to_port: -1 # icmp subtype, -1 = any subtype
cidr_ip: 0.0.0.0/0
rule_desc: allow ping
- proto: tcp
ports:
- 22
- 80
cidr_ip: 0.0.0.0/0
rule_desc: allow all on port 22,80
register: my_security_group
- name: dump security group info for {{ my_security_group }}
debug:
var: my_security_group
when: debug_flag is defined
- name: dump security group info for {{ my_security_group.group_id }}
debug:
var: my_security_group.group_id
when: debug_flag is defined
- name: dump security group info for {{ my_security_group.group_name }}
debug:
var: my_security_group.group_name
when: debug_flag is defined
- name: Create {{ ec2_vpc_subnet_name }} subnet
ec2_vpc_subnet:
state: present
vpc_id: "{{ my_vpc.vpc.id }}"
region: "{{ ec2_region }}"
cidr: "{{ ec2_cidr }}"
map_public: yes
tags:
Name: "{{ ec2_vpc_subnet_name }}"
ansible_group: "{{ ec2_ansible_group }}"
Contact: "{{ my_email_address }}"
DeleteBy: Never
register: my_vpc_subnet
- name: dump {{ ec2_vpc_subnet_name }} info
debug:
var: my_vpc_subnet
when: debug_flag is defined
- name: create {{ ec2_igw_name }}"
ec2_vpc_igw:
vpc_id: "{{ my_vpc.vpc.id }}"
region: "{{ ec2_region }}"
state: present
tags:
Name:: "{{ ec2_igw_name }}"
ansible_group: "{{ ec2_ansible_group }}"
Contact: "{{ my_email_address }}"
DeleteBy: Never
register: my_igw
- name: dump {{ ec2_igw_name }} info
debug:
var: my_igw
when: debug_flag is defined
- name: Set up public subnet route table
ec2_vpc_route_table:
vpc_id: "{{ my_vpc.vpc.id }}"
region: "{{ ec2_region }}"
tags:
Name: "{{ ec2_route_table_name }}"
ansible_group: "{{ ec2_ansible_group }}"
Contact: "{{ my_email_address }}"
DeleteBy: Never
subnets:
- "{{ my_vpc_subnet.subnet.id }}"
routes:
- dest: 0.0.0.0/0
gateway_id: "{{ my_igw.gateway_id }}"
register: my_route_table
- name: dump {{ my_route_table }} info
debug:
var: my_route_table
when: debug_flag is defined
...