9 Commits
1.0.1 ... main

Author SHA1 Message Date
fa17ef7475 refactor(role): Add 'system' tag to be in line with role name 2025-12-18 23:29:28 +01:00
66fd514a7f refactor(role): Rename variables to be in line with role name 2025-12-18 23:25:42 +01:00
11703c081e refactor(role): Rename role to better reflect non-VM use cases 2025-12-18 23:21:42 +01:00
6ed5c0c30a fix(role): Add pacman options to correct config section
Without an [options] or similar INI header line pacman config files
in '/etc/pacman.d' can sometimes load incorrectly, for example when
multiple files exist where some of them do and other do not have the
header. We're normalizing our config file here so that it no longer
trips up pacman.
2025-12-18 22:55:06 +01:00
5c3ed1736e refactor(role): systemctl daemon-reload after copy
Since unit files are now copied to '/etc/systemd/system' we should
make sure that systemd sees the newest version of all unit files
before we attempt to enable a timer unit.
2025-06-04 01:28:57 +02:00
023227fff7 refactor(role): No systemctl daemon-reload on Git pull
Since unit files are now copied to '/etc/systemd/system' merely
cloning or pulling a Git repo no longer warrants a systemctl
daemon-reload.
2025-06-04 01:28:12 +02:00
03b371650c refactor(role): Copy unit files instead of symlinking them
On each target machine we're storing the Git repo that has our unit
files underneath '/opt/git'. Prior to this commit we used to place
symlinks from '/etc/systemd/system' into the appropriate '/opt/git'
subdir. On most machines this worked fine, however, on some we
encountered a race condition on system start.

Sometimes '/opt/git' is not the same file system as '/'. If that's
the case chances are that systemd initializes the system and fails to
access a unit file at '/opt/git' because that file system is just
barely not yet visible early in the boot process.

For a timer unit for example this could result in enabling the unit
and upon reboot seeing that the unit no longer existed in systemd's
world view e.g. via 'systemctl list-timers' even though the symlink
at '/etc/systemd/system' still pointed to an '/opt/git' subdir when
inspected manually seconds after boot. journalctl, however, would
clearly confirm that at system initialization the symlink target was
inaccessible.

We could fiddle around with delaying boot until '/opt/git' and its
descendants are visible but the sane solution is to just not rely on
a separate file system for important stuff such as unit files. We now
copy unit files to '/etc/systemd/system' instead of symlinking them.
2025-06-04 01:26:15 +02:00
33e3ebea6f refactor(role): Move pacman pkg cache underneath boot dataset 2025-04-09 03:15:02 +02:00
b21d28587f refactor(role): Typo 2025-04-07 00:25:50 +02:00
7 changed files with 99 additions and 93 deletions

View File

