-
Notifications
You must be signed in to change notification settings - Fork 40
/
aws_lab_launch.yml
92 lines (83 loc) · 2.47 KB
/
aws_lab_launch.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
---
- name: Create AWS instances for {{ lab_user}} for use with Lab {{ lab_name }}
hosts: localhost
gather_facts: no
vars_files:
- aws_vars.yml
tasks:
- name: Provision AWS Tower Instances
ec2:
aws_access_key: "{{ec2_access_key}}"
aws_secret_key: "{{ec2_secret_key}}"
key_name: "{{ aws_key_name }}"
group: "{{ aws_sec_group }}"
instance_type: "{{ tower_inst_type }}"
image: "{{ tower_ami_id }}"
wait: yes
instance_tags:
Name: "tower-{{ lab_user }}-{{ item }}.{{ domain_name }}"
lab_name: "{{ lab_name }}"
lab_user: "{{ lab_user }}"
lab_role: "tower"
student_id: "{{ lab_user }}-{{ item }}"
vpc_subnet_id: "{{ aws_subnet_id }}"
zone: "{{ aws_az_1 }}"
assign_public_ip: yes
region: "{{ aws_region }}"
state: present
with_sequence: start={{ student_count_start }} end={{ student_count_end }}
register: instances_created
- debug:
var: instances_created
verbosity: 2
- name: Wait for ssh
wait_for:
port: 22
host: "{{ item.instances.0.public_ip }}"
timeout: 1000
with_items: "{{ instances_created.results }}"
ignore_errors: yes
- 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: tower_instances
student_id: "{{ item.instances.0.tags.student_id }}"
with_items: "{{ instances_created.results }}"
- debug:
var: groups
verbosity: 2
- name: Create AWS route53 entries for Tower instances
hosts: tower_instances
gather_facts: no
vars_files:
- aws_vars.yml
vars:
- ansible_user: ec2-user
tasks:
- debug:
var: hostvars
verbosity: 2
- name: Register route53 entries
local_action:
module: route53
command: create
aws_access_key: "{{ec2_access_key}}"
aws_secret_key: "{{ec2_secret_key}}"
zone: "{{ domain_name }}"
type: A
overwrite: True
ttl: 60
record: "{{ inventory_hostname }}"
value: "{{ public_ip }}"
wait: yes
- name: Wait for resolvable route53 hostname
local_action: command host {{ inventory_hostname }}
register: host_result
until: host_result.rc == 0
retries: 60
delay: 5
- import_playbook: tower_config.yml
when: tower_config is defined
...