From 9e8fffa14551d38ace86a80dc3fd2379496a6d05 Mon Sep 17 00:00:00 2001 From: L3D Date: Tue, 24 Oct 2023 02:11:32 +0200 Subject: [PATCH] Create Etesync.dav setup --- defaults/main.yml | 4 ++- handlers/main.yml | 15 +++++++++++ tasks/download_etesync_dav.yml | 10 ++++++++ tasks/get_version_of_etesync_dav.yml | 38 ++++++++++++++++++++++++++++ tasks/main.yml | 9 +++++++ tasks/setup_systemd.yml | 12 +++++++++ templates/etesync-dav.service.j2 | 11 ++++++++ vars/main.yml | 6 ++--- 8 files changed, 100 insertions(+), 5 deletions(-) create mode 100644 handlers/main.yml create mode 100644 tasks/download_etesync_dav.yml create mode 100644 tasks/get_version_of_etesync_dav.yml create mode 100644 tasks/setup_systemd.yml create mode 100644 templates/etesync-dav.service.j2 diff --git a/defaults/main.yml b/defaults/main.yml index 98d0548..0f7c85f 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,5 +1,7 @@ --- -etesync_dav__user: 'etesync_dav' +etesync_dav__version: 'latest' +etesync_dav__executable: '/usr/local/bin/etesync-dav' +etesync_dav__port: '37358' # should we do a version check? (recomended) submodules_versioncheck: false diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..44d10d8 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,15 @@ +--- +- name: Run systemctl enable etesync-dav.service + become: true + ansible.builtin.systemd: + name: 'etesync-dav.service' + enabled: true + state: 'started' + daemon_reload: true + +- name: Run systemctl restart etesync-dav.service + become: true + ansible.builtin.systemd: + name: 'etesync-dav.service' + enabled: true + state: 'restarted' diff --git a/tasks/download_etesync_dav.yml b/tasks/download_etesync_dav.yml new file mode 100644 index 0000000..e976a13 --- /dev/null +++ b/tasks/download_etesync_dav.yml @@ -0,0 +1,10 @@ +--- +- name: "Download etesync-dav version v{{ etesync_dav__version_target }}" + become: true + ansible.builtin.get_url: + url: "{{ etesync_dav__dl_url }}" + dest: "{{ etesync_dav__executable }}" + owner: root + group: root + mode: "0755" + notify: 'Run systemctl restart etesync-dav.service' diff --git a/tasks/get_version_of_etesync_dav.yml b/tasks/get_version_of_etesync_dav.yml new file mode 100644 index 0000000..3d5d0f6 --- /dev/null +++ b/tasks/get_version_of_etesync_dav.yml @@ -0,0 +1,38 @@ +--- +- name: "Determine 'latest' version release" + when: etesync_dav__version == "latest" + block: + - name: "Get latest etesync-dav release metadata" + ansible.builtin.uri: + url: "{{ etesync_dav__repo_api }}" + return_content: true + register: etesync_dav__remote_metadata + become: false + when: not ansible_check_mode + + - name: "Fail if running in check mode without versions set." + ansible.builtin.fail: + msg: | + "You are running this playbook in check mode: + Please set the desired version with the variable + 'etesync_dav__version', because the URI module cannot detect the latest version in this mode." + when: ansible_check_mode and (etesync_dav__version == 'latest') + + - name: "Set fact latest etesync-dav release" + ansible.builtin.set_fact: + etesync_dav__remote_version: "{{ etesync_dav__remote_metadata.json.tag_name[1:] }}" + when: not ansible_check_mode + + - name: "Set etesync-dav version target (latest)" + ansible.builtin.set_fact: + etesync_dav__version_target: "{{ etesync_dav__remote_version }}" + when: not ansible_check_mode + +- name: "Set etesync-dav version target {{ etesync_dav__version }}" + ansible.builtin.set_fact: + etesync_dav__version_target: "{{ etesync_dav__version }}" + when: etesync_dav__version != "latest" + +- name: "Generate etesync-dav download URL" + ansible.builtin.set_fact: + etesync_dav__dl_url: "https://github.com/etesync/etesync-dav/releases/download/v{{ etesync_dav__version_target }}/linux-amd64-etesync-dav" diff --git a/tasks/main.yml b/tasks/main.yml index f188539..c34d849 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -2,3 +2,12 @@ - name: Run optional versionscheck ansible.builtin.include_tasks: versioncheck.yml when: submodules_versioncheck | bool + +- name: Get Version of etesync-dav + ansible.builtin.include_tasks: tasks/get_version_of_etesync_dav.yml + +- name: Download etesync-dav + ansible.builtin.include_tasks: download_etesync_dav.yml + +- name: Setup Systemd service + ansible.builtin.include_tasks: setup_systemd.yml diff --git a/tasks/setup_systemd.yml b/tasks/setup_systemd.yml new file mode 100644 index 0000000..1673f7b --- /dev/null +++ b/tasks/setup_systemd.yml @@ -0,0 +1,12 @@ +--- +- name: Generate etesync-dav.service + become: true + ansible.builtin.template: + src: 'templates/etesync-dav.service.j2' + dest: '/usr/lib/systemd/system/etesync-dav.service' + mode: '0644' + owner: 'root' + group: 'root' + notify: + - 'Run systemctl restart etesync-dav.service' + - 'Run systemctl enable etesync-dav.service' diff --git a/templates/etesync-dav.service.j2 b/templates/etesync-dav.service.j2 new file mode 100644 index 0000000..b0b2352 --- /dev/null +++ b/templates/etesync-dav.service.j2 @@ -0,0 +1,11 @@ +{{ ansible_managed | comment }} +[Unit] +Description=Cal/CardDAV frontend for Etesync + +[Service] +Type=simple +Environment=ETESYNC_LISTEN_PORT={{ etesync_dav__port }} +ExecStart={{ etesync_dav__executable }} + +[Install] +WantedBy=default.target diff --git a/vars/main.yml b/vars/main.yml index 8296272..ece2320 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,8 +1,6 @@ --- -etesync_dav__repo: 'https://github.com/etesync/server.git' -etesync_dav__repo_api: 'https://api.github.com/repos/etesync/server/tags' -etesync_dav__venv: "{{ etesync_dav__venv_path }}/{{ etesync_dav_version_target }}" +etesync_dav__repo_api: 'https://api.github.com/repos/etesync/etesync-dav/releases/latest' # versionscheck -playbook_version_number: 15 # should be a integer +playbook_version_number: 16 playbook_version_path: 'role-l3d.etesync_dav.version'