Compare commits

...

14 commits
v1.0.0 ... main

Author SHA1 Message Date
2da9b5cfba feat: add options for backup
All checks were successful
/ lint (push) Successful in 15s
/ molecule (push) Successful in 6m20s
2024-07-13 12:26:20 +02:00
cdf5f3090a test: add forgejo workflow
All checks were successful
/ lint (push) Successful in 8s
/ molecule (push) Successful in 8m1s
2024-05-09 11:38:46 +02:00
52e0445972 test: use personal docker registry 2024-05-07 14:36:26 +02:00
b56342f14e test: fix syntax for ansible-lint 2024-03-13 21:35:44 +01:00
d02a152f4b test: add support debian 12 2024-03-13 21:35:43 +01:00
6819a4b3ac test: add gitlab-ci 2024-03-13 21:35:42 +01:00
fdf44bb252 feat: add gitlab_registry_url variable 2024-03-13 21:35:41 +01:00
6b60c360ed release: version 1.1.0 2021-08-24 09:14:40 +02:00
a530f03df0 test: add support debian 11 2021-08-24 09:13:44 +02:00
5a3175d750 feat: add backup cron 2021-08-24 08:30:10 +02:00
ee3401e419 feat: add complex variables in config file 2021-08-24 08:13:21 +02:00
1e057c9ba1 chore: use FQCN for module name 2021-08-24 08:06:07 +02:00
c821b91dd9 feat: add gitlab_pages_url variable 2021-08-24 08:03:45 +02:00
b6600b4d77 feat: add gitlab_data_dir variable 2021-08-24 07:59:04 +02:00
13 changed files with 195 additions and 48 deletions

View 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
View file

@ -0,0 +1,10 @@
---
image: nishiki/molecule:docker
before_script:
- molecule --version
molecule:
stage: test
script:
- molecule test

View file

@ -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

View file

