|
29 | 29 | - { src: "borgmatic.timer.j2", dest: "/usr/lib/systemd/system/borgmatic.timer", mode: "0644" } |
30 | 30 | - { src: "borgmatic.service.j2", dest: "/usr/lib/systemd/system/borgmatic.service", mode: "0644" } |
31 | 31 |
|
32 | | - - name: Populate service facts |
33 | | - ansible.builtin.service_facts: |
| 32 | + - name: Reload systemd daemon |
| 33 | + ansible.builtin.systemd: |
| 34 | + daemon_reload: true |
34 | 35 |
|
35 | | - # If the role is running and the repo is not yet initialized, an error will occur. |
36 | | - # Therefore the service is stopped by default and must be started manually. |
37 | | - - name: Stop fresh installed borgmatic.timer and borgmatic.service |
38 | | - when: "'borgmatic.service' not in ansible_facts.services" |
39 | | - block: |
40 | | - - name: Set borgmatic services to stopped - newly installed |
41 | | - ansible.builtin.systemd: |
42 | | - name: "{{ item }}" |
43 | | - state: stopped |
44 | | - enabled: false |
45 | | - masked: false |
46 | | - daemon_reload: true |
47 | | - when: item in ansible_facts.services |
48 | | - with_items: |
49 | | - - borgmatic.service |
| 36 | + - name: Enable and start borgmatic timer |
| 37 | + when: borgmatic_timer_enabled | default(true) | bool |
| 38 | + ansible.builtin.systemd: |
| 39 | + name: borgmatic.timer |
| 40 | + state: started |
| 41 | + enabled: true |
50 | 42 |
|
51 | | - # bug: Need own section without masked else the timer are skipped |
52 | | - - name: Set borgmatic timers to stopped - newly installed |
| 43 | + - name: Disable borgmatic timer |
| 44 | + when: not (borgmatic_timer_enabled | default(true) | bool) |
| 45 | + block: |
| 46 | + - name: Stop and disable borgmatic.timer |
53 | 47 | ansible.builtin.systemd: |
54 | | - name: "{{ item }}" |
| 48 | + name: borgmatic.timer |
55 | 49 | state: stopped |
56 | 50 | enabled: false |
57 | | - daemon_reload: true |
58 | | - with_items: |
59 | | - - "borgmatic.timer" |
60 | 51 |
|
61 | 52 | - name: Show hints |
62 | | - when: "'backup_init_repo' not in ansible_run_tags" |
63 | 53 | ansible.builtin.debug: |
64 | 54 | msg: >- |
65 | | - Attention: Since the repo was not initialized automatically, |
66 | | - the systemd service (borgmatic.service) and the timer (borgmatic.timer) are not activated. |
| 55 | + Attention: borgmatic_timer_enabled is set to false. |
| 56 | + The systemd timer (borgmatic.timer) is not activated. |
| 57 | + Enable it manually with: systemctl enable --now borgmatic.timer |
67 | 58 | ... |
0 commit comments