-
Notifications
You must be signed in to change notification settings - Fork 0
/
rasa_x_playbook.yml
439 lines (375 loc) · 13.9 KB
/
rasa_x_playbook.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
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
---
- name: "Install Rasa X"
hosts: "localhost"
become: True
vars:
RASA_HOME: "{{ lookup('env','RASA_HOME')|default('/etc/rasa', true) }}"
VAR_RASA_X_VERSION: 0.42.0
VAR_RASA_VERSION: 2.8.0
VAR_RASA_X_DEMO_VERSION: 0.42.0
VAR_RASA_TELEMETRY_ENABLED: "{{ lookup('env', 'RASA_TELEMETRY_ENABLED') | default((rasa_x_license_file.stat.exists | ternary('false', 'true')), True) }}"
roles:
- role: geerlingguy.docker
when: ansible_testing is not defined
tasks:
- name: Status of Rasa Enterprise license file
stat:
path: rasa-x-ee-license.yml
register: rasa_x_license_file
- name: Check if a license exists
debug:
msg: "There is no Rasa Enterprise license file. We will install Rasa X (Community Edition)."
when: rasa_x_license_file.stat.exists == False
- name: Load configuration file of the customer (includes e.g. the license)
include_vars:
file: rasa-x-ee-license.yml
name: rasax
when: rasa_x_license_file.stat.exists
- name: Telemetry status
debug:
msg: "Telemetry, RASA_TELEMETRY_ENABLED={{ VAR_RASA_TELEMETRY_ENABLED }}"
- name: Create Rasa X root directory
file:
path: "{{ RASA_HOME }}"
state: directory
- name: Create Rasa X log directory
file:
path: "{{ RASA_HOME }}/logs"
state: directory
mode: 0770
group: root
- name: Create Rasa X scripts directory
file:
path: "{{ RASA_HOME }}/scripts"
state: directory
- name: Create the directory for the database persistence
file:
path: "{{ RASA_HOME }}/db"
state: directory
mode: 0750
owner: "1001"
group: root
- name: Create the directory to store the models
file:
path: "{{ RASA_HOME }}/models"
state: directory
mode: 0770
group: root
- name: Create the directory to store the rasa global configuration
file:
path: "{{ RASA_HOME }}/.config"
state: directory
mode: 0770
group: root
- name: Create the directory for the authentication
file:
path: "{{ RASA_HOME }}/auth"
state: directory
mode: 0770
group: root
- name: Create the directory for the credentials
file:
path: "{{ RASA_HOME }}/credentials"
state: directory
mode: 0770
group: root
- name: Create the directory to store the certificate files
file:
path: "{{ RASA_HOME }}/certs"
state: directory
mode: 0770
group: root
# - name: Create the directory for the nginx config files
# file:
# path: "{{ RASA_HOME }}/nginx-config-files"
# state: directory
# mode: 0770
# group: root
# when: ci is not defined
# - name: Download rasax.nginx.template
# get_url:
# url: https://storage.googleapis.com/rasa-x-releases/{{ VAR_RASA_X_VERSION }}/nginx-config-files/rasax.nginx.template
# dest: "{{ RASA_HOME }}/nginx-config-files"
# mode: 0770
# group: root
# when: ci is not defined
# - name: Download nginx.conf
# get_url:
# url: https://storage.googleapis.com/rasa-x-releases/{{ VAR_RASA_X_VERSION }}/nginx-config-files/nginx.conf
# dest: "{{ RASA_HOME }}/nginx-config-files"
# mode: 0770
# group: root
# when: ci is not defined
# - name: Download nginx ssl.conf
# get_url:
# url: https://storage.googleapis.com/rasa-x-releases/{{ VAR_RASA_X_VERSION }}/nginx-config-files/ssl.conf.template
# dest: "{{ RASA_HOME }}/nginx-config-files"
# mode: 0770
# group: root
# when: ci is not defined
- name: stat user credentials
stat:
path: "{{ playbook_dir }}/credentials"
register: user_credentials_dir
- name: backwards compatible credentials
command: mv credentials {{ RASA_HOME }}/credentials
# Don't move the credentials directory to itself
when: user_credentials_dir.stat.exists and playbook_dir != RASA_HOME
- name: Status of Rasa X credentials folder
stat:
path: "{{ RASA_HOME }}/credentials"
register: rasa_x_credentials
- name: Status of Rasa X env file
stat:
path: "{{ RASA_HOME }}/.env"
register: rasa_x_env
- name: Ensure we do not overwrite the env if we do not have the credentials
assert:
that:
- "not (rasa_x_env.stat.exists and not rasa_x_credentials.stat.exists)"
msg: "There is a Rasa X env ({{ RASA_HOME }}/.env) but no folder containing the original credentials. To avoid overwriting the existing credentials in .env we ABORT. "
- name: Create the environment for the docker compose runner
copy:
content: |
PASSWORD_SALT={{ lookup('password', '{{ RASA_HOME }}/credentials/password_salt length=15') }}
RASA_X_VERSION={{ VAR_RASA_X_VERSION }}
RASA_VERSION={{ VAR_RASA_VERSION }}
RASA_X_DEMO_VERSION={{ VAR_RASA_X_DEMO_VERSION }}
RASA_TELEMETRY_ENABLED={{ VAR_RASA_TELEMETRY_ENABLED }}
dest: "{{ RASA_HOME }}/.env"
when: rasa_x_env.stat.exists == False
- name: Update Rasa X version in `.env` file if `.env` file already existed
lineinfile:
path: "{{ RASA_HOME }}/.env"
regexp: "RASA_X_VERSION=.*"
line: "RASA_X_VERSION={{ VAR_RASA_X_VERSION }}"
when: rasa_x_env.stat.exists
- name: Check if Rasa Open Source telemetry has been configured via `.env`
shell: "grep -c RASA_TELEMETRY_ENABLED= {{ RASA_HOME }}/.env || true"
register: telemetry_config_check
when: rasa_x_env.stat.exists
- name: Create Rasa Open Source telemetry config if it wasn't present (Enterprise only)
# If this is an Enterprise deployment that is upgrading, then there will be no OSS telemetry
# config in the .env file. Disable OSS telemetry by default, unless the user has explicitly
# enabled it. For non-Enterprise deployments, don't write any config, and use the default set
# in docker-compose.yml instead.
lineinfile:
path: "{{ RASA_HOME }}/.env"
line: "RASA_TELEMETRY_ENABLED=false"
when: (rasa_x_env.stat.exists and telemetry_config_check.stdout == "0" and rasa_x_license_file.stat.exists)
- name: Update Rasa version in `.env` file if `.env` file already existed
lineinfile:
path: "{{ RASA_HOME }}/.env"
regexp: "RASA_VERSION=.*"
line: "RASA_VERSION={{ VAR_RASA_VERSION }}"
when: rasa_x_env.stat.exists
- name: Update RASA X demo version in `.env` file if `.env` file already existed
lineinfile:
path: "{{ RASA_HOME }}/.env"
regexp: "RASA_X_DEMO_VERSION=.*"
line: "RASA_X_DEMO_VERSION={{ VAR_RASA_X_DEMO_VERSION }}"
when: rasa_x_env.stat.exists
- name: Read the the content of the .env file
shell: cat "{{ RASA_HOME }}/.env"
register: env_content
- name: Status of deployment environments file
stat:
path: "{{ RASA_HOME }}/environments.yml"
register: environments_file
- name: Create deployment environments file if not present
copy:
content: |
rasa:
production:
url: ${RASA_PRODUCTION_HOST}
token: ${RASA_TOKEN}
worker:
url: ${RASA_WORKER_HOST}
token: ${RASA_TOKEN}
dest: "{{ RASA_HOME }}/environments.yml"
mode: 0770
group: root
when: environments_file.stat.exists == False
- name: Status of Redis credentials file
stat:
path: "{{ RASA_HOME }}/credentials/redis"
register: redis_credentials
- name: Create Redis credentials if not present
lineinfile:
path: "{{ RASA_HOME }}/.env"
line: "REDIS_PASSWORD={{ lookup('password', '{{ RASA_HOME }}/credentials/redis length=15') }}"
when: redis_credentials.stat.exists == False
- name: Status of RabbitMQ credentials file
stat:
path: "{{ RASA_HOME }}/credentials/rabbit"
register: rabbitmq_credentials
- name: Create RabbitMQ credentials if not present
lineinfile:
path: "{{ RASA_HOME }}/.env"
line: "RABBITMQ_PASSWORD={{ lookup('password', '{{ RASA_HOME }}/credentials/rabbit chars=ascii_letters,digits length=15') }}"
when: rabbitmq_credentials.stat.exists == False
- name: Status of RASA_X_TOKEN credentials file
stat:
path: "{{ RASA_HOME }}/credentials/rasa_x_token"
register: rasa_x_token
- name: Create RASA_X_TOKEN credentials if not present
lineinfile:
path: "{{ RASA_HOME }}/.env"
line: "RASA_X_TOKEN={{ lookup('password', '{{ RASA_HOME }}/credentials/rasa_x_token chars=ascii_letters,digits length=15') }}"
when: rasa_x_token.stat.exists == False
- name: Status of JWT_SECRET credentials file
stat:
path: "{{ RASA_HOME }}/credentials/jwt_secret"
register: jwt_secret
- name: Create JWT_SECRET credentials if not present
lineinfile:
path: "{{ RASA_HOME }}/.env"
line: "JWT_SECRET={{ lookup('password', '{{ RASA_HOME }}/credentials/jwt_secret chars=ascii_letters,digits length=25') }}"
when: jwt_secret.stat.exists == False
- name: Status of RASA_TOKEN credentials file
stat:
path: "{{ RASA_HOME }}/credentials/rasa_token"
register: rasa_token
- name: Create RASA_TOKEN if not present
lineinfile:
path: "{{ RASA_HOME }}/.env"
line: "RASA_TOKEN={{ lookup('password', '{{ RASA_HOME }}/credentials/rasa_token chars=ascii_letters,digits length=15') }}"
when: rasa_token.stat.exists == False
- name: Status of db password credentials file
stat:
path: "{{ RASA_HOME }}/credentials/db"
register: db_password
- name: Create DB_PASSWORD if not present
lineinfile:
path: "{{ RASA_HOME }}/.env"
line: "DB_PASSWORD={{ lookup('password', '{{ RASA_HOME }}/credentials/db length=15 chars=ascii_letters,digits') }}"
when: db_password.stat.exists == False
- name: Status of channel credentials file
stat:
path: "{{ RASA_HOME }}/credentials.yml"
register: credentials_file
- name: Create the environment for the docker compose runner
copy:
content: |
rasa:
url: ${RASA_X_HOST}/api
dest: "{{ RASA_HOME }}/credentials.yml"
mode: 0770
group: root
when: credentials_file.stat.exists == False
- name: Status of the Rasa endpoint configuration file
stat:
path: "{{ RASA_HOME }}/endpoints.yml"
register: stack_endpoints_file
- name: Create the endpoints configuration file for Rasa
copy:
content: |
models:
url: ${RASA_MODEL_SERVER}
token: ${RASA_X_TOKEN}
wait_time_between_pulls: ${RASA_MODEL_PULL_INTERVAL}
tracker_store:
type: sql
dialect: "postgresql"
url: ${DB_HOST}
port: ${DB_PORT}
username: ${DB_USER}
password: ${DB_PASSWORD}
db: ${DB_DATABASE}
login_db: ${DB_LOGIN_DB}
lock_store:
type: "redis"
url: ${REDIS_HOST}
port: ${REDIS_PORT}
password: ${REDIS_PASSWORD}
db: ${REDIS_DB}
cache:
type: "redis"
url: ${REDIS_HOST}
port: ${REDIS_PORT}
password: ${REDIS_PASSWORD}
db: ${REDIS_CACHE_DB}
key_prefix: "rasax_cache"
event_broker:
type: "pika"
url: ${RABBITMQ_HOST}
username: ${RABBITMQ_USERNAME}
password: ${RABBITMQ_PASSWORD}
queues:
- ${RABBITMQ_QUEUE}
action_endpoint:
url: ${RASA_USER_APP}/webhook
token: ""
dest: "{{ RASA_HOME }}/endpoints.yml"
mode: 0770
group: root
when: stack_endpoints_file.stat.exists == False
# - name: Retrieve docker compose to run Rasa Enterprise
# get_url:
# url: https://storage.googleapis.com/rasa-x-releases/{{ VAR_RASA_X_VERSION }}/docker-compose.ee.yml
# dest: "{{ RASA_HOME }}/docker-compose.yml"
# mode: 0766
# force: yes
# when: (rasa_x_license_file.stat.exists and ansible_testing is not defined)
# - name: Retrieve docker compose to run Rasa X (Community Edition)
# get_url:
# url: https://storage.googleapis.com/rasa-x-releases/{{ VAR_RASA_X_VERSION }}/docker-compose.ce.yml
# dest: "{{ RASA_HOME }}/docker-compose.yml"
# mode: 0766
# force: yes
# when: (rasa_x_license_file.stat.exists == False and ansible_testing is not defined)
- name: Retrieve docker compose to run Rasa X (Community Edition)
copy:
src: docker-compose.yml
dest: "{{ RASA_HOME }}/docker-compose.yml"
mode: 0766
when: (rasa_x_license_file.stat.exists == False and ansible_testing is not defined)
- name: Retrieve docker compose override to run Rasa X (Community Edition)
copy:
src: docker-compose.override.yml
dest: "{{ RASA_HOME }}/docker-compose.override.yml"
mode: 0766
when: (rasa_x_license_file.stat.exists == False and ansible_testing is not defined)
- name: Retrieve the Rasa X commands file
get_url:
url: https://storage.googleapis.com/rasa-x-releases/{{ VAR_RASA_X_VERSION }}/rasa_x_commands.py
dest: "{{ RASA_HOME }}/rasa_x_commands.py"
mode: 0766
force: yes
when: ansible_testing is not defined
- name: Dump gcr license to separate file
copy:
content: "{{rasax.docker_registry_license | from_json | to_nice_json}}"
dest: "{{ RASA_HOME }}/gcr-auth.json"
when: rasa_x_license_file.stat.exists
- name: Log in to google cloud registry (gcr)
shell: "docker login -u _json_key -p {{rasax.docker_registry_license|quote}} https://gcr.io"
when: rasa_x_license_file.stat.exists
- name: Copy rasa-x-custom
copy:
src: rasa-x-custom
dest: "{{ RASA_HOME }}"
owner: 1001
group: root
when: ci is not defined
- name: Copy app (actions server)
copy:
src: app
dest: "{{ RASA_HOME }}"
owner: root
group: root
when: ci is not defined
- name: Copy git folder
copy:
src: git
dest: "{{ RASA_HOME }}"
owner: 1001
group: root
when: ci is not defined
- name: Copy nginx folder
copy:
src: nginx
dest: "{{ RASA_HOME }}"
owner: 1001
group: root
when: ci is not defined