Skip to content

Commit 390703a

Browse files
committed
Merge branch 'drybjed-role-enhancements'
2 parents 25df95f + 754423a commit 390703a

File tree

7 files changed

+108
-11
lines changed

7 files changed

+108
-11
lines changed

CHANGES.rst

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,24 @@ The current role maintainer_ is drybjed.
1414
`debops.gitlab_runner master`_ - unreleased
1515
-------------------------------------------
1616

17-
.. _debops.gitlab_runner master: https://github.com/debops/ansible-gitlab_runner/compare/v0.2.0...master
17+
.. _debops.gitlab_runner master: https://github.com/debops/ansible-gitlab_runner/compare/v0.3.0...master
18+
19+
20+
`debops.gitlab_runner v0.3.0`_ - 2017-10-13
21+
-------------------------------------------
22+
23+
.. _debops.gitlab_runner v0.3.0: https://github.com/debops/ansible-gitlab_runner/compare/v0.2.0...v0.3.0
24+
25+
Added
26+
~~~~~
27+
28+
- Add support for `Vagrant LXC <https://github.com/fgrehm/vagrant-lxc>`_
29+
provider when LXC is configured on a compatible host. [drybjed_]
30+
31+
Changed
32+
~~~~~~~
33+
34+
- Switch from GitLab API v1 to GitLab API v4 for Runner management. [drybjed_]
1835

1936

2037
`debops.gitlab_runner v0.2.0`_ - 2017-08-16

defaults/main.yml

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ gitlab_runner__apt_repo: 'deb https://packages.gitlab.com/runner/gitlab-ci-multi
3434
# .. envvar:: gitlab_runner__base_packages [[[
3535
#
3636
# List of APT packages which will be installed by the role.
37-
gitlab_runner__base_packages: [ 'gitlab-ci-multi-runner' ]
37+
gitlab_runner__base_packages:
38+
- 'gitlab-ci-multi-runner'
39+
- '{{ "vagrant-lxc" if gitlab_runner__vagrant_lxc|bool else [] }}'
3840

3941
# ]]]
4042
# .. envvar:: gitlab_runner__packages [[[
@@ -134,9 +136,18 @@ gitlab_runner__api_fqdn: 'code.{{ gitlab_runner__domain }}'
134136
# ]]]
135137
# .. envvar:: gitlab_runner__api_url [[[
136138
#
137-
# The HTTP API endpoint of the GitLab CI server to use for Runner registration.
139+
# The HTTP API endpoint of the GitLab CI server.
138140
# 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'
141+
gitlab_runner__api_url: 'https://{{ gitlab_runner__api_fqdn }}/'
142+
143+
# ]]]
144+
# .. envvar:: gitlab_runner__api_token [[[
145+
#
146+
# The personal GitLab API access token used for API operations, for example
147+
# removal of existing Runners. This is not a Runner registration token. You can
148+
# generate an access token in GitLab "User Settings", "Access Tokens"
149+
# configuration page.
150+
gitlab_runner__api_token: ''
140151

141152
# ]]]
142153
# .. envvar:: gitlab_runner__executor [[[
@@ -295,6 +306,26 @@ gitlab_runner__group_custom_files: []
295306
gitlab_runner__host_custom_files: []
296307
# ]]]
297308
# ]]]
309+
# Shell executor configuration [[[
310+
# --------------------------------
311+
312+
# These variables control what features are configured on the GitLab Runner
313+
# host to use by the shell executor.
314+
315+
# .. envvar:: gitlab_runner__vagrant_lxc [[[
316+
#
317+
# Enable or disable support for Vagrant LXC plugin (configuration of this
318+
# support also implies installation of :command:`vagrant` on the GitLab Runner
319+
# host). Enabling Vagrant LXC will give limited :command:`sudo` access for the
320+
# GitLab Runner UNIX account to allow access to LXC commands.
321+
gitlab_runner__vagrant_lxc: '{{ True
322+
if (ansible_local|d() and ansible_local.lxc|d() and
323+
(ansible_local.lxc.installed|d())|bool and
324+
(ansible_distribution_release not in
325+
[ "wheezy", "jessie", "precise", "trusty" ]))
326+
else False }}'
327+
# ]]]
328+
# ]]]
298329
# SSH key and host management [[[
299330
# -------------------------------
300331

