/
update-config-runner.yml
418 lines (377 loc) · 13.7 KB
/
update-config-runner.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
---
- name: Set concurrent limit option
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*limit ='
line: ' limit = {{ gitlab_runner.concurrent_specific|default(0) }}'
state: present
insertafter: '^\s*name ='
backrefs: no
check_mode: no
notify: restart_gitlab_runner
- name: Set coordinator URL
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*url ='
line: ' url = {{ gitlab_runner_coordinator_url | to_json }}'
state: present
insertafter: '^\s*limit ='
backrefs: no
check_mode: no
notify: restart_gitlab_runner
- name: Set environment option
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*environment ='
line: ' environment = {{ gitlab_runner.env_vars|default([]) | to_json }}'
state: present
insertafter: '^\s*url ='
backrefs: no
check_mode: no
notify: restart_gitlab_runner
- name: Set pre_clone_script
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*pre_clone_script ='
line: ' pre_clone_script = {{ gitlab_runner.pre_clone_script | to_json }}'
state: present
insertafter: '^\s*url ='
backrefs: no
check_mode: no
notify: restart_gitlab_runner
when: gitlab_runner.pre_clone_script is defined
- name: Set runner executor option
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*executor ='
line: ' executor = {{ gitlab_runner.executor|default("shell") | to_json }}'
state: present
insertafter: '^\s*url ='
backrefs: no
check_mode: no
notify: restart_gitlab_runner
- name: Set runner executor section
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*\[runners\.{{ gitlab_runner.executor|default("shell") }}\]'
line: ' [runners.{{ gitlab_runner.executor|default("shell") }}]'
state: "{{ 'absent' if (gitlab_runner.executor|default('shell')) == 'shell' else 'present' }}"
insertafter: '^\s*executor ='
backrefs: no
check_mode: no
notify: restart_gitlab_runner
- name: Set output_limit option
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*output_limit ='
line: ' output_limit = {{ gitlab_runner.output_limit|default(4096) }}'
state: present
insertafter: '^\s*executor ='
backrefs: no
check_mode: no
notify: restart_gitlab_runner
#### [runners.docker] section ####
- name: Set runner docker image option
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*image ='
line: ' image = {{ gitlab_runner.docker_image|default("") | to_json }}'
state: "{{ 'present' if gitlab_runner.docker_image is defined else 'absent' }}"
insertafter: '^\s*\[runners\.docker\]'
backrefs: no
check_mode: no
notify: restart_gitlab_runner
- name: Set docker privileged option
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*privileged ='
line: ' privileged = {{ gitlab_runner.docker_privileged|default(false) | lower }}'
state: "{{ 'present' if gitlab_runner.docker_privileged is defined else 'absent' }}"
insertafter: '^\s*\[runners\.docker\]'
backrefs: no
check_mode: no
notify: restart_gitlab_runner
- name: Set docker volumes option
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*volumes ='
line: ' volumes = {{ gitlab_runner.docker_volumes|default([])|to_json }}'
state: "{{ 'present' if gitlab_runner.docker_volumes is defined else 'absent' }}"
insertafter: '^\s*executor ='
backrefs: no
check_mode: no
notify: restart_gitlab_runner
#### [runners.cache] section ####
- name: Set cache section
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*\[runners\.cache\]'
line: ' [runners.cache]'
state: present
insertafter: EOF
backrefs: no
check_mode: no
notify: restart_gitlab_runner
- name: Set cache s3 section
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*\[runners\.cache\.s3\]'
line: ' [runners.cache.s3]'
state: "{{ 'present' if gitlab_runner.cache_type == 's3' else 'absent' }}"
insertafter: '^\s*\[runners\.cache\]'
backrefs: no
check_mode: no
notify: restart_gitlab_runner
- name: Set cache gcs section
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*\[runners\.cache\.gcs\]'
line: ' [runners.cache.gcs]'
state: "{{ 'present' if gitlab_runner.cache_gcs_bucket_name is defined else 'absent' }}"
insertafter: '^\s*\[runners\.cache\]'
backrefs: no
check_mode: no
notify: restart_gitlab_runner
- name: Set cache type option
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*Type ='
line: ' Type = {{ gitlab_runner.cache_type|default("") | to_json }}'
state: "{{ 'present' if gitlab_runner.cache_type is defined else 'absent' }}"
insertafter: '^\s*\[runners\.cache\]'
backrefs: no
check_mode: no
notify: restart_gitlab_runner
- name: Set cache path option
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*Path ='
line: ' Path = {{ gitlab_runner.cache_path|default("") | to_json }}'
state: "{{ 'present' if gitlab_runner.cache_path is defined else 'absent' }}"
insertafter: '^\s*\[runners\.cache\]'
backrefs: no
check_mode: no
notify: restart_gitlab_runner
- name: Set cache shared option
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*Shared ='
line: ' Shared = {{ gitlab_runner.cache_shared|default("") | lower }}'
state: "{{ 'present' if gitlab_runner.cache_shared is defined else 'absent' }}"
insertafter: '^\s*\[runners\.cache\]'
backrefs: no
check_mode: no
notify: restart_gitlab_runner
#### [runners.cache.s3] section ####
- name: Set cache s3 server addresss
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*ServerAddress ='
line: ' ServerAddress = {{ gitlab_runner.cache_s3_server_address|default("") | to_json }}'
state: "{{ 'present' if gitlab_runner.cache_s3_server_address is defined else 'absent' }}"
insertafter: '^\s*\[runners\.cache\.s3\]'
backrefs: no
check_mode: no
notify: restart_gitlab_runner
- name: Set cache s3 access key
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*AccessKey ='
line: ' AccessKey = {{ gitlab_runner.cache_s3_access_key|default("") | to_json }}'
state: "{{ 'present' if gitlab_runner.cache_s3_access_key is defined else 'absent' }}"
insertafter: '^\s*\[runners\.cache\.s3\]'
backrefs: no
check_mode: no
notify: restart_gitlab_runner
- name: Set cache s3 secret key
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*SecretKey ='
line: ' SecretKey = {{ gitlab_runner.cache_s3_secret_key|default("") | to_json }}'
state: "{{ 'present' if gitlab_runner.cache_s3_secret_key is defined else 'absent' }}"
insertafter: '^\s*\[runners\.cache\.s3\]'
backrefs: no
check_mode: no
notify: restart_gitlab_runner
- name: Set cache s3 bucket name option
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*BucketName ='
line: ' BucketName = {{ gitlab_runner.cache_s3_bucket_name|default("") | to_json }}'
state: "{{ 'present' if gitlab_runner.cache_s3_bucket_name is defined else 'absent' }}"
insertafter: '^\s*\[runners\.cache\.s3\]'
backrefs: no
check_mode: no
notify: restart_gitlab_runner
when: gitlab_runner.cache_type == 's3'
- name: Set cache s3 bucket location option
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*BucketLocation ='
line: ' BucketLocation = {{ gitlab_runner.cache_s3_bucket_location|default("") | to_json }}'
state: "{{ 'present' if gitlab_runner.cache_s3_bucket_location is defined else 'absent' }}"
insertafter: '^\s*\[runners\.cache\.s3\]'
backrefs: no
check_mode: no
notify: restart_gitlab_runner
- name: Set cache s3 insecure option
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*Insecure ='
line: ' Insecure = {{ gitlab_runner.cache_s3_insecure|default("") | lower }}'
state: "{{ 'present' if gitlab_runner.cache_s3_insecure is defined else 'absent' }}"
insertafter: '^\s*\[runners\.cache\.s3\]'
backrefs: no
check_mode: no
notify: restart_gitlab_runner
#### [runners.cache.gcs] section ####
- name: Set cache gcs bucket name
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*BucketName ='
line: ' BucketName = {{ gitlab_runner.cache_gcs_bucket_name|default("") | to_json }}'
state: "{{ 'present' if gitlab_runner.cache_gcs_bucket_name is defined else 'absent' }}"
insertafter: '^\s*\[runners\.cache\.gcs\]'
backrefs: no
check_mode: no
notify: restart_gitlab_runner
when: gitlab_runner.cache_type == 'gcs'
- name: Set cache gcs credentials file
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*CredentialsFile ='
line: ' CredentialsFile = {{ gitlab_runner.cache_gcs_credentials_file|default("") | to_json }}'
state: "{{ 'present' if gitlab_runner.cache_gcs_credentials_file is defined else 'absent' }}"
insertafter: '^\s*\[runners\.cache\.gcs\]'
backrefs: no
check_mode: no
notify: restart_gitlab_runner
- name: Set cache gcs access id
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*AccessID ='
line: ' AccessID = {{ gitlab_runner.cache_gcs_access_id|default("") | to_json }}'
state: "{{ 'present' if gitlab_runner.cache_gcs_access_id is defined else 'absent' }}"
insertafter: '^\s*\[runners\.cache\.gcs\]'
backrefs: no
check_mode: no
notify: restart_gitlab_runner
- name: Set cache gcs private key
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*PrivateKey ='
line: ' PrivateKey = {{ gitlab_runner.cache_gcs_private_key|default("") | to_json }}'
state: "{{ 'present' if gitlab_runner.cache_gcs_private_key is defined else 'absent' }}"
insertafter: '^\s*\[runners\.cache\.gcs\]'
backrefs: no
check_mode: no
notify: restart_gitlab_runner
#### [runners.ssh] section #####
- name: Set ssh user option
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*user ='
line: ' user = {{ gitlab_runner.ssh_user|default("") | to_json }}'
state: "{{ 'present' if gitlab_runner.ssh_user is defined else 'absent' }}"
insertafter: '^\s*\[runners\.ssh\]'
backrefs: no
check_mode: no
notify: restart_gitlab_runner
- name: Set ssh host option
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*host ='
line: ' host = {{ gitlab_runner.ssh_host|default("") | to_json }}'
state: "{{ 'present' if gitlab_runner.ssh_host is defined else 'absent' }}"
insertafter: '^\s*\[runners\.ssh\]'
backrefs: no
check_mode: no
notify: restart_gitlab_runner
- name: Set ssh port option
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*port ='
line: ' port = {{ gitlab_runner.ssh_port|default("") | to_json }}'
state: "{{ 'present' if gitlab_runner.ssh_port is defined else 'absent' }}"
insertafter: '^\s*\[runners\.ssh\]'
backrefs: no
check_mode: no
notify: restart_gitlab_runner
- name: Set ssh password option
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*password ='
line: ' password = {{ gitlab_runner.ssh_password|default("") | to_json }}'
state: "{{ 'present' if gitlab_runner.ssh_password is defined else 'absent' }}"
insertafter: '^\s*\[runners\.ssh\]'
backrefs: no
check_mode: no
notify: restart_gitlab_runner
- name: Set ssh identity file option
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*identity_file ='
line: ' identity_file = {{ gitlab_runner.ssh_identity_file|default("") | to_json }}'
state: "{{ 'present' if gitlab_runner.ssh_identity_file is defined else 'absent' }}"
insertafter: '^\s*\[runners\.ssh\]'
backrefs: no
check_mode: no
notify: restart_gitlab_runner
- name: Set builds dir file option
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*builds_dir ='
line: ' builds_dir = {{ gitlab_runner.builds_dir|default("") | to_json }}'
state: "{{ 'present' if gitlab_runner.builds_dir is defined else 'absent' }}"
insertafter: '^\s*executor ='
backrefs: no
check_mode: no
notify: restart_gitlab_runner
- name: Set cache dir file option
lineinfile:
dest: "{{ temp_runner_config.path }}"
regexp: '^\s*cache_dir ='
line: ' cache_dir = {{ gitlab_runner.cache_dir|default("") | to_json }}'
state: "{{ 'present' if gitlab_runner.cache_dir is defined else 'absent' }}"
insertafter: '^\s*executor ='
backrefs: no
check_mode: no
notify: restart_gitlab_runner
- name: Ensure directory permissions
file:
dest: "{{ item }}"
state: directory
owner: gitlab-runner
group: gitlab-runner
mode: 0770
modification_time: preserve
access_time: preserve
recurse: yes
loop:
- "{{ gitlab_runner.builds_dir | default(\"\") }}"
- "{{ gitlab_runner.cache_dir | default(\"\") }}"
when: item|length
- name: Ensure directory access test
command: "/usr/bin/test -r {{ item }}"
loop:
- "{{ gitlab_runner.builds_dir | default(\"\") }}"
- "{{ gitlab_runner.cache_dir | default(\"\") }}"
when: item|length
changed_when: False
become: yes
become_user: gitlab-runner
register: ensure_directory_access
ignore_errors: true
- name: Ensure directory access fail on error
fail:
msg: "Error: user gitlab-runner failed to test access to {{ item.item }}. Check parent folder(s) permissions"
loop: "{{ ensure_directory_access.results }}"
when:
- item.rc is defined and item.rc != 0
- include: section-config-runner.yml
loop: "{{ gitlab_runner.extra_configs|list }}"
loop_control:
loop_var: section
when:
- gitlab_runner.extra_configs is defined
- gitlab_runner.extra_configs|list|length > 0