mirror of
https://github.com/fscotto/infra.git
synced 2026-11-26 13:49:52 +00:00
Compare commits
2 Commits
bde34e19f4
...
e99bcc688e
| Author | SHA1 | Date | |
|---|---|---|---|
| e99bcc688e | |||
| 775840d3ef |
@@ -8,6 +8,9 @@ gemini_cli_deploy_enabled: false
|
|||||||
gemini_cli_uninstall_enabled: true
|
gemini_cli_uninstall_enabled: true
|
||||||
chatgpt_desktop_enabled: true
|
chatgpt_desktop_enabled: true
|
||||||
desktop_ai_media_enabled: true
|
desktop_ai_media_enabled: true
|
||||||
|
desktop_ai_media_external_storage_enabled: true
|
||||||
|
desktop_ai_media_external_mountpoint: /run/media/fscotto/Backup
|
||||||
|
desktop_ai_media_external_source: /run/media/fscotto/Backup/ai-media
|
||||||
|
|
||||||
host_packages:
|
host_packages:
|
||||||
- podman
|
- podman
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
desktop_ai_media_enabled: false
|
desktop_ai_media_enabled: false
|
||||||
desktop_ai_media_root: "{{ user_home }}/.local/share/ai-media"
|
desktop_ai_media_root: "{{ user_home }}/.local/share/ai-media"
|
||||||
desktop_ai_media_build_root: "{{ user_home }}/.local/share/ai-media-build"
|
desktop_ai_media_build_root: "{{ user_home }}/.local/share/ai-media-build"
|
||||||
|
desktop_ai_media_external_storage_enabled: false
|
||||||
|
desktop_ai_media_external_mountpoint: ""
|
||||||
|
desktop_ai_media_external_source: ""
|
||||||
desktop_ai_media_debian_snapshot: "20261013T000000Z"
|
desktop_ai_media_debian_snapshot: "20261013T000000Z"
|
||||||
desktop_ai_media_base_image: >-
|
desktop_ai_media_base_image: >-
|
||||||
docker.io/library/python@sha256:34386ef0cb081344d7ec1c103ba398e6e9f64e9ab3a1509accc92a4e24a07258
|
docker.io/library/python@sha256:34386ef0cb081344d7ec1c103ba398e6e9f64e9ab3a1509accc92a4e24a07258
|
||||||
|
|||||||
@@ -15,12 +15,23 @@ for line in pathlib.Path("/proc/self/mountinfo").read_text().splitlines():
|
|||||||
fields, description = line.split(" - ", 1)
|
fields, description = line.split(" - ", 1)
|
||||||
mount = re.sub(r"\\([0-7]{3})", lambda m: chr(int(m[1], 8)), fields.split()[4])
|
mount = re.sub(r"\\([0-7]{3})", lambda m: chr(int(m[1], 8)), fields.split()[4])
|
||||||
mounts.append((pathlib.Path(mount), description.split()[0]))
|
mounts.append((pathlib.Path(mount), description.split()[0]))
|
||||||
covering = [(p, kind) for p, kind in mounts if root == p or root.is_relative_to(p)]
|
automount_at_root = any(p == root and kind == "autofs" for p, kind in mounts)
|
||||||
|
backing_mount_at_root = any(
|
||||||
|
p == root and kind != "autofs" for p, kind in mounts
|
||||||
|
)
|
||||||
|
if automount_at_root and not backing_mount_at_root:
|
||||||
|
raise SystemExit("Media storage automount is not active; refusing to start")
|
||||||
|
covering = [
|
||||||
|
(p, kind) for p, kind in mounts
|
||||||
|
if kind != "autofs" and (root == p or root.is_relative_to(p))
|
||||||
|
]
|
||||||
if covering:
|
if covering:
|
||||||
selected = max(covering, key=lambda entry: len(entry[0].parts))
|
selected = max(covering, key=lambda entry: len(entry[0].parts))
|
||||||
if selected[1] not in local_filesystems:
|
if selected[1] not in local_filesystems:
|
||||||
raise SystemExit("Media storage is not on a local filesystem; refusing to start")
|
raise SystemExit("Media storage is not on a local filesystem; refusing to start")
|
||||||
for mount, kind in mounts:
|
for mount, kind in mounts:
|
||||||
|
if mount == root and kind == "autofs":
|
||||||
|
continue
|
||||||
if mount.is_relative_to(root) and kind not in local_filesystems:
|
if mount.is_relative_to(root) and kind not in local_filesystems:
|
||||||
raise SystemExit("Non-local mount beneath media storage; refusing to start")
|
raise SystemExit("Non-local mount beneath media storage; refusing to start")
|
||||||
sync_roots = []
|
sync_roots = []
|
||||||
|
|||||||
4
ansible/roles/desktop_ai_media/handlers/main.yml
Normal file
4
ansible/roles/desktop_ai_media/handlers/main.yml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
- name: Reload systemd units
|
||||||
|
ansible.builtin.systemd_service:
|
||||||
|
daemon_reload: true
|
||||||
@@ -1,4 +1,103 @@
|
|||||||
---
|
---
|
||||||
|
- name: Configure on-demand external ai-media storage
|
||||||
|
become: true
|
||||||
|
when: desktop_ai_media_external_storage_enabled | bool
|
||||||
|
tags: [ai_media, ai_media_storage]
|
||||||
|
block:
|
||||||
|
- name: Validate external ai-media storage paths
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- desktop_ai_media_external_mountpoint is match('^/run/media/[^/]+/[^/]+$')
|
||||||
|
- desktop_ai_media_external_source.startswith(desktop_ai_media_external_mountpoint + '/')
|
||||||
|
- desktop_ai_media_external_source != desktop_ai_media_external_mountpoint
|
||||||
|
- desktop_ai_media_root.startswith(user_home + '/')
|
||||||
|
- desktop_ai_media_root != user_home
|
||||||
|
|
||||||
|
- name: Derive external source mount unit name
|
||||||
|
ansible.builtin.command:
|
||||||
|
argv:
|
||||||
|
- systemd-escape
|
||||||
|
- -p
|
||||||
|
- --suffix=mount
|
||||||
|
- "{{ desktop_ai_media_external_mountpoint }}"
|
||||||
|
register: desktop_ai_media_external_source_mount_unit
|
||||||
|
changed_when: false
|
||||||
|
check_mode: false
|
||||||
|
|
||||||
|
- name: Derive ai-media bind mount unit name
|
||||||
|
ansible.builtin.command:
|
||||||
|
argv:
|
||||||
|
- systemd-escape
|
||||||
|
- -p
|
||||||
|
- --suffix=mount
|
||||||
|
- "{{ desktop_ai_media_root }}"
|
||||||
|
register: desktop_ai_media_bind_mount_unit
|
||||||
|
changed_when: false
|
||||||
|
check_mode: false
|
||||||
|
|
||||||
|
- name: Derive ai-media bind automount unit name
|
||||||
|
ansible.builtin.command:
|
||||||
|
argv:
|
||||||
|
- systemd-escape
|
||||||
|
- -p
|
||||||
|
- --suffix=automount
|
||||||
|
- "{{ desktop_ai_media_root }}"
|
||||||
|
register: desktop_ai_media_bind_automount_unit
|
||||||
|
changed_when: false
|
||||||
|
check_mode: false
|
||||||
|
|
||||||
|
- name: Create ai-media mount destination in the user home
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ desktop_ai_media_root }}"
|
||||||
|
state: directory
|
||||||
|
owner: "{{ username }}"
|
||||||
|
group: "{{ username }}"
|
||||||
|
mode: "0700"
|
||||||
|
|
||||||
|
- name: Install ai-media bind mount unit
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: ai-media-bind.mount.j2
|
||||||
|
dest: "/etc/systemd/system/{{ desktop_ai_media_bind_mount_unit.stdout }}"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0644"
|
||||||
|
notify: Reload systemd units
|
||||||
|
|
||||||
|
- name: Install ai-media bind automount unit
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: ai-media-bind.automount.j2
|
||||||
|
dest: "/etc/systemd/system/{{ desktop_ai_media_bind_automount_unit.stdout }}"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0644"
|
||||||
|
notify: Reload systemd units
|
||||||
|
|
||||||
|
- name: Install ai-media bind automount failure restarter
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: ai-media-bind-restarter.service.j2
|
||||||
|
dest: /etc/systemd/system/ai-media-bind-restarter.service
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0644"
|
||||||
|
notify: Reload systemd units
|
||||||
|
|
||||||
|
- name: Flush systemd unit changes
|
||||||
|
ansible.builtin.meta: flush_handlers
|
||||||
|
|
||||||
|
- name: Stop a stale ai-media bind mount when the Backup source is absent
|
||||||
|
ansible.builtin.systemd_service:
|
||||||
|
name: "{{ desktop_ai_media_bind_mount_unit.stdout }}"
|
||||||
|
state: stopped
|
||||||
|
when:
|
||||||
|
- desktop_ai_media_root in (ansible_facts['mounts'] | default([]) | map(attribute='mount') | list)
|
||||||
|
- desktop_ai_media_external_mountpoint not in (ansible_facts['mounts'] | default([]) | map(attribute='mount') | list)
|
||||||
|
|
||||||
|
- name: Enable and start ai-media bind automount
|
||||||
|
ansible.builtin.systemd_service:
|
||||||
|
name: "{{ desktop_ai_media_bind_automount_unit.stdout }}"
|
||||||
|
enabled: true
|
||||||
|
state: started
|
||||||
|
|
||||||
- name: Configure isolated desktop media tools as the desktop user
|
- name: Configure isolated desktop media tools as the desktop user
|
||||||
become: false
|
become: false
|
||||||
block:
|
block:
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Recover the ai-media bind automount after an unavailable Backup volume
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStartPre=/usr/bin/sleep 3
|
||||||
|
ExecStart=/usr/bin/bash -c '/usr/bin/systemctl restart "$(/usr/bin/systemd-escape -p --suffix=automount {{ desktop_ai_media_root }})"'
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=On-demand ai-media bind mount from the Backup LUKS volume
|
||||||
|
ConditionPathIsDirectory={{ desktop_ai_media_root }}
|
||||||
|
OnFailure=ai-media-bind-restarter.service
|
||||||
|
|
||||||
|
[Automount]
|
||||||
|
Where={{ desktop_ai_media_root }}
|
||||||
|
TimeoutIdleSec=5min
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Bind mount ai-media from the Backup LUKS volume
|
||||||
|
RequiresMountsFor={{ desktop_ai_media_external_mountpoint }}
|
||||||
|
After={{ desktop_ai_media_external_source_mount_unit.stdout }}
|
||||||
|
BindsTo={{ desktop_ai_media_external_source_mount_unit.stdout }}
|
||||||
|
ConditionPathIsMountPoint={{ desktop_ai_media_external_mountpoint }}
|
||||||
|
ConditionPathIsDirectory={{ desktop_ai_media_external_source }}
|
||||||
|
|
||||||
|
[Mount]
|
||||||
|
What={{ desktop_ai_media_external_source }}
|
||||||
|
Where={{ desktop_ai_media_root }}
|
||||||
|
Options=bind
|
||||||
Reference in New Issue
Block a user