feat: add backup cron

This commit is contained in:
Adrien Waksberg 2021-08-24 08:30:10 +02:00
parent ee3401e419
commit 5a3175d750
5 changed files with 34 additions and 2 deletions

View file

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

View file

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

View file

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

View file

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

View file

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