docs/getting-started.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ executors - one unprivileged, and one privileged. The executors will have a set
4545
of tags that identify them, shell executors will have additional tags that
4646
describe the host's architecture, OS release, etc.
4747

48+
If the ``debops.lxc`` role has been used to configure LXC support on a Debian
49+
Stretch or Ubuntu Xenial host, the ``debops.gitlab_runner`` will install the
50+
``vagrant-lxc`` package and configure :command:`sudo` support for it. Using
51+
a shell executor you cn start and stop Vagrant Boxes using LXC containers and
52+
execute commands inside them.
53+
4854
The Runner instances can be configured with variables specified as the keys of
4955
the dictionary that holds the specific Runner configuration. If any required
5056
keys are not specified, the value of the global variable will be used instead.

tasks/main.yml

Lines changed: 15 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:
@@ -186,6 +188,15 @@
186188
when: gitlab_runner__ssh_known_hosts and item is defined and item.rc > 0
187189
failed_when: False
188190

191+
- name: Configure Vagrant LXC sudo access
192+
template:
193+
src: 'etc/sudoers.d/gitlab-runner-vagrant-lxc.j2'
194+
dest: '/etc/sudoers.d/gitlab-runner-vagrant-lxc'
195+
owner: 'root'
196+
group: 'root'
197+
mode: '0440'
198+
when: gitlab_runner__vagrant_lxc|bool
199+
189200
- name: Make sure that Ansible fact directory exists
190201
file:
191202
path: '/etc/ansible/facts.d'

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 %}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# {{ ansible_managed }}
2+
3+
# lxc
4+
{{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env lxc-ls
5+
{{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env lxc-info *
6+
{{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env lxc-config *
7+
{{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env lxc-attach *
8+
{{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env which lxc-*
9+
10+
# vagrant-lxc (startup)
11+
{{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env cat /var/lib/lxc/*/config
12+
{{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env lxc-start -d --name *
13+
14+
# vagrant-lxc (create)
15+
{{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env lxc-create --version
16+
{{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env lxc-create -B * --template * --name * -- --tarball {{ gitlab_runner__home }}/.vagrant.d/boxes/* --config {{ gitlab_runner__home }}/.vagrant.d/boxes/*
17+
{{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env tar --numeric-owner -cvzf /tmp/*/rootfs.tar.gz -C /var/lib/lxc/* ./rootfs
18+
{{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env cp -f /tmp/lxc-config* /var/lib/lxc/*/config
19+
{{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env chown root\:root /var/lib/lxc/*/config
20+
{{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env chown *\:* /tmp/*/rootfs.tar.gz
21+
22+
# vagrant-lxc (shutdown & destroy)
23+
{{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env lxc-shutdown --name *
24+
{{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env lxc-stop --name *
25+
{{ gitlab_runner__user }} ALL=(root) NOPASSWD: /usr/bin/env lxc-destroy --name *

templates/lookup/gitlab_runner__shell_tags.j2

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
(ansible_local.docker.installed|d()) | bool) %}
1010
{% set _ = output.append('docker-host') %}
1111
{% endif %}
12+
{% if (ansible_local|d() and ansible_local.lxc|d() and
13+
(ansible_local.lxc.installed|d()) | bool) %}
14+
{% set _ = output.append('lxc-host') %}
15+
{% endif %}
16+
{% if gitlab_runner__vagrant_lxc|bool %}
17+
{% set _ = output.append('vagrant-lxc') %}
18+
{% endif %}
1219
{% set _ = output.append((ansible_local.core.distribution
1320
if (ansible_local|d() and ansible_local.core|d() and
1421
ansible_local.core.distribution|d())

0 commit comments

Comments
 (0)