diff --git a/group_vars/all.yml b/group_vars/all.yml index 6f88e21..e13ceb5 100644 --- a/group_vars/all.yml +++ b/group_vars/all.yml @@ -212,6 +212,61 @@ qbittorrent_port_webui: 45135 qbittorrent_port_torrent: 6881 qbittorrent_password: "13qeadZC" +qbittorrent_shares: + # Windows-шара с входящими торрентами + - name: downloads + src: "//192.168.1.101/Downloads" + dest: "/mnt/downloads" + opts: "uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8" + - name: abook + src: "//192.168.1.203/Abook" + dest: "/mnt/video/abook" + opts: "uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8" + - name: music + src: "//192.168.1.203/Music" + dest: "/mnt/audio" + opts: "uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8" + - name: books + src: "//192.168.1.203/Books" + dest: "/mnt/books" + opts: "uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8" + - name: films + src: "//192.168.1.203/Films" + dest: "/mnt/video/films" + opts: "uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8" + - name: mult + src: "//192.168.1.203/Mult" + dest: "/mnt/video/mult" + opts: "uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8" + - name: anime + src: "//192.168.1.203/Anime" + dest: "/mnt/video/anime" + opts: "uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8" + - name: serial + src: "//192.168.1.203/Serial" + dest: "/mnt/video/serial" + opts: "uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8" + - name: mserials + src: "//192.168.1.203/Mserials" + dest: "/mnt/video/mserials" + opts: "uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8" + - name: doc + src: "//192.168.1.203/Doc" + dest: "/mnt/documents" + opts: "uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8" + - name: ztube + src: "//192.168.1.203/Ztube" + dest: "/mnt/video/ztube" + opts: "uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8" + - name: show + src: "//192.168.1.203/Show" + dest: "/mnt/video/show" + opts: "uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8" + - name: games + src: "//192.168.1.207/Games" + dest: "/mnt/games" + opts: "uid={{ qbittorrent_puid }},gid={{ qbittorrent_pgid }},file_mode=0777,dir_mode=0777,iocharset=utf8" + torrserver_base_dir: "/mnt/service/torrserver" torrserver_config_dir: "{{ torrserver_base_dir }}/config" torrserver_torrents_dir: "{{ torrserver_base_dir }}/torrents" diff --git a/roles/qbittorrent/tasks/main.yml b/roles/qbittorrent/tasks/main.yml index fbc2474..a044fcb 100644 --- a/roles/qbittorrent/tasks/main.yml +++ b/roles/qbittorrent/tasks/main.yml @@ -1,13 +1,70 @@ --- -- name: Create qBittorrent directories +- name: Create qBittorrent base and local directories file: path: "{{ item }}" state: directory mode: '0755' + owner: "{{ qbittorrent_puid }}" + group: "{{ qbittorrent_pgid }}" loop: - "{{ qbittorrent_base_dir }}" - "{{ qbittorrent_config_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 + apt: + name: cifs-utils + state: present + tags: qbittorrent + +- name: Create SMB credentials file + copy: + content: | + username=Zailon + password=Welc0metohell + dest: /etc/smb-creds-qbt + owner: root + group: root + mode: '0600' + tags: qbittorrent + +- name: Mount all SMB shares + mount: + src: "{{ item.src }}" + path: "{{ item.dest }}" + fstype: cifs + opts: "{{ item.opts }},credentials=/etc/smb-creds-qbt" + state: mounted + loop: "{{ qbittorrent_shares }}" + tags: qbittorrent + +- name: Verify write access for UID {{ qbittorrent_puid }} + 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 @@ -24,17 +81,13 @@ # 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 }} @@ -55,6 +108,8 @@ 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 @@ -79,23 +134,33 @@ - name: Wait for qBittorrent to start wait_for: + host: "127.0.0.1" port: "{{ qbittorrent_port_webui }}" - timeout: 60 - state: started + timeout: 120 + delay: 5 tags: qbittorrent -- name: Display access information +- name: Display access and mount info debug: msg: | - ✅ qBittorrent успешно развернут! - + ✅ qBittorrent успешно развернут на {{ ansible_host }}! 🔗 Доступ: http://{{ ansible_host }}:{{ qbittorrent_port_webui }} - 👤 Имя пользователя: admin - 🔑 Пароль: {{ qbittorrent_password }} - - 📁 Директории: - - Конфигурация: {{ qbittorrent_config_dir }} - - Загрузки: {{ qbittorrent_downloads_dir }} - - ⚠️ Примечание: Пароль установлен в конфиге и должен работать стабильно. + 👤 Логин: admin | 🔑 Пароль: {{ qbittorrent_password }} + 📁 Локальные точки монтирования: + {% for share in qbittorrent_shares %} + - {{ share.name }} → {{ share.dest }} + {% endfor %} + 💡 Совет: в веб-интерфейсе создайте категории («Фильмы», «Сериалы», «Аниме») и укажите пути: + - Фильмы → /mnt/video/films + - Сериалы → /mnt/video/serial + - Аниме → /mnt/video/anime + - Мультфильмы → /mnt/video/mult + - Мультсериалы → /mnt/video/mserials + - Аудиокниги → /mnt/video/abook + - Музыка → /mnt/audio + - Книги → /mnt/books + - Документалистика → /mnt/documents + - Игры → /mnt/games + - YouTube → /mnt/video/ztube + - Шоу → /mnt/video/show tags: qbittorrent \ No newline at end of file diff --git a/roles/qbittorrent/templates/docker-compose.yml.j2 b/roles/qbittorrent/templates/docker-compose.yml.j2 index 11c0ea2..aee4646 100644 --- a/roles/qbittorrent/templates/docker-compose.yml.j2 +++ b/roles/qbittorrent/templates/docker-compose.yml.j2 @@ -11,8 +11,11 @@ services: volumes: - {{ qbittorrent_config_dir }}:/config - {{ qbittorrent_downloads_dir }}:/downloads + {% for share in qbittorrent_shares %} + - {{ share.dest }}:{{ share.dest }}:rw + {% endfor %} ports: - - {{ qbittorrent_port_webui }}:8080 - - 6881:6881 - - 6881:6881/udp + - "{{ qbittorrent_port_webui }}:8080" + - "6881:6881" + - "6881:6881/udp" restart: unless-stopped \ No newline at end of file