-
Notifications
You must be signed in to change notification settings - Fork 281
/
Copy pathconfig-runners-windows.yml
63 lines (54 loc) · 2.23 KB
/
config-runners-windows.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
---
- name: (Windows) Get existing config.toml
ansible.builtin.slurp:
src: "{{ gitlab_runner_config_file }}"
register: runner_config_file
- name: (Windows) Get pre-existing global config
ansible.builtin.set_fact:
runner_global_config: "{{ (runner_config_file['content'] | b64decode).split('[[runners]]')[0] }}"
- name: (Windows) Get pre-existing runner configs
ansible.builtin.set_fact:
runner_configs: "{{ (runner_config_file['content'] | b64decode).split('[[runners]]')[1:] }}"
- name: (Windows) Create temporary directory
ansible.windows.win_tempfile:
state: directory
suffix: gitlab-runner-config
register: temp_runner_config_dir
check_mode: false
changed_when: false
- name: (Windows) Write config section for each runner
vars:
conf_name_prefix: "conf[{{ (runner_config_index | int) + 1 }}/{{ runner_configs | length }}]:"
ansible.builtin.include_tasks: config-runner-windows.yml
loop: "{{ runner_configs }}"
loop_control:
index_var: runner_config_index
loop_var: runner_config
- name: (Windows) Assemble new config.toml
when: not ansible_check_mode
block:
- name: (Windows) Create temporary file config.toml
ansible.windows.win_tempfile:
state: file
suffix: temp
register: config_toml_temp
- name: (Windows) Write global config to file
community.windows.win_lineinfile:
insertbefore: BOF
path: "{{ config_toml_temp.path }}"
line: "{{ runner_global_config }}"
- name: (Windows) Create temporary file runners-config.toml
ansible.windows.win_tempfile:
state: file
suffix: temp
register: runners_config_toml_temp
- name: (Windows) Assemble runners files in config dir
ansible.windows.win_shell: dir -rec | gc | out-file "{{ runners_config_toml_temp.path }}"
args:
chdir: "{{ temp_runner_config_dir.path }}"
- name: (Windows) Assemble new config.toml
ansible.windows.win_shell: gc "{{ config_toml_temp.path }}","{{ runners_config_toml_temp.path }}" | Set-Content "{{ gitlab_runner_config_file }}"
- name: (Windows) Verify config
ansible.windows.win_command: "{{ gitlab_runner_executable }} verify"
args:
chdir: "{{ gitlab_runner_config_file_location }}"