--- - name: install dependencies ansible.builtin.apt: name: - git - apache2 - php-fpm - php-curl - php-xml - php-mbstring - php-zip - python3 - python3-cloudscraper - sox - mediainfo - ffmpeg - zip - unzip - unrar-free - curl - sudo state: present update_cache: yes notify: - restart apache - restart php-fpm - name: get current php-fpm version ansible.builtin.shell: php -r 'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION;' register: php_version changed_when: false - name: get latest dumptorrent release info ansible.builtin.uri: url: https://api.github.com/repos/tomcdj71/dumptorrent/releases/latest return_content: yes register: dumptorrent_release run_once: true check_mode: false - name: set current dumptorrent version ansible.builtin.set_fact: dumptorrent_version: "{{ dumptorrent_release.json.tag_name | regex_replace('^v', '') }}" dumptorrent_asset_url: "{{ dumptorrent_release.json.assets | selectattr('name', 'search', 'ubuntu-latest_amd64.deb') | map(attribute='browser_download_url') | first }}" - name: check dumptorrent installed version ansible.builtin.shell: dumptorrent -V | grep -oP '\d+\.\d+\.\d+' register: dumptorrent_current_version changed_when: false failed_when: false - name: display dumptorrent version info ansible.builtin.debug: msg: "latest version: {{ dumptorrent_version }}, installed version: {{ dumptorrent_current_version.stdout | default('not installed', true) }}" - name: download and install dumptorrent ansible.builtin.apt: deb: "{{ dumptorrent_asset_url }}" when: dumptorrent_version not in (dumptorrent_current_version.stdout | default('')) - name: create media group ansible.builtin.group: name: media gid: 1000 state: present - name: create rtorrent group ansible.builtin.group: name: rtorrent system: true state: present - name: create rtorrent user ansible.builtin.user: name: rtorrent group: rtorrent groups: media append: yes system: true shell: /usr/sbin/nologin home: /var/lib/rtorrent create_home: true state: present - name: add www-data to rtorrent group ansible.builtin.user: name: www-data groups: rtorrent append: yes notify: restart apache - name: ensure rtorrent data directory exists ansible.builtin.file: path: /var/lib/rtorrent owner: rtorrent group: rtorrent state: directory mode: "0750" - name: ensure rtorrent log directory exists ansible.builtin.file: path: /var/log/rtorrent owner: rtorrent group: rtorrent state: directory mode: "0755" - name: install rtorrent ansible.builtin.apt: name: rtorrent state: latest update_cache: true notify: restart rtorrent - name: fetch wan ip ansible.builtin.shell: ssh -o StrictHostKeyChecking=no root@{{ hostvars['router'].ip }} "ip -4 addr show eth1 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'" delegate_to: localhost register: router_wan_ip changed_when: false vars: ansible_connection: local - name: ensure rtorrent config directory exists ansible.builtin.file: path: /etc/rtorrent owner: root group: root state: directory mode: "0755" - name: deploy rtorrent config ansible.builtin.template: src: "{{ inventory_hostname }}/.rtorrent.rc.j2" dest: "/etc/rtorrent/.rtorrent.rc" owner: rtorrent group: rtorrent mode: "0640" vars: wan_ip: "{{ router_wan_ip.stdout }}" notify: restart rtorrent - name: ensure rtorrent session directory is a mountpoint ansible.builtin.command: mountpoint -q /var/lib/rtorrent/session register: session_mountpoint failed_when: false changed_when: false - name: ensure rtorrent session source directory exists ansible.builtin.file: path: /mnt/rtorrent/session state: directory owner: rtorrent group: rtorrent mode: "0755" - name: bind mount rtorrent session directory ansible.posix.mount: path: /var/lib/rtorrent/session src: /mnt/rtorrent/session fstype: none opts: bind state: mounted notify: restart rtorrent - name: set rtorrent session directory ownership ansible.builtin.file: path: /mnt/rtorrent/session owner: rtorrent group: rtorrent recurse: true - name: ensure ansible remote tmp dir exists ansible.builtin.file: path: /tmp/.ansible-www-data state: directory owner: www-data group: www-data mode: "0700" - name: check current rutorrent git remote ansible.builtin.command: git -C /var/www/html remote get-url origin become: yes become_user: www-data register: current_remote failed_when: false changed_when: false vars: ansible_remote_tmp: /tmp/.ansible-www-data - name: get latest rutorrent release info ansible.builtin.uri: url: "https://api.github.com/repos/Novik/ruTorrent/releases/latest" return_content: yes register: rutorrent_release run_once: true check_mode: false - name: set current rutorrent version ansible.builtin.set_fact: rutorrent_version: "{{ rutorrent_release.json.tag_name | regex_replace('^v', '') }}" - name: check rutorrent installed version ansible.builtin.command: grep -oP 'version:\s*"\K[^"]+' /var/www/html/js/webui.js register: rutorrent_current_version changed_when: false failed_when: false - name: ensure html share directory is a mountpoint ansible.builtin.command: mountpoint -q /var/www/html/share register: share_mountpoint failed_when: false changed_when: false - name: unmount rutorrent share directory before update ansible.posix.mount: path: /var/www/html/share state: unmounted when: - share_mountpoint.rc == 0 - rutorrent_version not in (rutorrent_current_version.stdout | default('')) - name: remove irrelevant html directory ansible.builtin.file: path: /var/www/html state: absent when: - current_remote.rc is defined - current_remote.rc != 0 - rutorrent_version not in (rutorrent_current_version.stdout | default('')) - name: display rutorrent version info ansible.builtin.debug: msg: "latest version: {{ rutorrent_version }}, installed version: {{ rutorrent_current_version.stdout | default('not installed', true) }}" - name: clone rutorrent ansible.builtin.git: repo: "https://github.com/Novik/ruTorrent.git" dest: "/var/www/html" version: "v{{ rutorrent_version }}" force: yes when: rutorrent_version not in (rutorrent_current_version.stdout | default('')) - name: set rutorrent directory ownership ansible.builtin.file: path: /var/www/html owner: www-data group: www-data recurse: yes when: rutorrent_version not in (rutorrent_current_version.stdout | default('')) - name: remove default share directory ansible.builtin.file: path: /var/www/html/share state: absent when: rutorrent_version not in (rutorrent_current_version.stdout | default('')) - name: ensure rutorrent share source directory exists ansible.builtin.file: path: /mnt/rutorrent/share state: directory owner: www-data group: www-data mode: "0755" - name: bind mount rutorrent share directory ansible.posix.mount: path: /var/www/html/share src: /mnt/rtorrent/share fstype: none opts: bind state: mounted notify: restart apache - name: set rutorrent share subdirectories ownership ansible.builtin.file: path: "/mnt/rtorrent/share/{{ item }}" owner: www-data group: www-data recurse: true loop: - settings - torrents - users - name: set rutorrent share tmp ownership ansible.builtin.file: path: /mnt/rtorrent/share/tmp owner: rtorrent group: rtorrent recurse: true - name: deploy rutorrent config ansible.builtin.template: src: "{{ inventory_hostname }}/config.php.j2" dest: "/var/www/html/conf/config.php" owner: www-data group: www-data mode: "0644" notify: restart apache - name: deploy rutorrent plugin config ansible.builtin.template: src: "{{ inventory_hostname }}/plugin.ini.j2" dest: "/var/www/html/conf/plugin.ini" owner: www-data group: www-data mode: "0644" notify: restart apache - name: enable required apache modules community.general.apache2_module: name: "{{ item }}" state: present loop: - proxy - proxy_fcgi - proxy_scgi - rewrite - setenvif - headers notify: restart apache - name: deploy rutorrent apache vhost ansible.builtin.template: src: "{{ inventory_hostname }}/rutorrent.conf.j2" dest: "/etc/apache2/sites-available/rutorrent.conf" owner: root group: root mode: '0644' notify: restart apache - name: enable rutorrent site ansible.builtin.command: a2ensite rutorrent args: creates: /etc/apache2/sites-enabled/rutorrent.conf notify: restart apache - name: disable default apache site ansible.builtin.command: a2dissite 000-default args: removes: /etc/apache2/sites-enabled/000-default.conf notify: restart apache - name: deploy rtorrent service ansible.builtin.copy: src: rtorrent.service dest: /etc/systemd/system/rtorrent.service owner: root group: root mode: '0644' notify: restart rtorrent