mirror of
https://github.com/fscotto/infra.git
synced 2026-11-26 05:39:52 +00:00
Add Atlas qBittorrent service configuration
This commit is contained in:
@@ -257,3 +257,7 @@ host_enabled_services:
|
||||
- cockpit.socket
|
||||
- pmlogger.service
|
||||
- zfs.target
|
||||
|
||||
# LAN-only torrent Web UI; downloads use the home Internet connection.
|
||||
atlas_manage_qbittorrent: true
|
||||
atlas_qbittorrent_image: docker.io/qbittorrentofficial/qbittorrent-nox@sha256:92bfd78d731e254ba64f62b77b0696add6447a33642ee5feda106a26b285aa7f
|
||||
|
||||
@@ -297,3 +297,9 @@ atlas_media_quadlet_services:
|
||||
- atlas-immich-machine-learning.service
|
||||
- atlas-immich-server.service
|
||||
- atlas-npm.service
|
||||
|
||||
atlas_manage_qbittorrent: false
|
||||
atlas_qbittorrent_image: CHANGEME_PINNED_QBITTORRENT_IMAGE
|
||||
atlas_qbittorrent_state_dir: "{{ atlas_app_data_mountpoint }}/qbittorrent"
|
||||
atlas_qbittorrent_downloads_dir: "{{ atlas_archive_mountpoint }}/Downloads"
|
||||
atlas_qbittorrent_web_port: 8090
|
||||
|
||||
@@ -26,6 +26,9 @@
|
||||
- name: Import Atlas iCloudPD storage and boot-started Quadlet tasks
|
||||
ansible.builtin.import_tasks: icloudpd.yml
|
||||
|
||||
- name: Import Atlas torrent service
|
||||
ansible.builtin.import_tasks: qbittorrent.yml
|
||||
|
||||
- name: Import Atlas ZFS maintenance tasks
|
||||
ansible.builtin.import_tasks: zfs_maintenance.yml
|
||||
|
||||
|
||||
124
ansible/roles/profile_atlas/tasks/qbittorrent.yml
Normal file
124
ansible/roles/profile_atlas/tasks/qbittorrent.yml
Normal file
@@ -0,0 +1,124 @@
|
||||
---
|
||||
- name: Manage Atlas rootless qBittorrent
|
||||
tags: [atlas, qbittorrent]
|
||||
when: atlas_manage_qbittorrent | bool
|
||||
block:
|
||||
- name: Require isolated paths and a pinned image
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- atlas_manage_storage | bool
|
||||
- atlas_qbittorrent_state_dir == atlas_app_data_mountpoint ~ '/qbittorrent'
|
||||
- atlas_qbittorrent_downloads_dir == atlas_archive_mountpoint ~ '/Downloads'
|
||||
- atlas_qbittorrent_image is search('@sha256:[0-9a-f]{64}$')
|
||||
|
||||
- name: Inspect the existing parent datasets
|
||||
community.general.zfs_facts:
|
||||
name: "{{ item.dataset }}"
|
||||
properties: name,mounted,mountpoint
|
||||
loop:
|
||||
- dataset: "{{ atlas_zfs_pool }}/{{ atlas_zfs_dataset_archive }}"
|
||||
mountpoint: "{{ atlas_archive_mountpoint }}"
|
||||
- dataset: "{{ atlas_zfs_pool }}/{{ atlas_zfs_dataset_app_data }}"
|
||||
mountpoint: "{{ atlas_app_data_mountpoint }}"
|
||||
register: atlas_qbittorrent_parents
|
||||
|
||||
- name: Refuse missing or unmounted parent datasets
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- item.ansible_facts.ansible_zfs_datasets | length == 1
|
||||
- item.ansible_facts.ansible_zfs_datasets[0].mounted == 'yes'
|
||||
- item.ansible_facts.ansible_zfs_datasets[0].mountpoint == item.item.mountpoint
|
||||
loop: "{{ atlas_qbittorrent_parents.results }}"
|
||||
loop_control:
|
||||
label: "{{ item.item.dataset }}"
|
||||
|
||||
- name: Inspect the proposed download directory without following links
|
||||
ansible.builtin.stat:
|
||||
path: "{{ atlas_qbittorrent_downloads_dir }}"
|
||||
follow: false
|
||||
register: atlas_qbittorrent_downloads
|
||||
|
||||
- name: Refuse unrelated or symlinked download paths
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- >-
|
||||
not atlas_qbittorrent_downloads.stat.exists or
|
||||
(atlas_qbittorrent_downloads.stat.isdir | default(false) and
|
||||
atlas_qbittorrent_downloads.stat.uid | int == atlas_admin_uid | int)
|
||||
|
||||
- name: Create the dedicated configuration dataset
|
||||
community.general.zfs:
|
||||
name: "{{ atlas_zfs_pool }}/services/data/qbittorrent"
|
||||
state: present
|
||||
extra_zfs_properties:
|
||||
compression: zstd
|
||||
mountpoint: "{{ atlas_qbittorrent_state_dir }}"
|
||||
|
||||
- name: Prepare private state and the SMB download directory
|
||||
ansible.builtin.file:
|
||||
path: "{{ item.path }}"
|
||||
state: directory
|
||||
owner: "{{ atlas_admin_username }}"
|
||||
group: "{{ atlas_admin_group }}"
|
||||
mode: "{{ item.mode }}"
|
||||
loop:
|
||||
- {path: "{{ atlas_qbittorrent_state_dir }}", mode: "0700"}
|
||||
- {path: "{{ atlas_qbittorrent_state_dir }}/qBittorrent/config", mode: "0700"}
|
||||
- {path: "{{ atlas_qbittorrent_downloads_dir }}", mode: "0770"}
|
||||
- {path: "{{ atlas_admin_home }}/.config/containers/systemd", mode: "0700"}
|
||||
|
||||
- name: Seed qBittorrent settings without overwriting application-managed state
|
||||
ansible.builtin.template:
|
||||
src: atlas-qbittorrent.conf.j2
|
||||
dest: "{{ atlas_qbittorrent_state_dir }}/qBittorrent/config/qBittorrent.conf"
|
||||
owner: "{{ atlas_admin_username }}"
|
||||
group: "{{ atlas_admin_group }}"
|
||||
mode: "0600"
|
||||
force: false
|
||||
diff: false
|
||||
|
||||
- name: Allow only the declared LAN to reach the Web UI
|
||||
ansible.posix.firewalld:
|
||||
zone: "{{ atlas_firewalld_zone }}"
|
||||
rich_rule: >-
|
||||
rule family="ipv4" source address="{{ atlas_lan_subnet }}"
|
||||
port port="{{ atlas_qbittorrent_web_port }}" protocol="tcp" accept
|
||||
permanent: true
|
||||
immediate: true
|
||||
state: enabled
|
||||
|
||||
- name: Keep the rootless user manager available at boot
|
||||
ansible.builtin.command: "loginctl enable-linger {{ atlas_admin_username }}"
|
||||
args:
|
||||
creates: "/var/lib/systemd/linger/{{ atlas_admin_username }}"
|
||||
|
||||
- name: Render the rootless torrent Quadlet
|
||||
ansible.builtin.template:
|
||||
src: atlas-qbittorrent.container.j2
|
||||
dest: "{{ atlas_admin_home }}/.config/containers/systemd/atlas-qbittorrent.container"
|
||||
owner: "{{ atlas_admin_username }}"
|
||||
group: "{{ atlas_admin_group }}"
|
||||
mode: "0644"
|
||||
register: atlas_qbittorrent_quadlet
|
||||
|
||||
- name: Start qBittorrent and restart only after a Quadlet change
|
||||
become_user: "{{ atlas_admin_username }}"
|
||||
ansible.builtin.systemd:
|
||||
name: atlas-qbittorrent.service
|
||||
scope: user
|
||||
daemon_reload: "{{ atlas_qbittorrent_quadlet.changed }}"
|
||||
state: "{{ 'restarted' if atlas_qbittorrent_quadlet.changed else 'started' }}"
|
||||
environment:
|
||||
XDG_RUNTIME_DIR: "/run/user/{{ atlas_admin_uid }}"
|
||||
DBUS_SESSION_BUS_ADDRESS: "unix:path=/run/user/{{ atlas_admin_uid }}/bus"
|
||||
when: not ansible_check_mode
|
||||
|
||||
- name: Verify the Web UI responds on the LAN address
|
||||
ansible.builtin.uri:
|
||||
url: "http://{{ ansible_host }}:{{ atlas_qbittorrent_web_port }}/"
|
||||
status_code: 200
|
||||
register: atlas_qbittorrent_http
|
||||
retries: 15
|
||||
delay: 2
|
||||
until: atlas_qbittorrent_http is succeeded
|
||||
when: not ansible_check_mode
|
||||
@@ -0,0 +1,17 @@
|
||||
; Seeded once by Ansible. Subsequent settings are managed through the Web UI.
|
||||
[BitTorrent]
|
||||
Session\DefaultSavePath=/downloads
|
||||
Session\TempPath=/downloads/.incomplete
|
||||
Session\TempPathEnabled=true
|
||||
Session\Port=6881
|
||||
[Meta]
|
||||
MigrationVersion=9999
|
||||
[Network]
|
||||
PortForwardingEnabled=false
|
||||
[Preferences]
|
||||
WebUI\Port={{ atlas_qbittorrent_web_port }}
|
||||
WebUI\LocalHostAuth=true
|
||||
WebUI\AuthSubnetWhitelistEnabled=false
|
||||
WebUI\CSRFProtection=true
|
||||
WebUI\ClickjackingProtection=true
|
||||
WebUI\HostHeaderValidation=true
|
||||
@@ -0,0 +1,33 @@
|
||||
# Managed by Ansible. No VPN, host networking or router port forwarding.
|
||||
[Unit]
|
||||
Description=Atlas rootless qBittorrent
|
||||
RequiresMountsFor={{ atlas_qbittorrent_state_dir }} {{ atlas_qbittorrent_downloads_dir }}
|
||||
|
||||
[Container]
|
||||
ContainerName=atlas-qbittorrent
|
||||
Image={{ atlas_qbittorrent_image }}
|
||||
UserNS=keep-id
|
||||
User={{ atlas_admin_uid }}
|
||||
Group={{ atlas_admin_gid }}
|
||||
PublishPort={{ ansible_host }}:{{ atlas_qbittorrent_web_port }}:{{ atlas_qbittorrent_web_port }}
|
||||
Environment=QBT_LEGAL_NOTICE=confirm
|
||||
Environment=QBT_WEBUI_PORT={{ atlas_qbittorrent_web_port }}
|
||||
Environment=XDG_CACHE_HOME=/tmp/cache
|
||||
Environment=TZ={{ atlas_timezone }}
|
||||
Environment=UMASK=007
|
||||
Volume={{ atlas_qbittorrent_state_dir }}:/config:Z
|
||||
Volume={{ atlas_qbittorrent_downloads_dir }}:/downloads:z
|
||||
ReadOnly=true
|
||||
Tmpfs=/tmp:rw,nosuid,nodev
|
||||
NoNewPrivileges=true
|
||||
DropCapability=all
|
||||
StopTimeout=1800
|
||||
|
||||
[Service]
|
||||
Restart=on-failure
|
||||
RestartSec=10
|
||||
TimeoutStartSec=900
|
||||
TimeoutStopSec=1900
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
Reference in New Issue
Block a user