aboutsummaryrefslogtreecommitdiff
path: root/ansible/roles/torrents/tasks/setup.yaml
blob: 25f1fe86dd2456b2a181838aedf10e44c013fbda (plain)
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
---

- 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