-
Notifications
You must be signed in to change notification settings - Fork 40
/
aws_create_hosts.yml
95 lines (87 loc) · 3.31 KB
/
aws_create_hosts.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
---
- name: Create OpenShift Instances
hosts: localhost
gather_facts: no
vars_files:
- aws_vars.yml
tasks:
- name: Provision AWS Instances
ec2:
key_name: "{{ aws_key_name }}"
group: "{{ aws_sec_group }}"
instance_type: "{{ item.type }}"
image: "{{ item.image }}"
wait: yes
instance_tags:
"{'Name': '{{ item.name }}-{{ student_id }}.{{ domain_name }}', 'lab_name': '{{ lab_name }}', 'lab_user': '{{ lab_user }}', 'lab_role': '{{ item.meta.node_type }}', 'student_id': '{{ student_id }}', 'node_group': '{{ item.meta.node_group }}', 'kubernetes.io/cluster/{{ student_id }}': '{{ student_id }}'}"
vpc_subnet_id: "{{ aws_subnet_id }}"
zone: "{{ aws_az_1 }}"
assign_public_ip: yes
region: "{{ aws_region }}"
state: present
user_data: "{{ lookup('template', 'aws_user_data.j2') }}"
with_items: "{{ aws_instances }}"
register: instances_created
- add_host:
hostname: "{{ item.instances.0.tags.Name }}"
ansible_host: "{{ item.instances.0.public_ip }}"
public_dns_name: "{{ item.instances.0.public_dns_name }}"
public_ip: "{{ item.instances.0.public_ip }}"
groups: OSEv3
student_id: "{{ item.instances.0.tags.student_id }}"
with_items: "{{ instances_created.results }}"
- debug:
var: groups
verbosity: 2
- name: Wait for ssh
wait_for:
port: 22
host: "{{ item.instances.0.public_ip }}"
timeout: 1000
with_items: "{{ instances_created.results }}"
- name: Register Host DNS
route53:
command: create
zone: "{{ domain_name }}"
type: A
overwrite: True
ttl: 60
record: "{{ item['instances'][0]['tags']['Name'] }}"
value: "{{ item['instances'][0]['public_ip'] }}"
wait: yes
register: host_dns_entries
with_items: "{{ instances_created.results }}"
- name: Register Public Environment DNS
route53:
command: create
zone: "{{ domain_name }}"
type: A
overwrite: True
ttl: 60
record: "{{ item.1 }}"
value: "{{ instances_created.results[aws_instances.index(item.0)]['instances'][0]['public_ip'] }}"
with_nested:
- "{{ aws_instances }}"
- [ "{{ openshift_master_dns_prefix }}-{{ student_id }}.{{ domain_name }}", "*.apps-{{ student_id }}.{{ domain_name }}" ]
when: "'node_type' in item.0['meta'] and 'master' in item.0['meta']['node_type']"
- name: Register Private Environment DNS
route53:
command: create
zone: "{{ domain_name }}"
type: A
overwrite: True
ttl: 60
record: "{{ item.1 }}"
value: "{{ instances_created.results[aws_instances.index(item.0)]['instances'][0]['private_ip'] }}"
with_nested:
- "{{ aws_instances }}"
- [ "{{ openshift_master_internal_dns_prefix }}-{{ student_id }}.{{ domain_name }}" ]
when: "'node_type' in item.0['meta'] and 'master' in item.0['meta']['node_type']"
- name: Wait for resolvable route53 hostname
local_action: command host {{ item['instances'][0]['tags']['Name'] }}
register: host_result
until: host_result.rc == 0
retries: 60
delay: 5
with_items: "{{ instances_created.results }}"
...