-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaybook-start.yml
98 lines (88 loc) · 3 KB
/
playbook-start.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
#start ec2 instance
- name: Start sandbox instances
hosts: localhost
connection: local
gather_facts: False
tasks:
# todo: нужно выделить в отдельную роль создание инстанса ?
- name: Create an EC2 key
ec2_key:
name: "{{ key_name }}"
region: "{{ region }}"
force: false
register: ec2_key
- name: Save EC2 private key
copy:
content: "{{ ec2_key.key.private_key }}"
dest: "{{ ansible_ssh_private_key_file }}"
mode: 0600
when: ec2_key.changed
- name: Launch instance
ec2:
key_name: "{{ key_name }}"
group: "{{ security_group }}"
instance_type: "{{ instance_type }}"
image: "{{ image }}"
wait: true
region: "{{ region }}"
vpc_subnet_id: "{{ vpc_subnet_id }}"
exact_count: 1
count_tag:
Playbook: "{{ playbook_tag }}"
Suite: "{{ suite_tag }}"
Build: "{{ build_tag }}"
instance_tags:
Name: "{{ playbook_tag }}-{{ suite_tag }}-{{ build_tag }}" # just a human-readble name
Playbook: "{{ playbook_tag }}" # same for all instances created with this playbook
# add these by --extra-vars "build_tag=build123 suite_tag=ignite2"
Suite: "{{ suite_tag }}" # unique for the whole test-suite, key to stop all suite instances
Build: "{{ build_tag }}" # unique for each build, key to start and stop 1 instance,
register: ec2
- name: Add new instance to host group
add_host:
hostname: "{% if use_public_ip == 'true' %}{{ item.public_ip }}{% else %}{{ item.private_ip }}{% endif %}"
groupname: launched
with_items: "{{ ec2.instances }}"
- name: Save instance address
local_action:
module: lineinfile
dest: "./hosts/host-{{ suite_tag }}-{{ build_tag }}"
line: "{% if use_public_ip == 'true' %}{{ item.public_ip }}{% else %}{{ item.private_ip }}{% endif %}"
create: yes
with_items: "{{ ec2.instances }}"
- name: Wait for SSH to come up
wait_for:
host: "{% if use_public_ip == 'true' %}{{ item.public_ip }}{% else %}{{ item.private_ip }}{% endif %}"
port: 22
delay: 5
timeout: 320
state: started
with_items: "{{ ec2.instances }}"
- name: Configure instance(s) 1
hosts: launched
remote_user: ubuntu
become: True
gather_facts: False
pre_tasks:
- name: Install python
raw: test -e /usr/bin/python || (apt -y upgrade && apt -y update && apt install -y python-minimal)
register: task_result
until: task_result.rc == 0
ignore_errors: yes
retries: 5
delay: 1
tasks:
- name: Install docker
apt:
name: "{{ item }}"
update_cache: yes
cache_valid_time: 86400 #One day
with_items:
- docker.io
- name: Configure instance(s) 2
hosts: all
remote_user: ubuntu
become: True
gather_facts: False
roles:
- selenoid