Tok
2018-11-09 04259f14a042c84a1164402d9ac2009c9db6adf5
commit | author | age
2a18ae 1 AWSTemplateFormatVersion: "2010-09-09"
S 2 Mappings:
3   RegionMapping:
4     us-east-1:
5       RHELAMI: ami-c998b6b2
0b1176 6       WIN2012R2AMI: ami-0dcdd073eeabb0101
2a18ae 7     us-east-2:
S 8       RHELAMI: ami-cfdafaaa
9       WIN2012R2AMI: ami-72745d17
10     us-west-1:
11       RHELAMI: ami-66eec506
12       WIN2012R2AMI: ami-ef95ae8f
13     us-west-2:
14       RHELAMI: ami-9fa343e7
15       WIN2012R2AMI: ami-af5980d7
16     eu-west-1:
17       RHELAMI: ami-bb9a6bc2
18       WIN2012R2AMI: ami-24f04d5d
19     eu-west-2:
20       WIN2012R2AMI: ami-6a746a0e
21     ca-central-1:
22       WIN2012R2AMI: ami-4e4cf72a
23     eu-central-1:
24       RHELAMI: ami-d74be5b8
25       WIN2012R2AMI: ami-88c14ee7
26     ap-northeast-1:
27       RHELAMI: ami-30ef0556
28       WIN2012R2AMI: ami-dcdd66ba
29     ap-northeast-2:
30       RHELAMI: ami-0f5a8361
31       WIN2012R2AMI: ami-681cbb06
32     ap-southeast-1:
33       RHELAMI: ami-10bb2373
34       WIN2012R2AMI: ami-f887d59b
35     ap-southeast-2:
36       RHELAMI: ami-ccecf5af
37       WIN2012R2AMI: ami-f601f494
38     sa-east-1:
39       RHELAMI: ami-a789ffcb
40       WIN2012R2AMI: ami-42a5e12e
41     ap-south-1:
42       RHELAMI: ami-cdbdd7a2
43       WIN2012R2AMI: ami-b9e8a6d6
44   DNSMapping:
45     "us-east-1":
46       domain: "us-east-1.compute.internal"
47     "us-west-1":
48       domain: "us-west-1.compute.internal"
49     "us-west-2":
50       domain: "us-west-2.compute.internal"
51     "eu-west-1":
52       domain: "eu-west-1.compute.internal"
53     "eu-central-1":
54       domain: "eu-central-1.compute.internal"
55     "ap-northeast-1":
56       domain: "ap-northeast-1.compute.internal"
57     "ap-northeast-2":
58       domain: "ap-northeast-2.compute.internal"
59     "ap-southeast-1":
60       domain: "ap-southeast-1.compute.internal"
61     "ap-southeast-2":
62       domain: "ap-southeast-2.compute.internal"
63     "sa-east-1":
64       domain: "sa-east-1.compute.internal"
65     "ap-south-1":
66       domain: "ap-south-1.compute.internal"
67 Resources:
68    Vpc:
69     Type: "AWS::EC2::VPC"
70     Properties:
71      CidrBlock: "192.199.0.0/16"
72      EnableDnsSupport: true
73      EnableDnsHostnames: true
74      Tags:
75       - Key: Name
76         Value: "{{vpcid_name_tag}}"
77       - Key: Hostlication
78         Value:
79           Ref: "AWS::StackId"
80    VpcInternetGateway:
81     Type: "AWS::EC2::InternetGateway"
82    VpcGA:
83     Type: "AWS::EC2::VPCGatewayAttachment"
84     Properties:
85      InternetGatewayId:
86       Ref: VpcInternetGateway
87      VpcId:
88       Ref: Vpc
89    VpcRouteTable:
90     Type: "AWS::EC2::RouteTable"
91     Properties:
92      VpcId:
93       Ref: Vpc
94    VPCRouteInternetGateway:
95     DependsOn: VpcGA
96     Type: "AWS::EC2::Route"
97     Properties:
98      GatewayId:
99       Ref: VpcInternetGateway
100      DestinationCidrBlock: "0.0.0.0/0"
101      RouteTableId:
102       Ref: VpcRouteTable
103    PublicSubnet:
104     Type: "AWS::EC2::Subnet"
105     DependsOn:
106      - Vpc
107     Properties:
108      CidrBlock: "192.199.0.0/24"
109      Tags:
110       - Key: Name
111         Value: "{{project_tag}}"
112       - Key: Hostlication
113         Value:
114           Ref: "AWS::StackId"
115      MapPublicIpOnLaunch: true
116      VpcId:
117       Ref: Vpc
118    PublicSubnetRTA:
119     Type: "AWS::EC2::SubnetRouteTableAssociation"
120     Properties:
121      RouteTableId:
122       Ref: VpcRouteTable
123      SubnetId:
124       Ref: PublicSubnet
125    HostSG:
126     Type: "AWS::EC2::SecurityGroup"
127     Properties:
128      GroupDescription: Host
129      VpcId:
130       Ref: Vpc
131      Tags:
132       - Key: Name
133         Value: host_sg
134    HostUDPPorts:
135     Type: "AWS::EC2::SecurityGroupIngress"
136     Properties:
137      GroupId:
138       "Fn::GetAtt":
139        - HostSG
140        - GroupId
141      IpProtocol: udp
142      FromPort: 0
143      ToPort: 65535
144      CidrIp: "0.0.0.0/0"
145    HostTCPPorts:
146     Type: "AWS::EC2::SecurityGroupIngress"
147     Properties:
148      GroupId:
149       "Fn::GetAtt":
150        - HostSG
151        - GroupId
152      IpProtocol: tcp
153      FromPort: 0
154      ToPort: 65535
155      CidrIp: "0.0.0.0/0"
156    zoneinternalidns:
157     Type: "AWS::Route53::HostedZone"
158     Properties:
159      Name: "{{ zone_internal_dns }}"
160      VPCs:
161       - VPCId:
162           Ref: Vpc
163         VPCRegion:
164           Ref: "AWS::Region"
165      HostedZoneConfig:
166       Comment: "Created By ansible agnostic deployer"
167
168 {% for instance in instances %}
169 {% if instance['dns_loadbalancer']|d(false)|bool and not instance['unique']|d(false)|bool %}
170    {{instance['name']}}DNSLoadBalancer:
171     Type: "AWS::Route53::RecordSetGroup"
172     DependsOn:
173 {% for c in range(1,(instance['count'] |int)+1) %}
174     - {{instance['name']}}{{c}}EIP
175 {% endfor %}
176     Properties:
177      HostedZoneId: {{HostedZoneId}}
178      RecordSets:
179       - Name: "{{instance['name']}}.{{subdomain_base}}."
180         Type: A
181         TTL: 900
182         ResourceRecords:
183 {% for c in range(1,(instance['count'] |int)+1) %}
184           - "Fn::GetAtt":
185             - {{instance['name']}}{{loop.index}}
186             - PublicIp
187 {% endfor %}
188 {% endif %}
189
190 {% for c in range(1,(instance['count'] |int)+1) %}
191    {{instance['name']}}{{loop.index}}:
192     Type: "AWS::EC2::Instance"
193     Properties:
194      ImageId:
195       "Fn::FindInMap":
196        - RegionMapping
197        - Ref: "AWS::Region"
198        - {{ instance['image_id'] | default('RHELAMI') }}
199
200      InstanceType: "{{instance['flavor'][cloud_provider]}}"
201      KeyName: "{{instance['key_name'] | default(key_name)}}"
202 {% if instance['UserData'] is defined %}
203      {{instance['UserData']}}
204 {% endif %}
205      SecurityGroupIds:
206         - "Fn::GetAtt":
207           - HostSG
208           - GroupId
209      SubnetId:
210       Ref: PublicSubnet
211      Tags:
212 {% if instance['unique'] | d(false) | bool %}
213       - Key: Name
214         Value: {{instance['name']}}
215       - Key: internaldns
216         Value: {{instance['name']}}.{{chomped_zone_internal_dns}}
217 {% else %}
218       - Key: Name
219         Value: {{instance['name']}}{{loop.index}}
220       - Key: internaldns
221         Value: {{instance['name']}}{{loop.index}}.{{chomped_zone_internal_dns}}
222 {% endif %}
223       - Key: "owner"
224         Value: "{{ email | default('unknownuser') }}"
225       - Key: "Project"
226         Value: "{{project_tag}}"
227       - Key: "{{project_tag}}"
228         Value: "{{ instance['name'] }}"
229 {% for tag in instance['tags'] %}
230       - Key: {{tag['key']}}
231         Value: {{tag['value']}}
232 {% endfor %}
233      BlockDeviceMappings:
234         - DeviceName: "/dev/sda1"
235           Ebs:
236             VolumeSize: 50
237         - DeviceName: "/dev/xvdb"
238           Ebs:
239             VolumeType: gp2
240             VolumeSize: 20
241    {{instance['name']}}{{loop.index}}InternalDNS:
242     Type: "AWS::Route53::RecordSetGroup"
243     Properties:
244      HostedZoneId:
245       Ref: zoneinternalidns
246      RecordSets:
247 {% if instance['unique'] | d(false) | bool %}
248       - Name: "{{instance['name']}}.{{zone_internal_dns}}"
249 {% else %}
250       - Name: "{{instance['name']}}{{loop.index}}.{{zone_internal_dns}}"
251 {% endif %}
252         Type: A
253         TTL: 10
254         ResourceRecords:
255           - "Fn::GetAtt":
256             - {{instance['name']}}{{loop.index}}
257             - PrivateIp
258 {% if instance['public_dns'] %}
259    {{instance['name']}}{{loop.index}}EIP:
260      Type: "AWS::EC2::EIP"
261      DependsOn:
262       - VpcGA
263      Properties:
264       InstanceId:
265        Ref: {{instance['name']}}{{loop.index}}
266    {{instance['name']}}{{loop.index}}PubliclDNS:
267      Type: "AWS::Route53::RecordSetGroup"
268      DependsOn:
269         - {{instance['name']}}{{loop.index}}EIP
270      Properties:
271       HostedZoneId: {{HostedZoneId}}
272       RecordSets:
273 {% if instance['unique'] | d(false) | bool %}
274         - Name: "{{instance['name']}}.{{subdomain_base}}."
275 {% else %}
276         - Name: "{{instance['name']}}{{loop.index}}.{{subdomain_base}}."
277 {% endif %}
278           Type: A
279           TTL: 10
280           ResourceRecords:
281           - "Fn::GetAtt":
282             - {{instance['name']}}{{loop.index}}
283             - PublicIp
284 {% endif %}
285
286 {% endfor %}
287 {% endfor %}