Update 4 files

- /group_vars/all.yml
- /roles/qbittorrent/tasks/main.yml
- /roles/qbittorrent/templates/docker-compose.yml.j2
- /roles/qbittorrent/templates/smb-credentials.j2
This commit is contained in:
Administrator 2025-12-18 11:31:51 +05:00
parent 1d7dbe9d76
commit 7b686a936c
4 changed files with 79 additions and 158 deletions

View File

@ -203,69 +203,75 @@ ampache_logs_dir: "{{ ampache_base_dir }}/logs"
ampache_mysql_dir: "{{ ampache_base_dir }}/mysql" ampache_mysql_dir: "{{ ampache_base_dir }}/mysql"
ampache_port: "45134" ampache_port: "45134"
qbittorrent_base_dir: "/opt/qbittorrent" qbittorrent_base_dir: "/mnt/service/qbittorrent"
qbittorrent_config_dir: "{{ qbittorrent_base_dir }}/appdata" qbittorrent_config_dir: "{{ qbittorrent_base_dir }}/appdata"
qbittorrent_downloads_dir: "{{ qbittorrent_base_dir }}/downloads" qbittorrent_downloads_dir: "{{ qbittorrent_base_dir }}/downloads"
qbittorrent_puid: 1000 qbittorrent_puid: 1000
qbittorrent_pgid: 1000 qbittorrent_pgid: 1000
qbittorrent_port_webui: 45135 qbittorrent_port_webui: 45135
qbittorrent_port_torrent: 6881 qbittorrent_port_torrent: 6881
qbittorrent_user: "qbittorrent"
qbittorrent_password: "13qeadZC" qbittorrent_password: "13qeadZC"
qbittorrent_smb_credentials_dir: "/etc/smb-creds"
qbittorrent_smb_creds:
olimp:
username: "Olimp"
password: "13qeadZC"
file: "olimp"
qbittorrent_shares: qbittorrent_shares:
# Windows-шара с входящими торрентами
- name: downloads - name: downloads
src: "//192.168.1.101/Downloads" src: "//192.168.1.101/Downloads"
dest: "/mnt/downloads" dest: "/mnt/downloads"
opts: "uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8" credential: "olimp"
opts: "rw,uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8,vers=3.0"
- name: abook - name: abook
src: "//192.168.1.203/Abook" src: "//192.168.1.203/Abook"
dest: "/mnt/video/abook" dest: "/mnt/video/abook"
opts: "uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8" opts: "rw,uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8,vers=3.0,guest"
- name: music - name: music
src: "//192.168.1.203/Music" src: "//192.168.1.203/Music"
dest: "/mnt/audio" dest: "/mnt/audio"
opts: "uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8" opts: "rw,uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8,vers=3.0,guest"
- name: books - name: books
src: "//192.168.1.203/Books" src: "//192.168.1.203/Books"
dest: "/mnt/books" dest: "/mnt/books"
opts: "uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8" opts: "rw,uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8,vers=3.0,guest"
- name: films - name: films
src: "//192.168.1.203/Films" src: "//192.168.1.203/Films"
dest: "/mnt/video/films" dest: "/mnt/video/films"
opts: "uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8" opts: "rw,uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8,vers=3.0,guest"
- name: mult - name: mult
src: "//192.168.1.203/Mult" src: "//192.168.1.203/Mult"
dest: "/mnt/video/mult" dest: "/mnt/video/mult"
opts: "uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8" opts: "rw,uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8,vers=3.0,guest"
- name: anime - name: anime
src: "//192.168.1.203/Anime" src: "//192.168.1.203/Anime"
dest: "/mnt/video/anime" dest: "/mnt/video/anime"
opts: "uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8" opts: "rw,uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8,vers=3.0,guest"
- name: serial - name: serial
src: "//192.168.1.203/Serial" src: "//192.168.1.203/Serial"
dest: "/mnt/video/serial" dest: "/mnt/video/serial"
opts: "uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8" opts: "rw,uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8,vers=3.0,guest"
- name: mserials - name: mserials
src: "//192.168.1.203/Mserials" src: "//192.168.1.203/Mserials"
dest: "/mnt/video/mserials" dest: "/mnt/video/mserials"
opts: "uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8" opts: "rw,uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8,vers=3.0,guest"
- name: doc - name: doc
src: "//192.168.1.203/Doc" src: "//192.168.1.203/Doc"
dest: "/mnt/documents" dest: "/mnt/documents"
opts: "uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8" opts: "rw,uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8,vers=3.0,guest"
- name: ztube - name: ztube
src: "//192.168.1.203/Ztube" src: "//192.168.1.203/Ztube"
dest: "/mnt/video/ztube" dest: "/mnt/video/ztube"
opts: "uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8" opts: "rw,uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8,vers=3.0,guest"
- name: show - name: show
src: "//192.168.1.203/Show" src: "//192.168.1.203/Show"
dest: "/mnt/video/show" dest: "/mnt/video/show"
opts: "uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8" opts: "rw,uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8,vers=3.0,guest"
- name: games - name: games
src: "//192.168.1.207/Games" src: "//192.168.1.207/Games"
dest: "/mnt/games" dest: "/mnt/games"
opts: "uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8" opts: "rw,uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8,vers=3.0,guest"
torrserver_base_dir: "/mnt/service/torrserver" torrserver_base_dir: "/mnt/service/torrserver"
torrserver_config_dir: "{{ torrserver_base_dir }}/config" torrserver_config_dir: "{{ torrserver_base_dir }}/config"

