From 5a3175d75088a96810ae1a5f2569c262359e6138 Mon Sep 17 00:00:00 2001 From: Adrien Waksberg Date: Tue, 24 Aug 2021 08:30:10 +0200 Subject: [PATCH] feat: add backup cron --- CHANGELOG.md | 1 + README.md | 6 ++++++ defaults/main.yml | 5 +++++ molecule/default/tests/test_default.py | 11 +++++++++-- tasks/main.yml | 13 +++++++++++++ 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7da7e13..8a69fc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/) - feat: add gitlab_data_dir variable - feat: add gitlab_pages_url variable - feat: add complex variables in config file +- feat: add backup cron ### Changed diff --git a/README.md b/README.md index 1b4655c..863faf4 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,12 @@ Install and configure a Gitlab server 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`) + ## How to use ``` diff --git a/defaults/main.yml b/defaults/main.yml index a432b39..4340cd0 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -2,3 +2,8 @@ gitlab_repository: 'deb https://packages.gitlab.com/gitlab/gitlab-ce/debian/ {{ ansible_distribution_release }} main' gitlab_url: http://gitlab.example.com gitlab_config: {} +gitlab_backup_cron_month: '*' +gitlab_backup_cron_weekday: '*' +gitlab_backup_cron_day: '*' +gitlab_backup_cron_hour: 2 +gitlab_backup_cron_minute: 30 diff --git a/molecule/default/tests/test_default.py b/molecule/default/tests/test_default.py index 65d9c3a..e474363 100644 --- a/molecule/default/tests/test_default.py +++ b/molecule/default/tests/test_default.py @@ -1,8 +1,9 @@ import testinfra.utils.ansible_runner def test_packages(host): - package = host.package('gitlab-ce') - assert package.is_installed + for package_name in ['cron', 'gitlab-ce']: + package = host.package(package_name) + assert package.is_installed def test_git_directory(host): path = host.file('/opt/data/git') @@ -35,3 +36,9 @@ def test_grafana_down(host): assert False except: 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') diff --git a/tasks/main.yml b/tasks/main.yml index dac8072..4dc16af 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -12,6 +12,7 @@ - name: install package ansible.builtin.package: name: + - cron - gitlab-ce tags: gitlab @@ -37,3 +38,15 @@ state: started enabled: true tags: gitlab + +- name: add backup cron + ansible.builtin.cron: + name: gitlab-backup + user: root + job: gitlab-backup create + 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