-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlaunch-workers.yml
86 lines (77 loc) · 2.19 KB
/
launch-workers.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
- hosts: localhost
connection: local
gather_facts: False
vars_files:
- vars.yml
tasks:
- name: create digital ocean workers
digital_ocean_droplet:
state: present
name: "locust-{{ item.0 }}-{{ item.1 }}"
private_networking: no
size: "{{ locust_node_size }}"
image_id: ubuntu-20-04-x64
region: "{{ item.0 }}"
ssh_keys: "{{ locust_ssh_keys }}"
unique_name: yes
tags:
- locust
loop: "{{ locust_regions|product(range(0,locust_nodes_per_region,1))|list }}"
register: do
- debug: var=do
- name: tag droplets
digital_ocean_tag:
name: locust
resource_id: "{{ item.data.droplet.id }}"
state: present
when: item.data is defined
with_items: "{{ do.results }}"
- name: add digital ocean workers to inventory
add_host:
name: "{{ item.data.ip_address }}"
groups: do
ansible_ssh_extra_args: '-o StrictHostKeyChecking=no'
ansible_python_interpreter: /usr/bin/python3
when: item.data is defined
with_items: "{{ do.results }}"
- hosts: do
remote_user: root
gather_facts: False
vars_files:
- vars.yml
tasks:
- name: Wait for hosts to become reachable
wait_for_connection:
- name: install ansible prereqs
script: ansible_prereqs_3.sh creates=/root/.ansible_prereqs_installed
register: ans_preq
changed_when: "'CHANGE' in ans_preq.stdout"
- name: Install pip
apt:
pkg: ['python3-pip']
state: present
- name: Install locust
pip:
name: locust
state: present
- name: Copy locust file
copy:
src: locust.py
dest: /root/locust.py
register: locust_file
- name: Copy service file
template:
src: locust.service
dest: /etc/systemd/system/locust.service
register: service_template
- name: Systemd restart
systemd:
daemon_reload: yes
name: locust
state: restarted
when: locust_file is changed or service_template is changed
- name: Ensure locust is running
systemd:
name: locust
state: started
enabled: yes