add 'btrfs' role, move vars to host_vars
This commit is contained in:
parent
13da397c76
commit
55d37e10ac
7 changed files with 127 additions and 45 deletions
10
roles/btrfs/files/btrfs-scrub@.service
Normal file
10
roles/btrfs/files/btrfs-scrub@.service
Normal file
|
@ -0,0 +1,10 @@
|
|||
[Unit]
|
||||
Description=Btrfs scrub on %f
|
||||
ConditionPathIsMountPoint=%f
|
||||
RequiresMountsFor=%f
|
||||
|
||||
[Service]
|
||||
Nice=19
|
||||
IOSchedulingClass=idle
|
||||
KillSignal=SIGINT
|
||||
ExecStart=/usr/bin/btrfs scrub start -B %f
|
11
roles/btrfs/files/btrfs-scrub@.timer
Normal file
11
roles/btrfs/files/btrfs-scrub@.timer
Normal file
|
@ -0,0 +1,11 @@
|
|||
[Unit]
|
||||
Description=Monthly Btrfs scrub on %f
|
||||
|
||||
[Timer]
|
||||
OnCalendar=monthly
|
||||
AccuracySec=1d
|
||||
RandomizedDelaySec=1w
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
5
roles/btrfs/handlers/main.yml
Normal file
5
roles/btrfs/handlers/main.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
- name: Reload systemd
|
||||
ansible.builtin.systemd:
|
||||
daemon_reload: true
|
||||
become: true
|
||||
listen: daemon_reload
|
32
roles/btrfs/tasks/main.yml
Normal file
32
roles/btrfs/tasks/main.yml
Normal file
|
@ -0,0 +1,32 @@
|
|||
- name: Setup scrub units
|
||||
ansible.builtin.copy:
|
||||
src: "{{ item }}"
|
||||
dest: /etc/systemd/system/
|
||||
mode: "0644"
|
||||
owner: root
|
||||
group: root
|
||||
with_items:
|
||||
- 'btrfs-scrub@.service'
|
||||
- 'btrfs-scrub@.timer'
|
||||
notify: daemon_reload
|
||||
become: true
|
||||
|
||||
- name: Run pending handlers
|
||||
ansible.builtin.meta: flush_handlers
|
||||
|
||||
- name: Determine btrfs mounts
|
||||
ansible.builtin.set_fact:
|
||||
btrfs_mounts: "{{ ansible_facts['mounts'] | selectattr('fstype', 'equalto', 'btrfs') | map(attribute='mount') | list }}"
|
||||
|
||||
- name: Determine systemd-friendly refs for BTRFS mount points
|
||||
ansible.builtin.command: "systemd-escape -p -- {{ item }}"
|
||||
register: sanitized_mounts
|
||||
loop: "{{ btrfs_mounts }}"
|
||||
changed_when: false
|
||||
|
||||
- name: Ensure the scrub timer is enabled for discovered BTRFS filesystems
|
||||
ansible.builtin.systemd:
|
||||
name: "btrfs-scrub@{{ item.stdout }}.timer"
|
||||
enabled: true
|
||||
with_items: "{{ sanitized_mounts.results }}"
|
||||
become: true
|
Loading…
Add table
Add a link
Reference in a new issue