Files
seafile-mirror-ansible/tasks/main.yml

105 lines
3.0 KiB
YAML
Raw Normal View History

2023-05-26 11:11:15 +02:00
# SPDX-FileCopyrightText: 2023 Max Mehl <https://mehl.mx>
#
# SPDX-License-Identifier: Apache-2.0
2023-05-26 11:04:55 +02:00
---
- name: Ensure local seafile user is configured correctly
include_role:
name: users
apply:
become: false
vars:
username: "{{ seafile_local_user.user }}"
password: "{{ seafile_local_user.pass | default('') }}"
- name: Ensure requirements are installed
apt:
name:
- moreutils # chronic
- pipx
2023-05-26 11:04:55 +02:00
- systemd-container # necessary to use machinectl become_method
- seafile-cli
become: false # need to do this as root
- name: Install seafile-mirror with pipx
command: pipx install seafile-mirror
changed_when: false
- name: Upgrade seafile-mirror with pipx
command: pipx upgrade seafile-mirror
changed_when: false
2023-05-26 11:04:55 +02:00
- name: Register user info of {{ seafile_local_user.user }}
user:
name: "{{ seafile_local_user.user }}"
check_mode: true
register: seafile_local_user_info
- name: Define directory for Seafile mirror service as fact
set_fact:
seafile_mirror_dir: "{{ seafile_local_user_info.home }}/seafile_mirror"
- name: Ensure directory for Seafile mirror service exists
file:
path: "{{ seafile_mirror_dir }}"
2023-05-26 11:04:55 +02:00
state: directory
2023-12-13 20:16:52 +01:00
mode: "0755"
2023-05-26 11:04:55 +02:00
recurse: true
- name: Ensure Seafile mirror configuration exists
template:
src: seafile_mirror.conf.yaml.j2
dest: "{{ seafile_mirror_dir }}/seafile_mirror.conf.yaml"
2023-12-13 20:16:52 +01:00
mode: "0600"
2023-05-26 11:04:55 +02:00
- name: Ensure cron entry for Seafile mirror service
cron:
name: Seafile Mirror Service
2023-12-20 09:00:29 +01:00
job: "chronic pipx run seafile-mirror -c {{ seafile_mirror_dir }}"
2023-05-26 11:04:55 +02:00
hour: "23"
minute: "20"
- name: Ensure user systemd directory exists
file:
path: "{{ seafile_local_user_info.home }}/.config/systemd/user/"
state: directory
2023-12-13 20:16:52 +01:00
mode: "0755"
2023-05-26 11:04:55 +02:00
- name: Ensure systemd service file is present
template:
src: seaf-daemon.service.j2
dest: "{{ seafile_local_user_info.home }}/.config/systemd/user/seaf-daemon.service"
2023-12-13 20:16:52 +01:00
mode: "0644"
2023-05-26 11:04:55 +02:00
- name: Ensure Seafile config dir exists
file:
path: "{{ seafile_local_user_info.home }}/config"
state: directory
2023-12-13 20:16:52 +01:00
mode: "0755"
2023-05-26 11:04:55 +02:00
- name: Ensure Seafile config dir is initialised
command:
cmd: seaf-cli init -d "{{ seafile_local_user_info.home }}/config"
register: result
changed_when: '"already exists" not in result.stdout'
- name: "Check whether user is lingering: {{ seafile_local_user.user }}"
stat:
path: "/var/lib/systemd/linger/{{ seafile_local_user.user }}"
register: seafile_local_user_lingering
- name: Ensure systemd lingering is enabled for user {{ seafile_local_user.user }}
command: loginctl enable-linger {{ seafile_local_user.user }}
become: false
2023-12-13 20:16:52 +01:00
changed_when: false
2023-05-26 11:04:55 +02:00
when: not seafile_local_user_lingering.stat.exists
- name: Ensure systemd service is running and enabled
systemd:
name: seaf-daemon
state: started
enabled: true
daemon_reload: true
scope: user
2023-12-13 20:16:52 +01:00
become_method: community.general.machinectl # in order to get XDG_RUNTIME_DIR and user's DBUS session