|
23 | 23 | generate_ssh_key: '{{ gitlab_runner__ssh_generate | bool }}' |
24 | 24 | ssh_key_bits: '{{ gitlab_runner__ssh_generate_bits }}' |
25 | 25 |
|
| 26 | +- name: Allow Docker access for gitlab-runner user |
| 27 | + user: |
| 28 | + name: '{{ gitlab_runner__user }}' |
| 29 | + groups: 'docker' |
| 30 | + append: True |
| 31 | + when: (ansible_local|d() and ansible_local.docker|d() and |
| 32 | + (ansible_local.docker.installed|d()) | bool) |
| 33 | + |
26 | 34 | - name: Copy custom files to GitLab Runner host |
27 | 35 | copy: |
28 | 36 | src: '{{ item.src | d(omit) }}' |
|
45 | 53 | name: '{{ item }}' |
46 | 54 | state: 'present' |
47 | 55 | install_recommends: False |
| 56 | + update_cache: True |
| 57 | + cache_valid_time: '{{ ansible_local.core.cache_valid_time |
| 58 | + if (ansible_local|d() and ansible_local.core|d() and |
| 59 | + ansible_local.core.cache_valid_time|d()) |
| 60 | + else "86400" }}' |
48 | 61 | with_items: [ 'apt-transport-https', 'openssl', 'ca-certificates' ] |
49 | 62 |
|
50 | 63 | - name: Add gitlab-runner APT key |
|
79 | 92 | register: gitlab_runner__register_api |
80 | 93 | when: gitlab_runner__api_url|d() and gitlab_runner__api_url |
81 | 94 | failed_when: False |
| 95 | + no_log: True |
82 | 96 |
|
83 | 97 | - name: Register new GitLab Runners |
84 | 98 | uri: |
85 | 99 | url: '{{ (item.api_url | d(gitlab_runner__api_url)) + "/api/v1/runners/register.json" }}' |
86 | 100 | method: 'POST' |
87 | | - body: 'token={{ item.token | d(gitlab_runner__token) }}&description={{ item.name | urlencode }}&tag_list={{ ((item.tags|d([]) + gitlab_runner__default_tags + gitlab_runner__tags + gitlab_runner__group_tags + gitlab_runner__host_tags) | unique | join(",")) | urlencode }}&run_untagged={{ gitlab_runner__run_untagged }}' |
| 101 | + body: 'token={{ item.token | d(gitlab_runner__token) }}&description={{ item.name | urlencode }}&tag_list={{ ((item.tags|d([]) + (gitlab_runner__shell_tags if (item.executor == "shell") else []) + gitlab_runner__combined_tags) | unique | join(",")) | urlencode }}&run_untagged={{ item.run_untagged | d(gitlab_runner__run_untagged) }}' |
88 | 102 | status_code: '200,201' |
89 | 103 | register: gitlab_runner__register_new_instances |
90 | 104 | with_flattened: |
|
95 | 109 | when: (gitlab_runner__register_api.status|d() and gitlab_runner__register_api.status == 200 and |
96 | 110 | (item.token | d() or gitlab_runner__token) and item.name and |
97 | 111 | (item.state is undefined or item.state != 'absent') and |
98 | | - (ansible_local|d(True) and |
99 | | - (ansible_local.gitlab_runner is undefined or |
100 | | - item.name not in ansible_local.gitlab_runner.instances)) and |
101 | | - (gitlab_runner__run_untagged|d())) |
| 112 | + (ansible_local is undefined or |
| 113 | + (ansible_local|d() and (ansible_local.gitlab_runner is undefined or |
| 114 | + (ansible_local.gitlab_runner|d() and ansible_local.gitlab_runner.instances is defined and |
| 115 | + item.name not in ansible_local.gitlab_runner.instances))))) |
102 | 116 |
|
103 | | -- name: Generate gitlab-runner configuration file |
| 117 | +- name: Generate GitLab Runner configuration files |
104 | 118 | template: |
105 | | - src: 'etc/gitlab-runner/config.toml.j2' |
106 | | - dest: '/etc/gitlab-runner/config.toml' |
| 119 | + src: 'etc/gitlab-runner/{{ item }}.j2' |
| 120 | + dest: '/etc/gitlab-runner/{{ item }}' |
107 | 121 | owner: 'root' |
108 | 122 | group: 'root' |
109 | 123 | mode: '0600' |
| 124 | + with_items: [ 'config.toml', 'ansible.json' ] |
110 | 125 |
|
111 | 126 | - name: Delete GitLab Runners if requested |
112 | 127 | uri: |
|
145 | 160 | owner: '{{ gitlab_runner__user }}' |
146 | 161 | group: '{{ gitlab_runner__group }}' |
147 | 162 | mode: '0700' |
148 | | - when: gitlab_runner__ssh_known_hosts |
| 163 | + when: gitlab_runner__ssh_known_hosts|d() |
149 | 164 |
|
150 | 165 | - name: Make sure the ~/.ssh/known_hosts file exists |
151 | 166 | copy: |
|
155 | 170 | group: '{{ gitlab_runner__group }}' |
156 | 171 | mode: '0644' |
157 | 172 | force: False |
158 | | - when: gitlab_runner__ssh_known_hosts |
| 173 | + when: gitlab_runner__ssh_known_hosts|d() |
159 | 174 |
|
160 | 175 | - name: Get list of already scanned host fingerprints |
161 | 176 | shell: ssh-keygen -f {{ gitlab_runner__home }}/.ssh/known_hosts -F {{ item }} | grep -q '^# Host {{ item }} found' |
162 | 177 | with_items: '{{ gitlab_runner__ssh_known_hosts }}' |
163 | | - when: gitlab_runner__ssh_known_hosts |
| 178 | + when: gitlab_runner__ssh_known_hosts|d() |
164 | 179 | register: gitlab_runner__register_known_hosts |
165 | 180 | changed_when: False |
166 | 181 | failed_when: False |
|
185 | 200 | dest: '/etc/ansible/facts.d/gitlab_runner.fact' |
186 | 201 | owner: 'root' |
187 | 202 | group: 'root' |
188 | | - mode: '0600' |
| 203 | + mode: '0755' |
0 commit comments