Compare commits
11 commits
Author | SHA1 | Date | |
---|---|---|---|
e040edb66c | |||
bc812f1eab | |||
694f7c11d9 | |||
745707157e | |||
f67928b2c5 | |||
93c6c0a8e3 | |||
2019eca6df | |||
f2e3f37201 | |||
24bc640fc9 | |||
0ee4ef794b | |||
5ed001d64e |
14 changed files with 155 additions and 45 deletions
18
.forgejo/workflows/molecule.yml
Normal file
18
.forgejo/workflows/molecule.yml
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
---
|
||||||
|
on: [push]
|
||||||
|
jobs:
|
||||||
|
lint:
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: code.waks.be/nishiki/molecule:docker
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- run: ansible-lint .
|
||||||
|
- run: yamllint .
|
||||||
|
molecule:
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: code.waks.be/nishiki/molecule:docker
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- run: molecule test
|
10
.gitlab-ci.yml
Normal file
10
.gitlab-ci.yml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
---
|
||||||
|
image: nishiki/molecule:docker
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- molecule --version
|
||||||
|
|
||||||
|
molecule:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- molecule test
|
|
@ -2,11 +2,11 @@
|
||||||
extends: default
|
extends: default
|
||||||
|
|
||||||
ignore: |
|
ignore: |
|
||||||
.kitchen/*
|
.kitchen*
|
||||||
vendor/
|
vendor/
|
||||||
|
.forgejo/
|
||||||
|
|
||||||
rules:
|
rules:
|
||||||
line-length:
|
line-length:
|
||||||
max: 120
|
max: 120
|
||||||
level: warning
|
level: warning
|
||||||
truthy: false
|
|
||||||
|
|
13
CHANGELOG.md
13
CHANGELOG.md
|
@ -5,6 +5,19 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- test: add support debian 12
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
|
||||||
|
- test: remove support debian 10
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- test: use personal docker registry
|
||||||
|
- feat: use new token for registrer
|
||||||
|
|
||||||
## [v1.0.0] - 2020-08-09
|
## [v1.0.0] - 2020-08-09
|
||||||
|
|
||||||
- first version
|
- first version
|
||||||
|
|
25
README.md
25
README.md
|
@ -1,14 +1,17 @@
|
||||||
# Ansible role: Gitlab Runner
|
# Ansible role: Gitlab Runner
|
||||||
|
|
||||||
[![Version](https://img.shields.io/badge/latest_version-1.0.0-green.svg)](https://git.yaegashi.fr/nishiki/ansible-role-gitlab/releases)
|
[![Version](https://img.shields.io/badge/latest_version-1.0.0-green.svg)](https://code.waks.be/nishiki/ansible-role-gitlab/releases)
|
||||||
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://git.yaegashi.fr/nishiki/ansible-role-gitlab/src/branch/master/LICENSE)
|
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://code.waks.be/nishiki/ansible-role-gitlab/src/branch/main/LICENSE)
|
||||||
|
[![Build](https://code.waks.be/nishiki/ansible-role-gitlab_runner/actions/workflows/molecule.yml/badge.svg?branch=main)](https://code.waks.be/nishiki/ansible-role-gitlab_runner/actions?workflow=molecule.yml)
|
||||||
|
|
||||||
Install and configure a Gitlab runner
|
Install and configure a Gitlab runner
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
* Ansible >= 2.9
|
- Ansible >= 2.9
|
||||||
* Debian Buster
|
- Debian
|
||||||
|
- Bullseye
|
||||||
|
- Bookworm
|
||||||
|
|
||||||
## Role variables
|
## Role variables
|
||||||
|
|
||||||
|
@ -24,6 +27,12 @@ Install and configure a Gitlab runner
|
||||||
locked: false
|
locked: false
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- `gitlab_runner_env_variables` - dict with environment variables
|
||||||
|
|
||||||
|
```
|
||||||
|
HTTP_PROXY: https://127.0.0.1:3218
|
||||||
|
```
|
||||||
|
|
||||||
## How to use
|
## How to use
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -36,10 +45,10 @@ Install and configure a Gitlab runner
|
||||||
|
|
||||||
### Test with molecule and docker
|
### Test with molecule and docker
|
||||||
|
|
||||||
* install [docker](https://docs.docker.com/engine/installation/)
|
- install [docker](https://docs.docker.com/engine/installation/)
|
||||||
* install `python3` and `python3-pip`
|
- install `python3` and `python3-pip`
|
||||||
* install molecule and dependencies `pip3 install molecule 'molecule[docker]' docker ansible-lint testinfra yamllint`
|
- install molecule and dependencies `pip3 install molecule 'molecule[docker]' docker ansible-lint testinfra yamllint`
|
||||||
* run `molecule test`
|
- run `molecule test`
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|
|
@ -2,3 +2,4 @@
|
||||||
gitlab_runner_repository: >
|
gitlab_runner_repository: >
|
||||||
deb https://packages.gitlab.com/runner/gitlab-runner/debian/ {{ ansible_distribution_release }} main
|
deb https://packages.gitlab.com/runner/gitlab-runner/debian/ {{ ansible_distribution_release }} main
|
||||||
gitlab_runner_runners: []
|
gitlab_runner_runners: []
|
||||||
|
gitlab_runner_env_variables: {}
|
||||||
|
|
5
handlers/main.yml
Normal file
5
handlers/main.yml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
- name: Restart gitlab-runner
|
||||||
|
ansible.builtin.service:
|
||||||
|
name: gitlab-runner
|
||||||
|
state: restarted
|
|
@ -14,15 +14,19 @@ class GitlabRunner:
|
||||||
if v is False:
|
if v is False:
|
||||||
opts.append('--%s=false' % k)
|
opts.append('--%s=false' % k)
|
||||||
else:
|
else:
|
||||||
opts.append('--%s' % k)
|
if isinstance(v, list):
|
||||||
if v is not True:
|
for av in v:
|
||||||
opts.append(str(v))
|
opts.append('--%s' % k)
|
||||||
|
opts.append(str(av))
|
||||||
|
else:
|
||||||
|
opts.append('--%s' % k)
|
||||||
|
if v is not True:
|
||||||
|
opts.append(str(v))
|
||||||
|
|
||||||
subprocess.check_call(['gitlab-runner', 'register',
|
subprocess.check_call(['gitlab-runner', 'register',
|
||||||
'--non-interactive',
|
'--non-interactive',
|
||||||
'--name', self.name,
|
|
||||||
'--url', url,
|
'--url', url,
|
||||||
'--registration-token', token,
|
'--token', token,
|
||||||
'--executor', executor,
|
'--executor', executor,
|
||||||
] + opts )
|
] + opts )
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,18 @@
|
||||||
---
|
---
|
||||||
galaxy_info:
|
galaxy_info:
|
||||||
role_name: gitlab_runner
|
role_name: gitlab_runner
|
||||||
|
namespace: nishiki
|
||||||
author: Adrien Waksberg
|
author: Adrien Waksberg
|
||||||
company: Adrien Waksberg
|
company: Adrien Waksberg
|
||||||
description: Install and configure Gitlab runner
|
description: Install and configure Gitlab runner
|
||||||
license: Apache2
|
license: Apache2
|
||||||
min_ansible_version: 2.9
|
min_ansible_version: "2.9"
|
||||||
|
|
||||||
platforms:
|
platforms:
|
||||||
- name: Debian
|
- name: Debian
|
||||||
versions:
|
versions:
|
||||||
- buster
|
- bullseye
|
||||||
|
- bookworm
|
||||||
|
|
||||||
galaxy_tags:
|
galaxy_tags:
|
||||||
- git
|
- git
|
||||||
|
|
|
@ -4,9 +4,16 @@
|
||||||
roles:
|
roles:
|
||||||
- ansible-role-gitlab_runner
|
- ansible-role-gitlab_runner
|
||||||
vars:
|
vars:
|
||||||
|
gitlab_runner_env_variables:
|
||||||
|
TEST: toto
|
||||||
gitlab_runner_runners:
|
gitlab_runner_runners:
|
||||||
- name: test
|
- name: test
|
||||||
url: https://gitlab.example.com
|
url: https://gitlab.example.com
|
||||||
token: TesT
|
token: TesT
|
||||||
executor: docker
|
executor: docker
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
|
pre_tasks:
|
||||||
|
- name: update apt cache
|
||||||
|
ansible.builtin.apt:
|
||||||
|
update_cache: true
|
||||||
|
|
|
@ -2,21 +2,27 @@
|
||||||
driver:
|
driver:
|
||||||
name: docker
|
name: docker
|
||||||
platforms:
|
platforms:
|
||||||
- name: debian10
|
- name: debian12
|
||||||
image: nishiki/debian10:molecule
|
image: code.waks.be/nishiki/molecule:debian12
|
||||||
privileged: true
|
privileged: true
|
||||||
volumes:
|
volumes:
|
||||||
- /sys/fs/cgroup:/sys/fs/cgroup:ro
|
- /sys/fs/cgroup:/sys/fs/cgroup:rw
|
||||||
|
cgroupns_mode: host
|
||||||
|
command: /bin/systemd
|
||||||
|
capabilities:
|
||||||
|
- SYS_ADMIN
|
||||||
|
- name: debian11
|
||||||
|
image: code.waks.be/nishiki/molecule:debian11
|
||||||
|
privileged: true
|
||||||
|
volumes:
|
||||||
|
- /sys/fs/cgroup:/sys/fs/cgroup:rw
|
||||||
|
cgroupns_mode: host
|
||||||
command: /bin/systemd
|
command: /bin/systemd
|
||||||
capabilities:
|
capabilities:
|
||||||
- SYS_ADMIN
|
- SYS_ADMIN
|
||||||
exposed_ports:
|
|
||||||
- 22/tcp
|
|
||||||
published_ports:
|
|
||||||
- 0.0.0.0:2222:22/tcp
|
|
||||||
lint: |
|
lint: |
|
||||||
set -e
|
set -e
|
||||||
yamllint .
|
yamllint .
|
||||||
ansible-lint
|
ansible-lint .
|
||||||
verifier:
|
verifier:
|
||||||
name: testinfra
|
name: testinfra
|
||||||
|
|
|
@ -4,6 +4,15 @@ def test_packages(host):
|
||||||
package = host.package('gitlab-runner')
|
package = host.package('gitlab-runner')
|
||||||
assert package.is_installed
|
assert package.is_installed
|
||||||
|
|
||||||
|
def test_env_file(host):
|
||||||
|
path = host.file('/etc/systemd/system/gitlab-runner.service.d/ansible.conf')
|
||||||
|
assert path.exists
|
||||||
|
assert path.is_file
|
||||||
|
assert path.user == 'root'
|
||||||
|
assert path.group == 'root'
|
||||||
|
assert path.mode == 0o644
|
||||||
|
assert path.contains('Environment="TEST=toto"')
|
||||||
|
|
||||||
def test_config_file(host):
|
def test_config_file(host):
|
||||||
config = host.file('/etc/gitlab-runner/config.toml')
|
config = host.file('/etc/gitlab-runner/config.toml')
|
||||||
assert config.exists
|
assert config.exists
|
||||||
|
|
|
@ -1,36 +1,56 @@
|
||||||
---
|
---
|
||||||
- name: add gpg key
|
- name: Add gpg key
|
||||||
apt_key:
|
ansible.builtin.apt_key:
|
||||||
url: https://packages.gitlab.com/runner/gitlab-runner/gpgkey
|
url: https://packages.gitlab.com/runner/gitlab-runner/gpgkey
|
||||||
tags: gitlab-runner
|
tags: gitlab-runner
|
||||||
|
|
||||||
- name: add repository
|
- name: Add repository
|
||||||
apt_repository:
|
ansible.builtin.apt_repository:
|
||||||
repo: '{{ gitlab_runner_repository }}'
|
repo: "{{ gitlab_runner_repository }}"
|
||||||
tags: gitlab-runner
|
tags: gitlab-runner
|
||||||
|
|
||||||
- name: install package
|
- name: Install package
|
||||||
package:
|
ansible.builtin.package:
|
||||||
name: gitlab-runner
|
name:
|
||||||
|
- gitlab-runner
|
||||||
environment:
|
environment:
|
||||||
GITLAB_RUNNER_DISABLE_SKEL: 'true'
|
GITLAB_RUNNER_DISABLE_SKEL: "true"
|
||||||
tags: gitlab-runner
|
tags: gitlab-runner
|
||||||
|
|
||||||
- name: register runners
|
- name: Create system directory
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: /etc/systemd/system/gitlab-runner.service.d
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: 0755
|
||||||
|
state: directory
|
||||||
|
tags: gitlab-runner
|
||||||
|
|
||||||
|
- name: Add environment variables
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: environment.conf.j2
|
||||||
|
dest: /etc/systemd/system/gitlab-runner.service.d/ansible.conf
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: 0644
|
||||||
|
notify: Restart gitlab-runner
|
||||||
|
tags: gitlab-runner
|
||||||
|
|
||||||
|
- name: Register runners
|
||||||
gitlab_runner:
|
gitlab_runner:
|
||||||
name: '{{ item.name }}'
|
name: "{{ item.name }}"
|
||||||
url: '{{ item.url }}'
|
url: "{{ item.url }}"
|
||||||
token: '{{ item.token }}'
|
token: "{{ item.token }}"
|
||||||
executor: '{{ item.executor }}'
|
executor: "{{ item.executor }}"
|
||||||
options: '{{ item.options|default({}) }}'
|
options: "{{ item.options | default({}) }}"
|
||||||
state: '{{ item.state|default("present") }}'
|
state: "{{ item.state | default('present') }}"
|
||||||
loop: '{{ gitlab_runner_runners }}'
|
loop: "{{ gitlab_runner_runners }}"
|
||||||
loop_control:
|
loop_control:
|
||||||
label: '{{ item.name }}'
|
label: "{{ item.name }}"
|
||||||
tags: gitlab-runner
|
tags: gitlab-runner
|
||||||
|
|
||||||
- name: enable and start service
|
- name: Enable and start service
|
||||||
service:
|
ansible.builtin.service:
|
||||||
name: gitlab-runner
|
name: gitlab-runner
|
||||||
state: started
|
state: started
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
6
templates/environment.conf.j2
Normal file
6
templates/environment.conf.j2
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
# {{ ansible_managed }}
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
{% for env, value in gitlab_runner_env_variables.items() %}
|
||||||
|
Environment="{{ env }}={{ value }}"
|
||||||
|
{% endfor %}
|
Loading…
Reference in a new issue