-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplaybook.yaml
280 lines (243 loc) · 8.71 KB
/
playbook.yaml
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
---
- hosts: all
gather_facts: true
vars:
home_dir: '/home/{{ ssh_user }}'
node_type: '{{ vm_type }}'
zap_version: 'v2.11.0'
zap_file: 'ZAP_2.11.0'
upgrade_python: true
python_version: 'Python-3.9.8'
python_version_no: '3.9.8'
remote_user: '{{ ssh_user }}'
environment:
PATH: '{{ ansible_env.PATH }}:{{ home_dir }}/.local/bin'
tasks:
# ###########################################################################################
# Install Required Packages
# ###########################################################################################
- name: Remove python3 package.
apt:
name: python3
state: absent
become: yes
when: upgrade_python
- name: Install build essentials.
apt:
pkg:
- build-essential
- zlib1g-dev
- libncurses5-dev
- libgdbm-dev
- libnss3-dev
- libssl-dev
- libreadline-dev
- libffi-dev
- libsqlite3-dev
- wget
- libbz2-dev
- acl
- default-jre
- nginx
state: present
become: yes
- name: Download python3.9 From https://www.python.org/ftp/python/{{ python_version_no }}/{{ python_version }}.tgz.
get_url:
url: 'https://www.python.org/ftp/python/{{ python_version_no }}/{{ python_version }}.tgz'
dest: '{{ home_dir }}/'
mode: '0777'
when: upgrade_python
- name: unzip {{ python_version }}.tgz.
ansible.builtin.unarchive:
src: '{{ home_dir }}/{{ python_version }}.tgz'
dest: '{{ home_dir }}/'
remote_src: yes
when: upgrade_python
- name: run configure.
command: ./configure
args:
chdir: '{{ home_dir }}/{{ python_version }}/'
when: upgrade_python
- name: install {{ python_version }}.
command: make install
args:
chdir: '{{ home_dir }}/{{ python_version }}/'
become: yes
when: upgrade_python
# apt update
- name: apt update.
apt:
update_cache: yes
become: yes
when: upgrade_python
# install required apt packages and dependencies
- name: Install required apt packages and dependencies.
apt:
pkg:
- python3-pip
force_apt_get: true
become: yes
# Download ZAP_2.11.0
- name: Download ZAP_2.11.0
ansible.builtin.command: 'wget https://github.com/zaproxy/zaproxy/releases/download/{{ zap_version }}/{{ zap_file }}_Linux.tar.gz'
# Unarchive {{ zap_file }}.tar.gz
- name: Unarchive {{ zap_file }}.tar.gz
ansible.builtin.unarchive:
src: '{{ home_dir }}/{{ zap_file }}_Linux.tar.gz'
dest: '{{ home_dir }}'
remote_src: yes
# Install required packages for script file
- name: Installing ray, ZAPv2, tldextract, python-dotenv
pip:
name:
- ray
- python-owasp-zap-v2.4
- tldextract
- python-dotenv
extra_args: -U
# ###########################################################################################
# Copy ray file, scan file, zedzap service file
# ###########################################################################################
- name: copy ray file
ansible.builtin.copy:
src: '{{ ray_file }}'
dest: '{{ home_dir }}/{{ ray_file }}'
mode: 0777
- name: copy scan file
ansible.builtin.copy:
src: '{{ scan_file }}'
dest: '{{ home_dir }}/{{ scan_file }}'
mode: 0777
- name: copy .env file
ansible.builtin.copy:
src: .env
dest: '{{ home_dir }}/.env'
mode: 0777
- name: copy zedzap service file
ansible.builtin.copy:
src: '{{ service_file }}'
dest: '/etc/systemd/system/zedzap.service'
mode: 0777
become: yes
# ###########################################################################################
# Enable zedzap service
# ###########################################################################################
- name: change service file zap folder path
ansible.builtin.replace:
path: '/etc/systemd/system/zedzap.service'
regexp: 'ZAP_PATH'
replace: '{{ home_dir }}/{{ zap_file }}'
become: yes
- name: enable {{ service_file }}
ansible.builtin.systemd:
name: zedzap
state: started
enabled: yes
become: yes
# ###########################################################################################
# Add nginx server
# ###########################################################################################
- name: openssl private key
openssl_privatekey:
path: /etc/nginx/server-cert.key
size: 2048
become: yes
when: node_type == "head"
- name: openssl csr
openssl_csr:
path: /etc/nginx/server-cert.csr
privatekey_path: /etc/nginx/server-cert.key
become: yes
when: node_type == "head"
- name: openssl certificate
openssl_certificate:
provider: selfsigned
path: /etc/nginx/server-cert.crt
privatekey_path: /etc/nginx/server-cert.key
csr_path: /etc/nginx/server-cert.csr
become: yes
when: node_type == "head"
# create configuration file for reverse proxying to localhost:8265
- name: copy ray nginx config file
ansible.builtin.copy:
src: misc/ray
dest: /etc/nginx/sites-available/ray
mode: 0644
become: yes
when: node_type == "head"
- name: activate link between sites-available/ray sites-enabled
file:
src: /etc/nginx/sites-available/ray
dest: /etc/nginx/sites-enabled/ray
state: link
become: yes
when: node_type == "head"
- name: reload nginx
ansible.builtin.systemd:
name: nginx
state: reloaded
daemon_reload: yes
enabled: True
become: yes
when: node_type == "head"
# ###########################################################################################
# Run Ray as a service on all nodes
# ###########################################################################################
# copy ray service file to remote
#- name: copy ray service file
# ansible.builtin.copy:
# src: misc/ray.service
# dest: '/etc/systemd/system/ray.service'
# mode: 0777
# become: yes
# change command of service file if head node
#- name: change command to 'ray start --head' if head node
# ansible.builtin.replace:
# path: '/etc/systemd/system/ray.service'
# regexp: 'COMMAND'
# replace: 'ray start --head'
# become: yes
# when: node_type == "head"
# change command of service file if worker node
#- name: change command to 'ray start --address={{ head_ip }}:6379 --redis-password=5241590000000000' if worker node
# ansible.builtin.replace:
# path: '/etc/systemd/system/ray.service'
# regexp: 'COMMAND'
# replace: 'ray start --address={{ head_ip }}:{{ ray_port }} --redis-password={{ ray_passwd }}'
# become: yes
# when: node_type == "worker"
# enable service
#- name: enable ray service
# ansible.builtin.systemd:
# name: ray
# state: started
# enabled: yes
# become: yes
# ###########################################################################################
# Run Ray on head node
# ###########################################################################################
- name: Run Ray on head node | check for head node
shell:
cmd: 'ray start --head --port={{ ray_port }} --include-dashboard=true'
chdir: '{{ home_dir }}'
register: head_ray
when: node_type == "head"
- name: head ray
debug:
var: head_ray.stdout_lines
when: node_type == "head"
# ###########################################################################################
# Connect workers to head node Ray
# ###########################################################################################
- name: Connect worker to head node Ray | check for worker node
shell:
cmd: "ray start --address='{{ head_ip }}:6379' --redis-password='5241590000000000'"
chdir: '{{ home_dir }}'
register: worker_ray
when: node_type == "worker"
- name: worker ray
debug:
var: worker_ray.stdout_lines
when: node_type == "worker"
- name: setup finished
command: echo "setup finished"