diff --git a/roles/cloudplow/tasks/main.yml b/roles/cloudplow/tasks/main.yml index 3d5ac27e55..1e277a4c5e 100644 --- a/roles/cloudplow/tasks/main.yml +++ b/roles/cloudplow/tasks/main.yml @@ -19,97 +19,117 @@ state: absent when: ('cloudplow-reset' in ansible_run_tags) -- name: Check if Plex instance is defined +- name: Filter Rclone remotes ansible.builtin.set_fact: - plex_name: "{{ plex_name | default(plex_instances[0]) }}" + cloudplow_remotes: "{{ cloudplow_remotes + [item] }}" + loop: "{{ rclone.remotes }}" + when: item.upload -- name: Stop Service - ansible.builtin.include_tasks: "{{ resources_tasks_path }}/systemd/stop_service.yml" - vars: - _service_name: "{{ cloudplow_service_name }}" - -- name: Create directory - ansible.builtin.file: - path: "{{ cloudplow_path }}" - state: directory - owner: "{{ user.name }}" - group: "{{ user.name }}" - mode: "0775" - recurse: true - -- name: Clone project git repo - ansible.builtin.include_tasks: "{{ resources_tasks_path }}/git/clone_git_repo.yml" - -- name: Set Python version +- name: Filter Rclone upload_from on remotes ansible.builtin.set_fact: - cloudplow_python: "{{ 'python3' - if ansible_distribution_version is version('20.04', '==') - else 'python3.8' }}" - -- name: "Execute Python role" - ansible.builtin.include_role: - name: "python" - vars: - python_version: "3.8" - when: ansible_distribution_version is version('22.04', '==') - -- name: Check if venv folder exists - ansible.builtin.stat: - path: "{{ cloudplow_venv_path }}" - register: cloudplow_venv_folder - -- name: Delete venv folder - ansible.builtin.file: - path: "{{ cloudplow_venv_path }}" - state: absent - when: cloudplow_venv_folder.stat.exists - -- name: Install pip requirements - ansible.builtin.pip: - requirements: "{{ cloudplow_requirements_path }}" - virtualenv_python: "{{ cloudplow_python }}" - virtualenv: "{{ cloudplow_venv_path }}" - become: true - become_user: "{{ user.name }}" - -- name: Find pip3 path - ansible.builtin.find: - paths: "{{ cloudplow_path }}/venv" - recurse: true - patterns: 'pip3' - register: files - -- name: Path - ansible.builtin.set_fact: - cloudplow_bin_folder: "{{ files.files[0].path | dirname }}" - -- name: Set script as executable - ansible.builtin.file: - path: "{{ cloudplow_script_path }}" - owner: "{{ user.name }}" - group: "{{ user.name }}" - mode: a+x - -- name: Create script alias - ansible.builtin.template: - src: cloudplow.sh.j2 - dest: "{{ cloudplow_alias_path }}" - mode: "0755" - force: true - -- name: Import Settings Task - ansible.builtin.import_tasks: "subtasks/settings.yml" - -- name: Import '{{ cloudplow_service_name }}.service' - ansible.builtin.template: - src: cloudplow.service.j2 - dest: "/etc/systemd/system/{{ cloudplow_service_name }}.service" - mode: "0644" - force: true - -- name: Start service - ansible.builtin.systemd: - name: "{{ cloudplow_service_name }}" - state: started - enabled: true - daemon_reload: true + cloudplow_upload_paths_unique: "{{ cloudplow_upload_paths_unique + [item.upload_from] }}" + loop: "{{ rclone.remotes }}" + when: item.upload and (item.upload_from not in cloudplow_upload_paths_unique) + +- name: Cloudplow tasks + when: (cloudplow_remotes | length > 0) + block: + - name: Check if Plex instance is defined + ansible.builtin.set_fact: + plex_name: "{{ plex_name | default(plex_instances[0]) }}" + + - name: Stop Service + ansible.builtin.include_tasks: "{{ resources_tasks_path }}/systemd/stop_service.yml" + vars: + _service_name: "{{ cloudplow_service_name }}" + + - name: Create directory + ansible.builtin.file: + path: "{{ cloudplow_path }}" + state: directory + owner: "{{ user.name }}" + group: "{{ user.name }}" + mode: "0775" + recurse: true + + - name: Clone project git repo + ansible.builtin.include_tasks: "{{ resources_tasks_path }}/git/clone_git_repo.yml" + + - name: Set Python version + ansible.builtin.set_fact: + cloudplow_python: "{{ 'python3' + if ansible_distribution_version is version('20.04', '==') + else 'python3.8' }}" + + - name: "Execute Python role" + ansible.builtin.include_role: + name: "python" + vars: + python_version: "3.8" + when: ansible_distribution_version is version('22.04', '==') + + - name: Check if venv folder exists + ansible.builtin.stat: + path: "{{ cloudplow_venv_path }}" + register: cloudplow_venv_folder + + - name: Delete venv folder + ansible.builtin.file: + path: "{{ cloudplow_venv_path }}" + state: absent + when: cloudplow_venv_folder.stat.exists + + - name: Install pip requirements + ansible.builtin.pip: + requirements: "{{ cloudplow_requirements_path }}" + virtualenv_python: "{{ cloudplow_python }}" + virtualenv: "{{ cloudplow_venv_path }}" + become: true + become_user: "{{ user.name }}" + + - name: Find pip3 path + ansible.builtin.find: + paths: "{{ cloudplow_path }}/venv" + recurse: true + patterns: 'pip3' + register: files + + - name: Path + ansible.builtin.set_fact: + cloudplow_bin_folder: "{{ files.files[0].path | dirname }}" + + - name: Set script as executable + ansible.builtin.file: + path: "{{ cloudplow_script_path }}" + owner: "{{ user.name }}" + group: "{{ user.name }}" + mode: a+x + + - name: Create script alias + ansible.builtin.template: + src: cloudplow.sh.j2 + dest: "{{ cloudplow_alias_path }}" + mode: "0755" + force: true + + - name: Import Settings Task + ansible.builtin.import_tasks: "subtasks/settings.yml" + + - name: Import '{{ cloudplow_service_name }}.service' + ansible.builtin.template: + src: cloudplow.service.j2 + dest: "/etc/systemd/system/{{ cloudplow_service_name }}.service" + mode: "0644" + force: true + + - name: Start service + ansible.builtin.systemd: + name: "{{ cloudplow_service_name }}" + state: started + enabled: true + daemon_reload: true + +- name: Cloudplow Skipped + ansible.builtin.debug: + msg: "Cloudplow was skipped due to no remotes having upload enabled." + when: not (cloudplow_remotes | length > 0) diff --git a/roles/cloudplow/tasks/subtasks/settings.yml b/roles/cloudplow/tasks/subtasks/settings.yml index 04e7c243a8..2ece0e4af8 100644 --- a/roles/cloudplow/tasks/subtasks/settings.yml +++ b/roles/cloudplow/tasks/subtasks/settings.yml @@ -1,6 +1,6 @@ ######################################################################### # Title: Saltbox: Cloudplow | Settings Task # -# Author(s): desimaniac # +# Author(s): desimaniac, salty # # URL: https://github.com/saltyorg/Saltbox # # -- # ######################################################################### @@ -26,18 +26,6 @@ sabnzbd_apikey: "{{ lookup('file', sabnzbd_paths_config_location) | regex_search('^api_key *= *.*', multiline=True) | regex_replace('.*= *(.*)$', '\\1') }}" when: stat_sabnzbd.stat.exists -- name: Settings | Filter Rclone remotes - ansible.builtin.set_fact: - cloudplow_remotes: "{{ cloudplow_remotes + [item] }}" - loop: "{{ rclone.remotes }}" - when: item.upload - -- name: Settings | Filter Rclone upload_from on remotes - ansible.builtin.set_fact: - cloudplow_upload_paths_unique: "{{ cloudplow_upload_paths_unique + [item.upload_from] }}" - loop: "{{ rclone.remotes }}" - when: item.upload and (item.upload_from not in cloudplow_upload_paths_unique) - - name: Settings | Fail if duplicate folders where found. ansible.builtin.fail: msg: