Skip to content

Commit 9672bb4

Browse files
committed
Switch from GitLab API v1 to GitLab API v4
1 parent 25df95f commit 9672bb4

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ The current role maintainer_ is drybjed.
1616

1717
.. _debops.gitlab_runner master: https://github.com/debops/ansible-gitlab_runner/compare/v0.2.0...master
1818

19+
Changed
20+
~~~~~~~
21+
22+
- Switch from GitLab API v1 to GitLab API v4 for Runner management. [drybjed_]
23+
1924

2025
`debops.gitlab_runner v0.2.0`_ - 2017-08-16
2126
-------------------------------------------

defaults/main.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,18 @@ gitlab_runner__api_fqdn: 'code.{{ gitlab_runner__domain }}'
134134
# ]]]
135135
# .. envvar:: gitlab_runner__api_url [[[
136136
#
137-
# The HTTP API endpoint of the GitLab CI server to use for Runner registration.
137+
# The HTTP API endpoint of the GitLab CI server.
138138
# The role will check if the API server is available before trying to use it.
139-
gitlab_runner__api_url: 'https://{{ gitlab_runner__api_fqdn }}/ci'
139+
gitlab_runner__api_url: 'https://{{ gitlab_runner__api_fqdn }}/'
140+
141+
# ]]]
142+
# .. envvar:: gitlab_runner__api_token [[[
143+
#
144+
# The personal GitLab API access token used for API operations, for example
145+
# removal of existing Runners. This is not a Runner registration token. You can
146+
# generate an access token in GitLab "User Settings", "Access Tokens"
147+
# configuration page.
148+
gitlab_runner__api_token: ''
140149

141150
# ]]]
142151
# .. envvar:: gitlab_runner__executor [[[

tasks/main.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696

9797
- name: Register new GitLab Runners
9898
uri:
99-
url: '{{ (item.api_url | d(gitlab_runner__api_url)) + "/api/v1/runners/register.json" }}'
99+
url: '{{ (item.api_url | d(gitlab_runner__api_url)) + "api/v4/runners" }}'
100100
method: 'POST'
101101
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) }}'
102102
status_code: '200,201'
@@ -125,16 +125,18 @@
125125

126126
- name: Delete GitLab Runners if requested
127127
uri:
128-
url: '{{ (item.0.api_url | d(gitlab_runner__api_url)) + "/api/v1/runners/delete" }}'
128+
url: '{{ (item.0.api_url | d(gitlab_runner__api_url)) + "api/v4/runners/" + item.1.id | string }}'
129129
method: 'DELETE'
130-
body: 'token={{ item.1.token }}'
130+
headers:
131+
'PRIVATE-TOKEN': '{{ gitlab_runner__api_token }}'
131132
with_together:
132133
- '{{ gitlab_runner__default_instances + gitlab_runner__instances + gitlab_runner__group_instances + gitlab_runner__host_instances }}'
133134
- '{{ ansible_local.gitlab_runner.instance_tokens if (ansible_local|d() and ansible_local.gitlab_runner|d() and ansible_local.gitlab_runner.instance_tokens|d()) else [] }}'
134135
when: (gitlab_runner__register_api.status|d() and gitlab_runner__register_api.status == 200 and
135-
item.0.name|d() and item.1.name|d() and item.0.name == item.1.name and
136+
gitlab_runner__api_token and item.0.name|d() and item.1.name|d() and item.0.name == item.1.name and
136137
(item.0.state|d() and item.0.state == 'absent'))
137138
failed_when: False
139+
no_log: True
138140

139141
- name: Get the SSH key from the remote host
140142
slurp:

templates/etc/gitlab-runner/ansible.json.j2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
{% set gitlab_runner__tpl_instance_tokens = [] %}
33
{% if gitlab_runner__register_new_instances|d() and gitlab_runner__register_new_instances.results %}
44
{% for item in gitlab_runner__register_new_instances.results %}
5-
{% if item.item.name|d() and item.json|d() and item.json.token|d() %}
5+
{% if item.item.name|d() and item.json|d() and item.json.id|d() and item.json.token|d() %}
66
{% set _ = gitlab_runner__tpl_instances.append(item.item.name) %}
7-
{% set _ = gitlab_runner__tpl_instance_tokens.append({ "name": item.item.name, "token": item.json.token }) %}
7+
{% set _ = gitlab_runner__tpl_instance_tokens.append({ "id": item.json.id, "name": item.item.name, "token": item.json.token }) %}
88
{% endif %}
99
{% endfor %}
1010
{% endif %}
@@ -14,7 +14,7 @@
1414
{% for element in (gitlab_runner__default_instances + gitlab_runner__instances + gitlab_runner__group_instances + gitlab_runner__host_instances) %}
1515
{% if (item.name == element.name and (element.state is undefined or element.state != 'absent')) %}
1616
{% set _ = gitlab_runner__tpl_instances.append(item.name) %}
17-
{% set _ = gitlab_runner__tpl_instance_tokens.append({ "name": item.name, "token": item.token }) %}
17+
{% set _ = gitlab_runner__tpl_instance_tokens.append({ "id": item.id, "name": item.name, "token": item.token }) %}
1818
{% endif %}
1919
{% endfor %}
2020
{% endif %}

0 commit comments

Comments
 (0)