ctucx.git: ansible-configs

My personal ansible roles and playbooks [deprecated in favor of nixos]

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 
---

- name: "Find uid of user: {{ services.rest_server.user }}"
  command: "id -u {{ services.syncthing.user }}"
  register: userId
  check_mode: no # Run even in check mode, otherwise the playbook fails with --check.
  changed_when: false
  when:
    - ansible_service_mgr == "systemd"
    - services.syncthing.user is defined

- name: "Determine XDG_RUNTIME_DIR"
  set_fact:
    xdg_runtime_dir: "/run/user/{{ userId.stdout }}"
  changed_when: false
  when:
    - ansible_service_mgr == "systemd"


- name: "[OpenRC] Disable and stop service: syncthing-{{ services.syncthing.user }}"
  service:
    name: "syncthing-{{ syncthing.user }}"
    enabled: yes
    state: stopped
  when: 
    - ansible_service_mgr == "openrc"

- name: "[systemd] Disable and stop service: syncthing"
  environment:
    XDG_RUNTIME_DIR: "{{ xdg_runtime_dir }}"
  systemd:
    name: syncthing
    scope: user
    enabled: no
    state: stopped
  become: true
  become_user: "{{ services.syncthing.user }}"
  when: 
    - ansible_service_mgr == "systemd"


- name: "[Alpine] Remove package: syncthing"
  apk:
    name: syncthing
    state: absent
  when: 
    - ansible_distribution == "Alpine" 
    - services.syncthing.enable is false

- name: "[Archlinux] Remove package: syncthing"
  pacman:
    name: syncthing
    state: absent
  when: 
    - ansible_distribution == "Archlinux" 
    - services.syncthing.enable is false


- name: "Delete leftovers"
  file:
    path: "{{ item }}"
    state: absent
  with_items:
    - "/etc/init.d/syncthing-{{ services.syncthing.user }}"

- name: "[nftables] Delete rule for: syncthing"
  file:
    path: /etc/nftables.d/syncthing.nft
    state: absent
  notify: "Restart nftables"

- name: "Delete nginx vhost for: syncthing"
  file:
    path: /etc/nginx/conf.d/syncthing.conf
    state: absent
  notify: "Restart nginx"