-
-
Notifications
You must be signed in to change notification settings - Fork 93
/
main.yml
123 lines (107 loc) · 3.52 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#########################################################################
# Title: Sandbox: Plex Autoscan Role #
# Author(s): l3uddz, desimaniac #
# URL: https://github.com/saltyorg/Sandbox #
# -- #
#########################################################################
# GNU General Public License v3.0 #
#########################################################################
---
- name: Check if Plex instance is defined
ansible.builtin.set_fact:
plex_name: "{{ plex_name | default(plex_instances[0]) }}"
- name: Import Services Task
ansible.builtin.import_tasks: "subtasks/services.yml"
- name: Create plex_autoscan directories
ansible.builtin.file:
path: "{{ item }}"
state: directory
owner: "{{ user.name }}"
group: "{{ user.name }}"
mode: 0775
recurse: true
with_items:
- /opt/plex_autoscan
- name: Clone plex_autoscan repo 'HEAD'
ansible.builtin.git:
repo: https://github.com/l3uddz/plex_autoscan.git
dest: /opt/plex_autoscan
clone: true
version: HEAD
force: true
become: true
become_user: "{{ user.name }}"
ignore_errors: true
register: plex_autoscan_clone_status
- name: Clone plex_autoscan repo 'master'
ansible.builtin.git:
repo: https://github.com/l3uddz/plex_autoscan.git
dest: /opt/plex_autoscan
clone: true
version: master
force: true
become: true
become_user: "{{ user.name }}"
when: plex_autoscan_clone_status is failed
- name: Set Python version
ansible.builtin.set_fact:
plex_autoscan_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: "/opt/plex_autoscan/venv"
register: plex_autoscan_venv_folder
- name: Delete venv folder
ansible.builtin.file:
path: "/opt/plex_autoscan/venv"
state: absent
when: plex_autoscan_venv_folder.stat.exists
- name: Install pip requirements
ansible.builtin.pip:
requirements: /opt/plex_autoscan/requirements.txt
virtualenv_python: "{{ plex_autoscan_python }}"
virtualenv: "/opt/plex_autoscan/venv"
become: true
become_user: "{{ user.name }}"
- name: Find pip3 path
ansible.builtin.find:
paths: /opt/plex_autoscan/venv
recurse: true
patterns: 'pip3'
register: files
- name: Path
ansible.builtin.set_fact:
plex_autoscan_bin_folder: "{{ files.files[0].path | dirname }}"
- name: Set 'scan.py' as executable
ansible.builtin.file:
path: /opt/plex_autoscan/scan.py
owner: "{{ user.name }}"
group: "{{ user.name }}"
mode: a+x
- name: Create script alias
ansible.builtin.template:
src: plex_autoscan.sh.j2
dest: "{{ plex_autoscan_alias_path }}"
mode: "0755"
force: true
- name: Import 'plex_autoscan.service'
ansible.builtin.template:
src: plex_autoscan.service.j2
dest: /etc/systemd/system/plex_autoscan.service
mode: "0644"
force: true
- name: Import Settings Task
ansible.builtin.import_tasks: "subtasks/settings.yml"
- name: Start 'plex_autoscan.service'
ansible.builtin.systemd:
name: plex_autoscan
state: started
enabled: true
daemon_reload: true