diff --git a/roles/mgrote_docker_housekeeping/handlers/main.yml b/roles/mgrote_docker_housekeeping/handlers/main.yml new file mode 100644 index 00000000..7a0fa1e2 --- /dev/null +++ b/roles/mgrote_docker_housekeeping/handlers/main.yml @@ -0,0 +1,28 @@ +--- +- name: systemctl daemon-reload + become: true + ansible.builtin.systemd: + daemon_reload: true + +- name: systemctl enable units + become: true + ansible.builtin.systemd: + name: "{{ item }}" + enabled: true + masked: false + with_items: + - media-docker_housekeeping.automount + - media-docker_housekeeping.mount + - docker_housekeeping.service + - docker_housekeeping.timer + - docker_housekeeping_mail.service + +- name: systemctl start units + become: true + ansible.builtin.systemd: + name: "{{ item }}" + state: restarted + enabled: true + with_items: + - docker_housekeeping.timer + notify: systemctl daemon-reload diff --git a/roles/mgrote_docker_housekeeping/tasks/main.yml b/roles/mgrote_docker_housekeeping/tasks/main.yml index 1da6b7d9..e5828573 100644 --- a/roles/mgrote_docker_housekeeping/tasks/main.yml +++ b/roles/mgrote_docker_housekeeping/tasks/main.yml @@ -1,7 +1,23 @@ --- -- name: Include LDAP tasks - ansible.builtin.include_tasks: ldap.yml +- name: template docker_housekeeping.service + become: true + ansible.builtin.template: + src: docker_housekeeping.service.j2 + dest: /etc/systemd/system/docker_housekeeping.service + owner: root + group: root + mode: "0644" + notify: + - systemctl daemon-reload -- name: Include User tasks - ansible.builtin.include_tasks: admin.yml +- name: template docker_housekeeping.timer + become: true + ansible.builtin.template: + src: docker_housekeeping.timer.j2 + dest: /etc/systemd/system/docker_housekeeping.timer + owner: root + group: root + mode: "0644" + notify: + - systemctl daemon-reload ... diff --git a/roles/mgrote_docker_housekeeping/templates/docker_housekeeping.service.j2 b/roles/mgrote_docker_housekeeping/templates/docker_housekeeping.service.j2 new file mode 100644 index 00000000..0f808bb7 --- /dev/null +++ b/roles/mgrote_docker_housekeeping/templates/docker_housekeeping.service.j2 @@ -0,0 +1,15 @@ +{{ file_header | default () }} +[Unit] +Description=Backup with docker_housekeeping +Requires=media-docker_housekeeping.mount +After=media-docker_housekeeping.mount +OnFailure=docker_housekeeping_mail.service + +[Service] +Type=simple +EnvironmentFile={{ docker_housekeeping_conf_dir }}/docker_housekeeping.env +ExecStart=/usr/bin/docker_housekeeping backup --one-file-system --no-cache --exclude-file {{ docker_housekeeping_conf_dir }}/excludes {{ docker_housekeeping_folders_to_backup }} +{# -iexclude-file Same as exclude-file but ignores cases like in --iexclude; https://docker_housekeeping.readthedocs.io/en/latest/040_backup.html #} +User={{ docker_housekeeping_user }} +Group={{ docker_housekeeping_group }} +RestartSec={{ docker_housekeeping_failure_delay }} diff --git a/roles/mgrote_docker_housekeeping/templates/restic.timer.j2 b/roles/mgrote_docker_housekeeping/templates/docker_housekeeping.timer.j2 similarity index 56% rename from roles/mgrote_docker_housekeeping/templates/restic.timer.j2 rename to roles/mgrote_docker_housekeeping/templates/docker_housekeeping.timer.j2 index c40f99da..3626a930 100644 --- a/roles/mgrote_docker_housekeeping/templates/restic.timer.j2 +++ b/roles/mgrote_docker_housekeeping/templates/docker_housekeeping.timer.j2 @@ -1,9 +1,9 @@ {{ file_header | default () }} [Unit] -Description=Timer for restic backups. +Description=Timer for docker_housekeeping backups. [Timer] -OnCalendar={{ restic_schedule }} +OnCalendar={{ docker_housekeeping_schedule }} RandomizedDelaySec=30 min [Install] diff --git a/roles/mgrote_docker_housekeeping/templates/restic.service.j2 b/roles/mgrote_docker_housekeeping/templates/restic.service.j2 deleted file mode 100644 index bf498f75..00000000 --- a/roles/mgrote_docker_housekeeping/templates/restic.service.j2 +++ /dev/null @@ -1,15 +0,0 @@ -{{ file_header | default () }} -[Unit] -Description=Backup with restic -Requires=media-restic.mount -After=media-restic.mount -OnFailure=restic_mail.service - -[Service] -Type=simple -EnvironmentFile={{ restic_conf_dir }}/restic.env -ExecStart=/usr/bin/restic backup --one-file-system --no-cache --exclude-file {{ restic_conf_dir }}/excludes {{ restic_folders_to_backup }} -{# -iexclude-file Same as exclude-file but ignores cases like in --iexclude; https://restic.readthedocs.io/en/latest/040_backup.html #} -User={{ restic_user }} -Group={{ restic_group }} -RestartSec={{ restic_failure_delay }}