View File

@ -1,166 +1,79 @@
--- ---
- name: Create qBittorrent base and local directories - name: Создание директорий для qBittorrent
file: file:
path: "{{ item }}" path: "{{ item }}"
state: directory state: directory
mode: '0755'
owner: "{{ qbittorrent_puid }}" owner: "{{ qbittorrent_puid }}"
group: "{{ qbittorrent_pgid }}" group: "{{ qbittorrent_pgid }}"
mode: '0755'
loop: loop:
- "{{ qbittorrent_base_dir }}"
- "{{ qbittorrent_config_dir }}" - "{{ qbittorrent_config_dir }}"
- "{{ qbittorrent_downloads_dir }}" - "{{ qbittorrent_downloads_dir }}"
- "/mnt/downloads"
- "/mnt/video"
- "/mnt/video/abook"
- "/mnt/video/films"
- "/mnt/video/mult"
- "/mnt/video/anime"
- "/mnt/video/serial"
- "/mnt/video/mserials"
- "/mnt/video/ztube"
- "/mnt/video/show"
- "/mnt/audio"
- "/mnt/books"
- "/mnt/documents"
- "/mnt/games"
tags: qbittorrent
- name: Ensure cifs-utils is installed - name: Создание директории для учетных данных SMB
apt: file:
name: cifs-utils path: "{{ qbittorrent_smb_credentials_dir }}"
state: present state: directory
tags: qbittorrent mode: '0700'
- name: Create SMB credentials file - name: Создание файлов учетных данных SMB
copy: template:
content: | src: smb-credentials.j2
username=Zailon dest: "{{ qbittorrent_smb_credentials_dir }}/{{ item.key }}"
password=Welc0metohell
dest: /etc/smb-creds-qbt
owner: root
group: root
mode: '0600' mode: '0600'
tags: qbittorrent loop: "{{ qbittorrent_smb_creds | dict2items }}"
loop_control:
label: "{{ item.key }}"
- name: Mount all SMB shares - name: Монтирование SMB-шаров
mount: mount:
src: "{{ item.src }}"
path: "{{ item.dest }}" path: "{{ item.dest }}"
src: "{{ item.src }}"
fstype: cifs fstype: cifs
opts: "{{ item.opts }},credentials=/etc/smb-creds-qbt" opts: "{{ item.opts }}{% if item.credential is defined %},credentials={{ qbittorrent_smb_credentials_dir }}/{{ item.credential }}{% endif %}"
state: mounted state: mounted
loop: "{{ qbittorrent_shares }}" loop: "{{ qbittorrent_shares }}"
tags: qbittorrent loop_control:
label: "{{ item.name }}"
- name: Verify write access for UID {{ qbittorrent_puid }} - name: Копирование docker-compose файла для qBittorrent
command: runuser -u {{ qbittorrent_puid }} -- touch "{{ item.dest }}/.qbt_mount_test"
loop: "{{ qbittorrent_shares }}"
register: write_test
ignore_errors: yes
tags: qbittorrent
- name: Fail if any share is not writable
fail:
msg: "❌ Нет прав на запись в шару {{ item.item.dest }} (проверьте SMB-сервер, права, UID/GID)"
when: item.failed
loop: "{{ write_test.results }}"
tags: qbittorrent
- name: Generate password hash for qBittorrent
shell: |
echo -n "admin:Web UI:{{ qbittorrent_password }}" | md5sum | awk '{print $1}'
register: password_hash
changed_when: false
no_log: true
tags: qbittorrent
- name: Create qBittorrent configuration with password hash
copy:
content: |
# Auto-generated qBittorrent configuration
[AutoRun]
enabled=false
[BitTorrent]
Session\DefaultSavePath=/downloads
Session\Port={{ qbittorrent_port_torrent }}
[Core]
AutoDeleteAddedTorrentFile=Never
[LegalNotice]
Accepted=true
[Preferences]
Connection\PortRangeMin={{ qbittorrent_port_torrent }}
Connection\PortRangeMax={{ qbittorrent_port_torrent }}
Downloads\SavePath=/downloads
Downloads\TempPath=/downloads/incomplete
WebUI\Address=*
WebUI\Port=8080
WebUI\LocalHostAuth=false
WebUI\AuthSubnetWhitelist=192.168.1.0/24
WebUI\UseUPnP=false
WebUI\ClickjackingProtection=false
WebUI\CSRFProtection=false
WebUI\HostHeaderValidation=false
WebUI\DomainList=192.168.1.201:{{ qbittorrent_port_webui }},localhost:{{ qbittorrent_port_webui }}
WebUI\MaxAuthenticationFailCount=-1
WebUI\Username=admin
WebUI\Password_PBKDF2="@ByteArray({{ password_hash.stdout }}:100000)"
WebUI\Password_ha1=@ByteArray({{ password_hash.stdout }})
Advanced\RecheckOnCompletion=false
dest: "{{ qbittorrent_config_dir }}/qBittorrent.conf"
owner: "{{ qbittorrent_puid }}"
group: "{{ qbittorrent_pgid }}"
mode: '0644'
tags: qbittorrent
- name: Deploy docker-compose.yml
template: template:
src: docker-compose.yml.j2 src: docker-compose.yml.j2
dest: "{{ qbittorrent_base_dir }}/docker-compose.yml" dest: "{{ qbittorrent_base_dir }}/docker-compose.yml"
owner: root
group: root
mode: '0644' mode: '0644'
tags: qbittorrent
- name: Start qBittorrent container with docker compose - name: Запуск qBittorrent контейнера
community.docker.docker_compose_v2: community.docker.docker_compose_v2:
project_src: "{{ qbittorrent_base_dir }}" project_src: "{{ qbittorrent_base_dir }}"
state: present state: present
pull: "always"
build: "never"
recreate: "always"
remove_orphans: yes
tags: qbittorrent
- name: Wait for qBittorrent to start - name: Ожидание запуска qBittorrent
wait_for: wait_for:
host: "127.0.0.1"
port: "{{ qbittorrent_port_webui }}" port: "{{ qbittorrent_port_webui }}"
timeout: 120 timeout: 60
delay: 5
tags: qbittorrent
- name: Display access and mount info - name: Настройка пользователя qBittorrent
debug: uri:
msg: | url: "http://localhost:{{ qbittorrent_port_webui }}/api/v2/auth/login"
✅ qBittorrent успешно развернут на {{ ansible_host }}! method: POST
🔗 Доступ: http://{{ ansible_host }}:{{ qbittorrent_port_webui }} body_format: form-urlencoded
👤 Логин: admin | 🔑 Пароль: {{ qbittorrent_password }} body:
📁 Локальные точки монтирования: username: "admin"
{% for share in qbittorrent_shares %} password: "adminadmin"
- {{ share.name }} → {{ share.dest }} status_code: 200
{% endfor %} register: login_response
💡 Совет: в веб-интерфейсе создайте категории («Фильмы», «Сериалы», «Аниме») и укажите пути: until: login_response.status == 200
- Фильмы → /mnt/video/films retries: 10
- Сериалы → /mnt/video/serial delay: 5
- Аниме → /mnt/video/anime
- Мультфильмы → /mnt/video/mult - name: Смена пароля по умолчанию
- Мультсериалы → /mnt/video/mserials uri:
- Аудиокниги → /mnt/video/abook url: "http://localhost:{{ qbittorrent_port_webui }}/api/v2/app/setPreferences"
- Музыка → /mnt/audio method: POST
- Книги → /mnt/books body_format: json
- Документалистика → /mnt/documents body:
- Игры → /mnt/games json: '{"web_ui":{"username":"{{ qbittorrent_user }}","password":"{{ qbittorrent_password }}","session_timeout":3600}}'
- YouTube → /mnt/video/ztube headers:
- Шоу → /mnt/video/show Cookie: "{{ login_response.set_cookie }}"
tags: qbittorrent status_code: 200
when: login_response.status == 200

View File

@ -9,13 +9,13 @@ services:
- TZ={{ timezone }} - TZ={{ timezone }}
- WEBUI_PORT=8080 - WEBUI_PORT=8080
volumes: volumes:
- {{ qbittorrent_config_dir }}:/config - "{{ qbittorrent_config_dir }}:/config"
- {{ qbittorrent_downloads_dir }}:/downloads - "{{ qbittorrent_downloads_dir }}:/downloads"
{% for share in qbittorrent_shares %} {% for share in qbittorrent_shares %}
- {{ share.dest }}:{{ share.dest }}:rw - "{{ share.dest }}:{{ share.dest }}:rw"
{% endfor %} {% endfor %}
ports: ports:
- "{{ qbittorrent_port_webui }}:8080" - "{{ qbittorrent_port_webui }}:8080"
- "6881:6881" - "{{ qbittorrent_port_torrent }}:{{ qbittorrent_port_torrent }}/udp"
- "6881:6881/udp" - "{{ qbittorrent_port_torrent }}:{{ qbittorrent_port_torrent }}/tcp"
restart: unless-stopped restart: unless-stopped

View File

@ -0,0 +1,2 @@
username={{ item.value.username }}
password={{ item.value.password }}