Skip to content

Commit 7eb2bd9

Browse files
committed
Add support for Vagrant LXC provider
1 parent 9672bb4 commit 7eb2bd9

File tree

6 files changed

+76
-1
lines changed

6 files changed

+76
-1
lines changed

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ 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+
Added
20+
~~~~~
21+
22+
- Add support for `Vagrant LXC <https://github.com/fgrehm/vagrant-lxc>`_
23+
provider when LXC is configured on a compatible host. [drybjed_]
24+
1925
Changed
2026
~~~~~~~
2127

defaults/main.yml

Lines changed: 23 additions & 1 deletion
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 [[[
@@ -304,6 +306,26 @@ gitlab_runner__group_custom_files: []
304306
gitlab_runner__host_custom_files: []
305307
# ]]]
306308
# ]]]
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+
# ]]]
307329
# SSH key and host management [[[
308330
# -------------------------------
309331

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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,15 @@
188188
when: gitlab_runner__ssh_known_hosts and item is defined and item.rc > 0
189189
failed_when: False
190190

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+
191200
- name: Make sure that Ansible fact directory exists
192201
file:
193202
path: '/etc/ansible/facts.d'
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)