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

- name: "Enable linger for user: {{ services.syncthing.user }}"
  command: "loginctl enable-linger {{ services.syncthing.user }}"
  changed_when: false
  when:
    - ansible_service_mgr == "systemd"
    - services.syncthing.user is defined

- 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] Enable and start service: syncthing-{{ services.syncthing.user }}"
  service:
    name: "syncthing-{{ services.syncthing.user }}"
    enabled: yes
    state: started
  when: 
    - ansible_service_mgr == "openrc"

- name: "[systemd] Enable and start service: syncthing"
  environment:
    XDG_RUNTIME_DIR: "{{ xdg_runtime_dir }}"
  systemd:
    name: syncthing
    scope: user
    enabled: yes
    state: started
  become: true
  become_user: "{{ services.syncthing.user }}"
  when: 
    - ansible_service_mgr == "systemd"