@ -3,8 +3,37 @@
This project adheres to [Semantic Versioning](http://semver.org/). This project adheres to [Semantic Versioning](http://semver.org/).
Which is based on [Keep A Changelog](http://keepachangelog.com/) Which is based on [Keep A Changelog](http://keepachangelog.com/)
## [Unreleased] ## Unreleased
## [v1.0.0] - 2020-04-11 ### Added
- feat: add gitlab_registry_url variable
- feat: add options for backup
- test: add support debian 12
### Changed
- test: use personal docker registry
### Removed
- test: remove support debian 10
- test: remove support debian 11
## v1.1.0 - 2021-08-24
### Added
- feat: add gitlab_data_dir variable
- feat: add gitlab_pages_url variable
- feat: add complex variables in config file
- feat: add backup cron
- test: add support debian 11
### Changed
- chore: use FQCN for module name
## v1.0.0 - 2020-04-11
- first version - first version

View file

@ -1,18 +1,23 @@
# Ansible role: Gitlab # Ansible role: Gitlab
[![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.1.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/actions/workflows/molecule.yml/badge.svg?branch=main)](https://code.waks.be/nishiki/ansible-role-gitlab/actions?workflow=molecule.yml)
Install and configure a Gitlab server Install and configure a Gitlab server
## Requirements ## Requirements
* Ansible >= 2.9 - Ansible >= 2.9
* Debian Buster - Debian
- Bullseye
- Bookworm
## Role variables ## Role variables
- `gitlab_url` - set the gitlab url (default: `http://gitlab.example.com`) - `gitlab_url` - set the gitlab url
- `gitlab_pages_url` - set the gitlab pages url
- `gitlab_data_dir` - set the path for repository
- `gitlab_config` - set the config - `gitlab_config` - set the config
``` ```
@ -23,6 +28,14 @@ Install and configure a Gitlab server
backup_archive_permissions: 0644 backup_archive_permissions: 0644
``` ```
- `gitlab_backup_cron_month` - set the month for the backup cron (default: `'*'`)
- `gitlab_backup_cron_weekday` - set the weekday for the backup cron (default: `'*'`)
- `gitlab_backup_cron_day` - set the day for the backup cron (default: `'*'`)
- `gitlab_backup_cron_hour` - set the hour for the backup cron (default: `2`)
- `gitlab_backup_cron_minute` - set the minute for the backup cron (default: `30`)
- `gitlab_backup_skip` - list with [skip data](https://docs.gitlab.com/ee/administration/backup_restore/backup_gitlab.html#excluding-specific-data-from-the-backup)
- `gitlab_backup_auto` - set if a backup if create during update (default: `true`)
## How to use ## How to use
``` ```
@ -35,10 +48,10 @@ Install and configure a Gitlab server
### 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 pytest-testinfra yamllint`
* run `molecule test` - run `molecule test`
## License ## License

View file

@ -2,3 +2,10 @@
gitlab_repository: 'deb https://packages.gitlab.com/gitlab/gitlab-ce/debian/ {{ ansible_distribution_release }} main' gitlab_repository: 'deb https://packages.gitlab.com/gitlab/gitlab-ce/debian/ {{ ansible_distribution_release }} main'
gitlab_url: http://gitlab.example.com gitlab_url: http://gitlab.example.com
gitlab_config: {} gitlab_config: {}
gitlab_backup_cron_month: '*'
gitlab_backup_cron_weekday: '*'
gitlab_backup_cron_day: '*'
gitlab_backup_cron_hour: 2
gitlab_backup_cron_minute: 30
gitlab_backup_skip: []
gitlab_backup_auto: true

View file

@ -1,4 +1,3 @@
--- ---
- name: reconfigure gitlab - name: Reconfigure gitlab # noqa no-changed-when
command: gitlab-ctl reconfigure ansible.builtin.command: gitlab-ctl reconfigure
tags: gitlab

View file

@ -1,16 +1,18 @@
--- ---
galaxy_info: galaxy_info:
role_name: gitlab role_name: gitlab
namespace: nishiki
author: Adrien Waksberg author: Adrien Waksberg
company: Adrien Waksberg company: Adrien Waksberg
description: Install and configure gitlab server description: Install and configure gitlab server
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

View file

@ -4,16 +4,23 @@
roles: roles:
- ansible-role-gitlab - ansible-role-gitlab
vars: vars:
gitlab_data_dir: /opt/data/git
gitlab_backup_auto: false
gitlab_backup_skip:
- db
- registry
gitlab_config: gitlab_config:
prometheus: prometheus:
enable: false enable: false
alertmanager: alertmanager:
enable: false enable: false
grafana:
enable: false
pre_tasks: pre_tasks:
- name: delete dockerenv file - name: delete dockerenv file
file: ansible.builtin.file:
path: /.dockerenv path: /.dockerenv
state: absent state: absent
- name: update apt cache
ansible.builtin.apt:
update_cache: true

View file

@ -2,21 +2,18 @@
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 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

View file

@ -1,8 +1,14 @@
import testinfra.utils.ansible_runner import testinfra.utils.ansible_runner
def test_packages(host): def test_packages(host):
package = host.package('gitlab-ce') for package_name in ['cron', 'gitlab-ce']:
assert package.is_installed package = host.package(package_name)
assert package.is_installed
def test_git_directory(host):
path = host.file('/opt/data/git')
assert path.exists
assert path.is_directory
def test_config_file(host): def test_config_file(host):
config = host.file('/etc/gitlab/gitlab.rb') config = host.file('/etc/gitlab/gitlab.rb')
@ -12,7 +18,15 @@ def test_config_file(host):
assert config.group == 'root' assert config.group == 'root'
assert config.mode == 0o600 assert config.mode == 0o600
assert config.contains("external_url 'http://gitlab.example.com'") assert config.contains("external_url 'http://gitlab.example.com'")
assert config.contains("grafana\\['enable'\\] = false") assert config.contains("prometheus\\['enable'\\] = false")
def test_skip_auto_backup_file(host):
config = host.file('/etc/gitlab/skip-auto-backup')
assert config.exists
assert config.is_file
assert config.user == 'root'
assert config.group == 'root'
assert config.mode == 0o644
def test_service(host): def test_service(host):
service = host.service('gitlab-runsvdir') service = host.service('gitlab-runsvdir')
@ -29,3 +43,9 @@ def test_grafana_down(host):
assert False assert False
except: except:
assert True assert True
def test_cron_file(host):
config = host.file('/var/spool/cron/crontabs/root')
assert config.exists
assert config.is_file
assert config.contains('30 2 \\* \\* \\* gitlab-backup create SKIP=db,registry')

View file

@ -1,38 +1,74 @@
--- ---
- name: add gpg key - name: Install dependencies packages
apt_key: ansible.builtin.package:
name:
- cron
- gpg
tags: gitlab
- name: Add gpg key
ansible.builtin.apt_key:
url: https://packages.gitlab.com/gitlab/gitlab-ce/gpgkey url: https://packages.gitlab.com/gitlab/gitlab-ce/gpgkey
tags: gitlab tags: gitlab
- name: add repository - name: Add repository
apt_repository: ansible.builtin.apt_repository:
repo: '{{ gitlab_repository }}' repo: '{{ gitlab_repository }}'
tags: gitlab tags: gitlab
- name: install package - name: Install package
package: ansible.builtin.package:
name: gitlab-ce name:
- gitlab-ce
tags: gitlab tags: gitlab
- name: copy config - name: Copy config
template: ansible.builtin.template:
src: gitlab.rb.j2 src: gitlab.rb.j2
dest: /etc/gitlab/gitlab.rb dest: /etc/gitlab/gitlab.rb
owner: root owner: root
group: root group: root
mode: 0600 mode: 0600
notify: reconfigure gitlab notify: Reconfigure gitlab
tags: gitlab tags: gitlab
- name: init gitlab - name: Init gitlab
command: gitlab-ctl reconfigure ansible.builtin.command: gitlab-ctl reconfigure
args: args:
creates: /usr/lib/systemd/system/gitlab-runsvdir.service creates: /usr/lib/systemd/system/gitlab-runsvdir.service
tags: gitlab tags: gitlab
- name: enable and start service - name: Enable and start service
service: ansible.builtin.service:
name: gitlab-runsvdir name: gitlab-runsvdir
state: started state: started
enabled: true enabled: true
tags: gitlab tags: gitlab
- name: Check if skip autobackup file exists
ansible.builtin.stat:
path: /etc/gitlab/skip-auto-backup
register: st
tags: gitlab
- name: Manage skip autobackup file
ansible.builtin.file:
path: /etc/gitlab/skip-auto-backup
owner: root
group: root
mode: "0644"
state: "{{ gitlab_backup_auto | ternary('absent', 'touch')}}"
when: not st.stat.exists or gitlab_backup_auto
tags: gitlab
- name: Add backup cron
ansible.builtin.cron:
name: gitlab-backup
user: root
job: "gitlab-backup create SKIP={{ gitlab_backup_skip | join(',') }}"
month: '{{ gitlab_backup_cron_month | string }}'
weekday: '{{ gitlab_backup_cron_weekday | string }}'
day: '{{ gitlab_backup_cron_day | string }}'
hour: '{{ gitlab_backup_cron_hour | string }}'
minute: '{{ gitlab_backup_cron_minute | string }}'
tags: gitlab

View file

@ -1,12 +1,19 @@
# {{ ansible_managed }} # {{ ansible_managed }}
external_url '{{ gitlab_url }}' external_url '{{ gitlab_url }}'
{% if gitlab_registry_url is defined %}
registry_external_url '{{ gitlab_registry_url }}'
{% endif %}
{% if gitlab_pages_url is defined %}
pages_external_url '{{ gitlab_pages_url }}'
{% endif %}
{% if gitlab_data_dir is defined %}
git_data_dirs({ git_data_dirs({
"default" => { "default" => {
"path" => "{{ gitlab_data_dir }}" "path" => "{{ gitlab_data_dir }}"
} }
}) })
{% endif %}
{% for module, options in gitlab_config.items() %} {% for module, options in gitlab_config.items() %}
{% for option, value in options.items() %} {% for option, value in options.items() %}
@ -14,7 +21,9 @@ git_data_dirs({
{% elif value is sameas false %}false {% elif value is sameas false %}false
{% elif value is string %}'{{ value }}' {% elif value is string %}'{{ value }}'
{% elif value is number %}{{ value }} {% elif value is number %}{{ value }}
{% else %}['{{ value|join("', '") }}'] {% else %}YAML.load <<-EOS
{{ value|to_nice_yaml }}
EOS
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}