2025-04-03 00:12:58 +02:00
# SPDX-License-Identifier: MIT
- name : 'If Arch Linux create dir to Git clone repo for pacman hook for ZFS dataset snapshots'
when : 'ansible_facts[' 'os_family' '] | lower == ' 'archlinux' ''
ansible.builtin.file :
2025-12-18 23:25:42 +01:00
path : '{{ genma_pacman_hook_git_base_dir }}/{{ genma_pacman_hook_git_branch }}'
2025-04-03 00:12:58 +02:00
state : 'directory'
- name : 'If Arch Linux Git clone repo for pacman hook for ZFS dataset snapshots'
when : 'ansible_facts[' 'os_family' '] | lower == ' 'archlinux' ''
ansible.builtin.git :
repo : 'https://quico.space/quico-os-setup/zfs-pacman-hook'
2025-12-18 23:25:42 +01:00
dest : '{{ genma_pacman_hook_git_base_dir }}/{{ genma_pacman_hook_git_branch }}'
version : '{{ genma_pacman_hook_git_branch }}'
2025-04-03 00:12:58 +02:00
- name : 'If Arch Linux get list of checked out branches of repo for pacman hook for ZFS dataset snapshots'
when : 'ansible_facts[' 'os_family' '] | lower == ' 'archlinux' ''
2025-12-18 23:25:42 +01:00
register : 'genma_pacman_hook_branches_actual'
2025-04-03 00:12:58 +02:00
changed_when : false
ansible.builtin.shell : |
2025-12-18 23:25:42 +01:00
ls -1 '{{ genma_pacman_hook_git_base_dir }}'
2025-04-03 00:12:58 +02:00
- name : 'If Arch Linux remove unneeded branches of repo for pacman hook for ZFS dataset snapshots'
2025-12-18 23:25:42 +01:00
when : 'item != genma_pacman_hook_git_branch and ansible_facts[' 'os_family' '] | lower == ' 'archlinux' ''
2025-04-03 00:12:58 +02:00
loop_control :
label : 'If unneeded delete branch ' '{{ item }}' ''
2025-12-18 23:25:42 +01:00
loop : '{{ genma_pacman_hook_branches_actual.stdout_lines }}'
2025-04-03 00:12:58 +02:00
ansible.builtin.file :
2025-12-18 23:25:42 +01:00
path : '{{ genma_pacman_hook_git_base_dir }}/{{ item }}'
2025-04-03 00:12:58 +02:00
state : 'absent'
- name : 'If Arch Linux create symlinks to repo for pacman hook for ZFS dataset snapshots'
when : 'ansible_facts[' 'os_family' '] | lower == ' 'archlinux' ''
loop_control :
2025-12-18 23:25:42 +01:00
loop_var : 'genma_pacman_hook_symlink'
label : 'Create symlink to ' '{{ genma_pacman_hook_symlink.target | basename }}' ''
2025-04-03 00:12:58 +02:00
loop :
2025-12-18 23:25:42 +01:00
- { target : '{{ genma_pacman_hook_git_base_dir }}/{{ genma_pacman_hook_git_branch }}/pacman-zfs-snapshot.sh' , symlink : '/usr/local/bin/pacman-zfs-snapshot' }
- { target : '{{ genma_pacman_hook_git_base_dir }}/{{ genma_pacman_hook_git_branch }}/pacman-zfs-snapshot-install.hook' , symlink : '/usr/share/libalpm/hooks/00-pacman-zfs-snapshot-install.hook' }
- { target : '{{ genma_pacman_hook_git_base_dir }}/{{ genma_pacman_hook_git_branch }}/pacman-zfs-snapshot-remove.hook' , symlink : '/usr/share/libalpm/hooks/00-pacman-zfs-snapshot-remove.hook' }
- { target : '{{ genma_pacman_hook_git_base_dir }}/{{ genma_pacman_hook_git_branch }}/pacman-zfs-snapshot-upgrade.hook' , symlink : '/usr/share/libalpm/hooks/00-pacman-zfs-snapshot-upgrade.hook' }
- { target : '{{ genma_pacman_hook_git_base_dir }}/{{ genma_pacman_hook_git_branch }}/pacman-zfs-snapshot.conf' , symlink : '/etc/pacman-zfs-snapshot.conf' }
2025-04-03 00:12:58 +02:00
ansible.builtin.file :
2025-12-18 23:25:42 +01:00
src : '{{ genma_pacman_hook_symlink.target }}'
dest : '{{ genma_pacman_hook_symlink.symlink }}'
2025-04-03 00:12:58 +02:00
state : 'link'
force : true
- name : 'If Arch Linux get list of datasets'
when : 'ansible_facts[' 'os_family' '] | lower == ' 'archlinux' ''
2025-12-18 23:25:42 +01:00
register : 'genma_pacman_hook_auto_snapshot_datasets_list'
2025-04-03 00:12:58 +02:00
changed_when : false
ansible.builtin.shell : |
zfs list -H -o name
- name : 'If Arch Linux check current state of auto-snapshot marker on datasets'
when : 'ansible_facts[' 'os_family' '] | lower == ' 'archlinux' ''
2025-12-18 23:25:42 +01:00
register : 'genma_pacman_hook_auto_snapshot_datasets_actual'
2025-04-03 00:12:58 +02:00
changed_when : false
loop_control :
loop_var : 'dataset'
label : 'Check if dataset ' '{{ dataset }}' ' is marked for auto-snapshotting'
2025-12-18 23:25:42 +01:00
loop : '{{ genma_pacman_hook_auto_snapshot_datasets_list.stdout_lines }}'
2025-04-03 00:12:58 +02:00
ansible.builtin.shell : |
zfs get -H -o value space.quico:auto-snapshot '{{ dataset }}'
- name : 'If Arch Linux mark ZFS datasets for auto-snapshotting'
2025-12-18 23:25:42 +01:00
when : 'genma_pacman_hook_auto_snapshot_datasets_actual[' 'results' '][i][' 'stdout_lines' '] | first != ' 'true' ' and dataset in genma_pacman_hook_auto_snapshot_datasets and ansible_facts[' 'os_family' '] | lower == ' 'archlinux' ''
2025-04-03 00:12:58 +02:00
loop_control :
loop_var : 'dataset'
index_var : 'i'
2025-12-18 23:25:42 +01:00
label : 'If not marked for auto-snapshotting - {% if genma_pacman_hook_auto_snapshot_datasets_actual[' 'results' '][i][' 'stdout_lines' '] | first != ' 'true' ' and dataset in genma_pacman_hook_auto_snapshot_datasets %}⚠️{% else %}✅{% endif %} expected {% if dataset in genma_pacman_hook_auto_snapshot_datasets %}yes{% else %} no{% endif %}/was actually {% if genma_pacman_hook_auto_snapshot_datasets_actual[' 'results' '][i][' 'stdout_lines' '] | first != ' 'true' ' %} no{% else %}yes{% endif %} - mark ZFS dataset ' '{{ dataset }}' ''
loop : '{{ genma_pacman_hook_auto_snapshot_datasets_list.stdout_lines }}'
2025-04-03 00:12:58 +02:00
ansible.builtin.shell : |
zfs set space.quico:auto-snapshot=true '{{ dataset }}'
- name : 'If Arch Linux unmark ZFS datasets for auto-snapshotting'
2025-12-18 23:25:42 +01:00
when : 'genma_pacman_hook_auto_snapshot_datasets_actual[' 'results' '][i][' 'stdout_lines' '] | first == ' 'true' ' and dataset not in genma_pacman_hook_auto_snapshot_datasets and ansible_facts[' 'os_family' '] | lower == ' 'archlinux' ''
2025-04-03 00:12:58 +02:00
loop_control :
loop_var : 'dataset'
index_var : 'i'
2025-12-18 23:25:42 +01:00
label : 'If incorrectly marked for auto-snapshotting - {% if genma_pacman_hook_auto_snapshot_datasets_actual[' 'results' '][i][' 'stdout_lines' '] | first == ' 'true' ' and dataset not in genma_pacman_hook_auto_snapshot_datasets %}⚠️{% else %}✅{% endif %} expected {% if dataset not in genma_pacman_hook_auto_snapshot_datasets %} no{% else %}yes{% endif %}/was actually {% if genma_pacman_hook_auto_snapshot_datasets_actual[' 'results' '][i][' 'stdout_lines' '] | first == ' 'true' ' %}yes{% else %} no{% endif %} - unmark ZFS dataset ' '{{ dataset }}' ''
loop : '{{ genma_pacman_hook_auto_snapshot_datasets_list.stdout_lines }}'
2025-04-03 00:12:58 +02:00
ansible.builtin.shell : |
zfs inherit space.quico:auto-snapshot '{{ dataset }}'