feat: add environment variables

This commit is contained in:
Adrien Waksberg 2022-05-10 10:40:42 +02:00
parent 24bc640fc9
commit f2e3f37201
7 changed files with 48 additions and 0 deletions

View file

@ -24,6 +24,12 @@ Install and configure a Gitlab runner
locked: false
```
- `gitlab_runner_env_variables` - dict with environment variables
```
HTTP_PROXY: https://127.0.0.1:3218
```
## How to use
```

View file

@ -2,3 +2,4 @@
gitlab_runner_repository: >
deb https://packages.gitlab.com/runner/gitlab-runner/debian/ {{ ansible_distribution_release }} main
gitlab_runner_runners: []
gitlab_runner_env_variables: {}

5
handlers/main.yml Normal file
View file

@ -0,0 +1,5 @@
---
- name: restart gitlab-runner
ansible.builtin.service:
name: gitlab-runner
state: restarted

View file

@ -4,6 +4,8 @@
roles:
- ansible-role-gitlab_runner
vars:
gitlab_runner_env_variables:
TEST: toto
gitlab_runner_runners:
- name: test
url: https://gitlab.example.com

View file

@ -4,6 +4,15 @@ def test_packages(host):
package = host.package('gitlab-runner')
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):
config = host.file('/etc/gitlab-runner/config.toml')
assert config.exists

View file

@ -17,6 +17,25 @@
GITLAB_RUNNER_DISABLE_SKEL: 'true'
tags: gitlab-runner
- 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:
name: '{{ item.name }}'

View file

@ -0,0 +1,6 @@
# {{ ansible_managed }}
[Service]
{% for env, value in gitlab_runner_env_variables.items() %}
Environment="{{ env }}={{ value }}"
{% endfor %}