aboutsummaryrefslogtreecommitdiff
path: root/ansible/roles/torrents/tasks/setup.yaml
diff options
context:
space:
mode:
Diffstat (limited to 'ansible/roles/torrents/tasks/setup.yaml')
-rw-r--r--ansible/roles/torrents/tasks/setup.yaml79
1 files changed, 79 insertions, 0 deletions
diff --git a/ansible/roles/torrents/tasks/setup.yaml b/ansible/roles/torrents/tasks/setup.yaml
new file mode 100644
index 0000000..25f1fe8
--- /dev/null
+++ b/ansible/roles/torrents/tasks/setup.yaml
@@ -0,0 +1,79 @@
+---
+
+- name: 'setup | Ensure required vars are set'
+ ansible.builtin.assert:
+ that:
+ - item | mandatory
+ loop:
+ - '{{ torrents_nas_mount_path }}'
+ - '{{ torrents_rpc_username }}'
+ - '{{ torrents_rpc_password }}'
+ no_log: true
+
+- name: 'setup | Install required pkgs'
+ ansible.builtin.package:
+ name:
+ - 'nfs-common'
+ - 'transmission-daemon'
+
+- name: 'setup | Stop the transmission-daemon service'
+ ansible.builtin.service:
+ name: 'transmission-daemon'
+ state: 'stopped'
+
+- name: 'setup | Create the mount dir'
+ ansible.builtin.file:
+ path: '/mnt/data'
+ state: 'directory'
+ mode: '755'
+
+- name: 'setup | Setup the NFS mount'
+ ansible.posix.mount:
+ src: '{{ torrents_nas_mount_path }}'
+ path: '/mnt/data'
+ state: 'mounted'
+ fstype: 'nfs'
+
+- name: 'setup | Create new user for transmission'
+ ansible.builtin.user:
+ name: 'transmission-user'
+ uid: 1001
+ groups: 'users'
+ create_home: true
+
+- name: 'setup | Fix the service file to use our user'
+ ansible.builtin.lineinfile:
+ path: '/lib/systemd/system/transmission-daemon.service'
+ regexp: '^User='
+ line: 'User=transmission-user'
+
+- name: 'setup | Reload systemd daemon'
+ ansible.builtin.systemd:
+ daemon_reload: true
+
+# THis is kind of a hack to force the generation of
+# /home/transmission-user/.config/transmission-daemon dirs
+# so that we can place our config file there.
+- name: 'setup | Start the service'
+ ansible.builtin.service:
+ name: 'transmission-daemon'
+ state: 'started'
+
+# We still need to stop it to place the config file or else it will get overwritten
+- name: 'setup | Stop the service'
+ ansible.builtin.service:
+ name: 'transmission-daemon'
+ state: 'stopped'
+
+- name: 'setup | Copy the transmission config'
+ ansible.builtin.template:
+ src: 'settings.json.j2'
+ dest: '/home/transmission-user/.config/transmission-daemon/settings.json'
+ owner: 'transmission-user'
+ mode: '644'
+
+- name: 'setup | Start the service'
+ ansible.builtin.service:
+ name: 'transmission-daemon'
+ state: 'started'
+ enabled: true