aboutsummaryrefslogtreecommitdiff
path: root/ansible/roles/torrents/tasks
diff options
context:
space:
mode:
authorKumar Damani <me@kumardamani.net>2023-08-11 16:28:54 +0000
committerKumar Damani <me@kumardamani.net>2023-08-11 16:28:54 +0000
commita8a40383081441ebd3757a501364b9ac45eb421e (patch)
treef48b7040615af1bda263faa4d2657636c77ba2a4 /ansible/roles/torrents/tasks
parent9bae899e227e4899a5ee629bf305a00a39044bc2 (diff)
parent1f321db8949b3aeb80afdd7a94e92b7743c3e275 (diff)
Merge branch 'work' into 'main'
Work See merge request kdam0/home-lab!1
Diffstat (limited to 'ansible/roles/torrents/tasks')
-rw-r--r--ansible/roles/torrents/tasks/main.yaml5
-rw-r--r--ansible/roles/torrents/tasks/setup.yaml79
2 files changed, 84 insertions, 0 deletions
diff --git a/ansible/roles/torrents/tasks/main.yaml b/ansible/roles/torrents/tasks/main.yaml
new file mode 100644
index 0000000..806a4e3
--- /dev/null
+++ b/ansible/roles/torrents/tasks/main.yaml
@@ -0,0 +1,5 @@
+---
+
+- name: 'Run the setup tasks'
+ ansible.builtin.import_tasks: 'setup.yaml'
+ tags: 'torrents'
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