From 849f13400323b6b8ba684d04c1d76c94a23be3e2 Mon Sep 17 00:00:00 2001 From: Paul Belanger Date: Sun, 17 Feb 2019 16:08:35 -0500 Subject: [PATCH] Add crontab configuration Install a default crontab configuration, as part of our installation process. Change-Id: Ibd1b9a91b0a9a31d0a95ed6b34f760a01bd5ba03 Signed-off-by: Paul Belanger --- defaults/main.yaml | 6 ++++++ molecule/default/Dockerfile.j2 | 2 +- molecule/tests/test_role.py | 8 ++++++++ tasks/config.yaml | 9 +++++++++ templates/etc/cron.d/borgmatic.j2 | 4 ++++ 5 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 templates/etc/cron.d/borgmatic.j2 diff --git a/defaults/main.yaml b/defaults/main.yaml index 86883e9..dd17711 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -29,6 +29,12 @@ borgmatic_file_config_yaml_mode: 0640 borgmatic_file_config_yaml_owner: "{{ borgmatic_user_name }}" borgmatic_file_config_yaml_src: root/.config/borgmatic/config.yaml.j2 +borgmatic_file_crontab_dest: /etc/cron.d/borgmatic +borgmatic_file_crontab_group: root +borgmatic_file_crontab_mode: 0644 +borgmatic_file_crontab_owner: root +borgmatic_file_crontab_src: etc/cron.d/borgmatic.j2 + # tasks/install.yaml borgmatic_git_dest: "{{ ansible_user_dir }}/src/github.com/witten/borgmatic" borgmatic_git_uri: https://github.com/witten/borgmatic diff --git a/molecule/default/Dockerfile.j2 b/molecule/default/Dockerfile.j2 index 0a084c6..12f6b56 100644 --- a/molecule/default/Dockerfile.j2 +++ b/molecule/default/Dockerfile.j2 @@ -6,4 +6,4 @@ FROM {{ item.registry.url }}/{{ item.image }} FROM {{ item.image }} {% endif %} -RUN apt-get update && apt-get install -y python sudo bash ca-certificates python-pip python3-pip && apt-get clean; +RUN apt-get update && apt-get install -y python sudo bash ca-certificates cron python-pip python3-pip && apt-get clean; diff --git a/molecule/tests/test_role.py b/molecule/tests/test_role.py index df5c040..c188be0 100644 --- a/molecule/tests/test_role.py +++ b/molecule/tests/test_role.py @@ -30,6 +30,14 @@ def test_borgmatic_config(host): assert f.mode == 0o640 del f + f = host.file('/etc/cron.d/borgmatic') + assert f.exists + assert f.is_file + assert f.user == 'root' + assert f.group == 'root' + assert f.mode == 0o644 + del f + def test_borgmatic_version(host): host.check_output('borgmatic --version') diff --git a/tasks/config.yaml b/tasks/config.yaml index 7dc8c46..62d3610 100644 --- a/tasks/config.yaml +++ b/tasks/config.yaml @@ -29,3 +29,12 @@ mode: "{{ borgmatic_file_config_yaml_mode }}" owner: "{{borgmatic_file_config_yaml_owner }}" src: "{{ borgmatic_file_config_yaml_src }}" + +- name: Install borgmatic crontab + become: true + template: + dest: "{{ borgmatic_file_crontab_dest }}" + group: "{{ borgmatic_file_crontab_group }}" + mode: "{{ borgmatic_file_crontab_mode }}" + owner: "{{borgmatic_file_crontab_owner }}" + src: "{{ borgmatic_file_crontab_src }}" diff --git a/templates/etc/cron.d/borgmatic.j2 b/templates/etc/cron.d/borgmatic.j2 new file mode 100644 index 0000000..408bd9c --- /dev/null +++ b/templates/etc/cron.d/borgmatic.j2 @@ -0,0 +1,4 @@ +# This file is generated by Ansible +# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN +# +0 3 * * * {{ borgmatic_user_name }} {{ borgmatic_pip_virtualenv | default('/usr/local') }}/bin/borgmatic