@@ -1,7 +1,7 @@
[//]: # (SPDX-License-Identifier: MIT) [//]: # (SPDX-License-Identifier: MIT)
# Role Name # Role Name
role-service-generic_vm role-service-generic_machine
# Description # Description
@@ -15,26 +15,26 @@ Your target machines must be Linux.
Per [defaults/main.yml](defaults/main.yml) this role comes with a whole host of default variables almost all of which are relevant only to Arch Linux machines as that's what we run ourselves. Feel free to override these with host or group vars. Per [defaults/main.yml](defaults/main.yml) this role comes with a whole host of default variables almost all of which are relevant only to Arch Linux machines as that's what we run ourselves. Feel free to override these with host or group vars.
- `genvm_git_repos_base_dir`: The base directory where we canonically store checked out Git repos. This defaults to `/opt/git`. We use this var to construct subdirectory paths underneath that location. - `genma_git_repos_base_dir`: The base directory where we canonically store checked out Git repos. This defaults to `/opt/git`. We use this var to construct subdirectory paths underneath that location.
- `genvm_pacman_hook_git_base_dir`: On Arch Linux we Git clone [quico.space/quico-os-setup/zfs-pacman-hook](https://quico.space/quico-os-setup/zfs-pacman-hook/src/branch/1-get-base-version-going) into this location. The repo contains package manager hooks that automatically snapshot the root-on-ZFS filesystem that all of our Arch Linux machines are using. - `genma_pacman_hook_git_base_dir`: On Arch Linux we Git clone [quico.space/quico-os-setup/zfs-pacman-hook](https://quico.space/quico-os-setup/zfs-pacman-hook/src/branch/1-get-base-version-going) into this location. The repo contains package manager hooks that automatically snapshot the root-on-ZFS filesystem that all of our Arch Linux machines are using.
- `genvm_pacman_hook_git_branch`: In above repo we're interested in _this_ branch. Can be `main` for example. - `genma_pacman_hook_git_branch`: In above repo we're interested in _this_ branch. Can be `main` for example.
- `genvm_pacman_hook_auto_snapshot_datasets`: Name ZFS datasets that we want to automatically snapshot whenever package manager actions happen. This is a list with one entry by default, `zpool/root/archlinux`. - `genma_pacman_hook_auto_snapshot_datasets`: Name ZFS datasets that we want to automatically snapshot whenever package manager actions happen. This is a list with one entry by default, `zpool/root/archlinux`.
The following four plus four vars deal with Git cloning firstly, a repo with a script that detects the need to a system reboot on Arch Linux and secondly, a repo that automatically does unattended package upgrades. They follow the same pattern. The following four plus four vars deal with Git cloning firstly, a repo with a script that detects the need to a system reboot on Arch Linux and secondly, a repo that automatically does unattended package upgrades. They follow the same pattern.
## Arch Linux reboot detection ## Arch Linux reboot detection
- `genvm_os_needs_restart_git_repo`: Git clone from this location - `genma_os_needs_restart_git_repo`: Git clone from this location
- `genvm_os_needs_restart_git_base_dir`: Git clone into this base dir - `genma_os_needs_restart_git_base_dir`: Git clone into this base dir
- `genvm_os_needs_restart_git_branch`: Check out this branch - `genma_os_needs_restart_git_branch`: Check out this branch
- `genvm_os_needs_restart_git_clone_dir`: Git clone into this exact dir (constructed from both `genvm_os_needs_restart_git_base_dir` and the branch we want). - `genma_os_needs_restart_git_clone_dir`: Git clone into this exact dir (constructed from both `genma_os_needs_restart_git_base_dir` and the branch we want).
## Arch Linux unattended package upgrades ## Arch Linux unattended package upgrades
- `genvm_os_auto_upgrades_git_repo`: Git clone from this location - `genma_os_auto_upgrades_git_repo`: Git clone from this location
- `genvm_os_auto_upgrades_git_base_dir`: Git clone into this base dir - `genma_os_auto_upgrades_git_base_dir`: Git clone into this base dir
- `genvm_os_auto_upgrades_git_branch`: Check out this branch - `genma_os_auto_upgrades_git_branch`: Check out this branch
- `genvm_os_auto_upgrades_git_clone_dir`: Git clone into this exact dir (constructed from both `genvm_os_auto_upgrades_git_base_dir` and the branch we want). - `genma_os_auto_upgrades_git_clone_dir`: Git clone into this exact dir (constructed from both `genma_os_auto_upgrades_git_base_dir` and the branch we want).
# Dependencies # Dependencies
@@ -48,7 +48,7 @@ In your `playbook.yml` call it like so:
- name: 'Awesome playbook' - name: 'Awesome playbook'
hosts: all hosts: all
roles: roles:
- 'role-service-generic_vm' - 'role-service-generic_machine'
``` ```
# License # License

View File

@@ -1,14 +1,14 @@
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
genvm_git_repos_base_dir: '/opt/git' genma_git_repos_base_dir: '/opt/git'
genvm_pacman_hook_git_base_dir: '/opt/git/quico.space/quico-os-setup/zfs-pacman-hook/branches' genma_pacman_hook_git_base_dir: '/opt/git/quico.space/quico-os-setup/zfs-pacman-hook/branches'
genvm_pacman_hook_git_branch: '1-get-base-version-going' genma_pacman_hook_git_branch: '1-get-base-version-going'
genvm_pacman_hook_auto_snapshot_datasets: genma_pacman_hook_auto_snapshot_datasets:
- 'zpool/root/archlinux' - 'zpool/root/archlinux'
genvm_os_needs_restart_git_repo: 'https://quico.space/quico-os-setup/arch-needs-restart' genma_os_needs_restart_git_repo: 'https://quico.space/quico-os-setup/arch-needs-restart'
genvm_os_needs_restart_git_base_dir: '{{ genvm_git_repos_base_dir }}/{{ genvm_os_needs_restart_git_repo | regex_search(''(.*?://)([^\r\n\f]+)'', ''\2'') | first }}' genma_os_needs_restart_git_base_dir: '{{ genma_git_repos_base_dir }}/{{ genma_os_needs_restart_git_repo | regex_search(''(.*?://)([^\r\n\f]+)'', ''\2'') | first }}'
genvm_os_needs_restart_git_branch: 'main' genma_os_needs_restart_git_branch: 'main'
genvm_os_needs_restart_git_clone_dir: '{{ genvm_os_needs_restart_git_base_dir }}/branches/{{ genvm_os_needs_restart_git_branch }}' genma_os_needs_restart_git_clone_dir: '{{ genma_os_needs_restart_git_base_dir }}/branches/{{ genma_os_needs_restart_git_branch }}'
genvm_os_auto_upgrades_git_repo: 'https://quico.space/quico-os-setup/arch-linux-update-and-restart' genma_os_auto_upgrades_git_repo: 'https://quico.space/quico-os-setup/arch-linux-update-and-restart'
genvm_os_auto_upgrades_git_base_dir: '{{ genvm_git_repos_base_dir }}/{{ genvm_os_auto_upgrades_git_repo | regex_search(''(.*?://)([^\r\n\f]+)'', ''\2'') | first }}' genma_os_auto_upgrades_git_base_dir: '{{ genma_git_repos_base_dir }}/{{ genma_os_auto_upgrades_git_repo | regex_search(''(.*?://)([^\r\n\f]+)'', ''\2'') | first }}'
genvm_os_auto_upgrades_git_branch: 'main' genma_os_auto_upgrades_git_branch: 'main'
genvm_os_auto_upgrades_git_clone_dir: '{{ genvm_os_auto_upgrades_git_base_dir }}/branches/{{ genvm_os_auto_upgrades_git_branch }}' genma_os_auto_upgrades_git_clone_dir: '{{ genma_os_auto_upgrades_git_base_dir }}/branches/{{ genma_os_auto_upgrades_git_branch }}'

View File

@@ -1,5 +1,6 @@
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
[options]
ILoveCandy ILoveCandy
Color Color
ParallelDownloads = 20 ParallelDownloads = 20
NoExtract = etc/pacman.d/mirrorlist NoExtract = etc/pacman.d/mirrorlist

View File

@@ -5,5 +5,6 @@ galaxy_info:
license: MIT license: MIT
min_ansible_version: 2.18.1 min_ansible_version: 2.18.1
galaxy_tags: galaxy_tags:
- 'system'
- 'vm' - 'vm'
dependencies: [] dependencies: []

View File

@@ -2,60 +2,64 @@
- name: 'If Arch Linux create dir to Git clone repo for restart detection' - name: 'If Arch Linux create dir to Git clone repo for restart detection'
when: 'ansible_facts[''os_family''] | lower == ''archlinux''' when: 'ansible_facts[''os_family''] | lower == ''archlinux'''
ansible.builtin.file: ansible.builtin.file:
path: '{{ genvm_os_needs_restart_git_clone_dir }}' path: '{{ genma_os_needs_restart_git_clone_dir }}'
state: 'directory' state: 'directory'
- name: 'If Arch Linux Git clone repo for restart detection' - name: 'If Arch Linux Git clone repo for restart detection'
when: 'ansible_facts[''os_family''] | lower == ''archlinux''' when: 'ansible_facts[''os_family''] | lower == ''archlinux'''
ansible.builtin.git: ansible.builtin.git:
repo: '{{ genvm_os_needs_restart_git_repo }}' repo: '{{ genma_os_needs_restart_git_repo }}'
dest: '{{ genvm_os_needs_restart_git_clone_dir }}' dest: '{{ genma_os_needs_restart_git_clone_dir }}'
version: '{{ genvm_os_needs_restart_git_branch }}' version: '{{ genma_os_needs_restart_git_branch }}'
- name: 'If Arch Linux create symlinks to repo for restart detection' - name: 'If Arch Linux create symlinks to repo for restart detection'
when: 'ansible_facts[''os_family''] | lower == ''archlinux''' when: 'ansible_facts[''os_family''] | lower == ''archlinux'''
loop_control: loop_control:
loop_var: 'genvm_os_needs_restart_symlink' loop_var: 'genma_os_needs_restart_symlink'
label: 'Create symlink to ''{{ genvm_os_needs_restart_symlink.target | basename }}''' label: 'Create symlink to ''{{ genma_os_needs_restart_symlink.target | basename }}'''
loop: loop:
- { target: '{{ genvm_os_needs_restart_git_clone_dir }}/arch-needs-restart.sh', symlink: '/usr/local/bin/arch-needs-restart' } - { target: '{{ genma_os_needs_restart_git_clone_dir }}/arch-needs-restart.sh', symlink: '/usr/local/bin/arch-needs-restart' }
- { target: '{{ genvm_os_needs_restart_git_clone_dir }}/arch-needs-restart.hook', symlink: '/usr/share/libalpm/hooks/arch-needs-restart.hook' } - { target: '{{ genma_os_needs_restart_git_clone_dir }}/arch-needs-restart.hook', symlink: '/usr/share/libalpm/hooks/arch-needs-restart.hook' }
ansible.builtin.file: ansible.builtin.file:
src: '{{ genvm_os_needs_restart_symlink.target }}' src: '{{ genma_os_needs_restart_symlink.target }}'
dest: '{{ genvm_os_needs_restart_symlink.symlink }}' dest: '{{ genma_os_needs_restart_symlink.symlink }}'
state: 'link' state: 'link'
force: true force: true
- name: 'If Arch Linux create dir to Git clone repo for OS auto-upgrades' - name: 'If Arch Linux create dir to Git clone repo for OS auto-upgrades'
when: 'ansible_facts[''os_family''] | lower == ''archlinux''' when: 'ansible_facts[''os_family''] | lower == ''archlinux'''
ansible.builtin.file: ansible.builtin.file:
path: '{{ genvm_os_auto_upgrades_git_clone_dir }}' path: '{{ genma_os_auto_upgrades_git_clone_dir }}'
state: 'directory' state: 'directory'
- name: 'If Arch Linux Git clone repo for OS auto-upgrades' - name: 'If Arch Linux Git clone repo for OS auto-upgrades'
when: 'ansible_facts[''os_family''] | lower == ''archlinux''' when: 'ansible_facts[''os_family''] | lower == ''archlinux'''
ansible.builtin.git: ansible.builtin.git:
repo: '{{ genvm_os_auto_upgrades_git_repo }}' repo: '{{ genma_os_auto_upgrades_git_repo }}'
dest: '{{ genvm_os_auto_upgrades_git_clone_dir }}' dest: '{{ genma_os_auto_upgrades_git_clone_dir }}'
version: '{{ genvm_os_auto_upgrades_git_branch }}' version: '{{ genma_os_auto_upgrades_git_branch }}'
- name: 'If Arch Linux copy systemd unit files for OS auto-upgrades to ''/etc/systemd/system'''
when: 'ansible_facts[''os_family''] | lower == ''archlinux'''
loop_control:
loop_var: 'genma_os_auto_upgrades_unit'
label: 'Copy ''{{ genma_os_auto_upgrades_unit.source | basename }}'' to ''/etc/systemd/system'''
loop:
- { source: '{{ genma_os_auto_upgrades_git_clone_dir }}/arch-linux-update-and-restart.service', target: '/etc/systemd/system/arch-linux-update-and-restart.service' }
- { source: '{{ genma_os_auto_upgrades_git_clone_dir }}/arch-linux-update-and-restart.timer', target: '/etc/systemd/system/arch-linux-update-and-restart.timer' }
ansible.builtin.copy:
src: '{{ genma_os_auto_upgrades_unit.source }}'
dest: '{{ genma_os_auto_upgrades_unit.target }}'
remote_src: true
notify: notify:
- 'Reload systemd unit configs' - 'Reload systemd unit configs'
- name: 'If Arch Linux create symlinks to repo for OS auto-upgrades' # Chances are we've just updated systemd unit files in '/etc/systemd/system'. In
when: 'ansible_facts[''os_family''] | lower == ''archlinux''' # a second we'll be enabling a timer unit that was among those files we just
loop_control: # (potentially) changed. We should flush our handlers now, i.e. 'systemctl
loop_var: 'genvm_os_auto_upgrades_symlink' # daemon-reload' to make sure systemd knows the newest state of our units.
label: 'Create symlink to ''{{ genvm_os_auto_upgrades_symlink.target | basename }}''' - name: 'Flush handlers'
loop: meta: flush_handlers
- { target: '{{ genvm_os_auto_upgrades_git_clone_dir }}/arch-linux-update-and-restart.service', symlink: '/etc/systemd/system/arch-linux-update-and-restart.service' }
- { target: '{{ genvm_os_auto_upgrades_git_clone_dir }}/arch-linux-update-and-restart.timer', symlink: '/etc/systemd/system/arch-linux-update-and-restart.timer' }
ansible.builtin.file:
src: '{{ genvm_os_auto_upgrades_symlink.target }}'
dest: '{{ genvm_os_auto_upgrades_symlink.symlink }}'
state: 'link'
force: true
notify:
- 'Reload systemd unit configs'
- name: 'If Arch Linux enable systemd timer for OS auto-upgrades' - name: 'If Arch Linux enable systemd timer for OS auto-upgrades'
ansible.builtin.systemd_service: ansible.builtin.systemd_service:

View File

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

View File

@@ -1,28 +1,28 @@
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
- name: 'Check if ZFS functional' - name: 'Check if ZFS functional'
register: 'genvm_archlinux_zfs_pacman_cache_os_has_functional_zfs' register: 'genma_archlinux_zfs_pacman_cache_os_has_functional_zfs'
changed_when: false changed_when: false
failed_when: false failed_when: false
ansible.builtin.shell: | ansible.builtin.shell: |
zpool list zpool list
- name: 'If ZFS functional check if pacman cache dataset exists' - name: 'If ZFS functional check if pacman cache dataset exists'
when: 'genvm_archlinux_zfs_pacman_cache_os_has_functional_zfs.rc == 0' when: 'genma_archlinux_zfs_pacman_cache_os_has_functional_zfs.rc == 0'
register: 'genvm_archlinux_zfs_pacman_cache_zfs_has_pacman_cache_dataset' register: 'genma_archlinux_zfs_pacman_cache_zfs_has_pacman_cache_dataset'
changed_when: false changed_when: false
failed_when: false failed_when: false
ansible.builtin.shell: | ansible.builtin.shell: |
zfs list zpool/data/var/cache/pacman/pkg zfs list zpool/root/archlinux/var/cache/pacman/pkg
- name: 'If no pacman cache dataset exists create dataset' - name: 'If no pacman cache dataset exists create dataset'
when: 'genvm_archlinux_zfs_pacman_cache_zfs_has_pacman_cache_dataset.rc > 0' when: 'genma_archlinux_zfs_pacman_cache_zfs_has_pacman_cache_dataset.rc > 0'
register: 'genvm_archlinux_zfs_pacman_cache_pacman_cache_dir_was_temp_moved' register: 'genma_archlinux_zfs_pacman_cache_pacman_cache_dir_was_temp_moved'
changed_when: 'genvm_archlinux_zfs_pacman_cache_pacman_cache_dir_was_temp_moved.rc == 0' changed_when: 'genma_archlinux_zfs_pacman_cache_pacman_cache_dir_was_temp_moved.rc == 0'
ansible.builtin.shell: | ansible.builtin.shell: |
mv '/var/cache/pacman/pkg'{,'.bak'} && \ mv '/var/cache/pacman/pkg'{,'.bak'} && \
if ! zfs list zpool/data/var &>/dev/null; then zfs create -o canmount=off zpool/data/var; fi && \ if ! zfs list zpool/root/archlinux/var &>/dev/null; then zfs create -o canmount=off zpool/root/archlinux/var; fi && \
if ! zfs list zpool/data/var/cache &>/dev/null; then zfs create -o canmount=off zpool/data/var/cache; fi && \ if ! zfs list zpool/root/archlinux/var/cache &>/dev/null; then zfs create -o canmount=off zpool/root/archlinux/var/cache; fi && \
if ! zfs list zpool/data/var/cache/pacman &>/dev/null; then zfs create -o canmount=off zpool/data/var/cache/pacman; fi && \ if ! zfs list zpool/root/archlinux/var/cache/pacman &>/dev/null; then zfs create -o canmount=off zpool/root/archlinux/var/cache/pacman; fi && \
zfs create zpool/data/var/cache/pacman/pkg && \ zfs create zpool/root/archlinux/var/cache/pacman/pkg && \
rsync -a --remove-source-files '/var/cache/pacman/pkg'{'.bak',}'/' && \ rsync -a --remove-source-files '/var/cache/pacman/pkg'{'.bak',}'/' && \
find '/var/cache/pacman/pkg.bak' -type d -empty -delete find '/var/cache/pacman/pkg.bak' -type d -empty -delete