-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsingle-runner.yml
55 lines (52 loc) · 2.16 KB
/
single-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
---
- name: Determine configuration for the runner
ansible.builtin.set_fact:
runner_target: "{{ item.group | default(item.project) }}"
runner_target_type: "{{ item.group is defined | ternary('group', 'project') }}"
- name: Test
ansible.builtin.set_fact:
runner_filename: "{{ runner_target_type }}-{{ runner_target.split('/') | join('__') }}.toml"
- name: Test2
ansible.builtin.set_fact:
runner_config_full_path: "{{ gitlab_runner_config_directory }}/conf.d/{{ runner_filename }}"
- name: Ensure the runner is registered and retrieve its token
block:
- name: Ensure the runner is registered
community.general.gitlab_runner:
access_level: not_protected
active: true
locked: false
run_untagged: true
state: present
api_url: "{{ item.gitlab_url }}"
api_token: "{{ gitlab_runner_api_token }}"
description: "{{ inventory_hostname }}"
group: "{{ item.group is defined | ternary(runner_target, omit) }}"
project: "{{ item.project is defined | ternary(runner_target, omit) }}"
tag_list: "{{ item.tags | default([]) + [inventory_hostname] }}"
registration_token: "{{ item.registration_token }}"
validate_certs: false
register: runner_register
- name: Define runner token variable
when: runner_register.changed and runner_register.runner.token is defined
ansible.builtin.set_fact:
runner_token: "{{ runner_register.runner.token }}"
- name: Retrieve runner token from toml fragment
when: not runner_register.changed or runner_register.runner.token is not defined
block:
- name: Grep token from runner toml fragment
ansible.builtin.shell: |
set -o pipefail
grep token {{ runner_config_full_path }} | cut -d'"' -f2
changed_when: false
register: runner_token_extraction
- name: Define runner token variable
ansible.builtin.set_fact:
runner_token: "{{ runner_token_extraction.stdout }}"
- name: Generate runner configuration file
ansible.builtin.template:
src: runner.toml.j2
dest: "{{ runner_config_full_path }}"
owner: "{{ ansible_user_id }}"
group: docker
mode: 0644