From a28793b684b3299c95e04924ed18e0fe5cd6f107 Mon Sep 17 00:00:00 2001 From: meisterfischy Date: Sat, 22 Jan 2022 17:17:33 +0100 Subject: Added a role for a calibre-web server --- roles/calibre/README.md | 16 ++++++++++ roles/calibre/files/white.pdf | Bin 0 -> 11540 bytes roles/calibre/handlers/main.yml | 7 +++++ roles/calibre/tasks/main.yml | 56 +++++++++++++++++++++++++++++++++ roles/calibre/templates/cps.service.j2 | 14 +++++++++ 5 files changed, 93 insertions(+) create mode 100644 roles/calibre/README.md create mode 100644 roles/calibre/files/white.pdf create mode 100644 roles/calibre/handlers/main.yml create mode 100644 roles/calibre/tasks/main.yml create mode 100644 roles/calibre/templates/cps.service.j2 (limited to 'roles') diff --git a/roles/calibre/README.md b/roles/calibre/README.md new file mode 100644 index 0000000..1dbc079 --- /dev/null +++ b/roles/calibre/README.md @@ -0,0 +1,16 @@ +# calibre-web + +Installed calibre-web with optional features if specified. +Assumes the ssl cert and key are located at `/etc/ssl/certs/FQDN.(pem | key)`. + +```yaml +ssl: true + +features: + - ldap + - oauth + - metadata + - comics +``` + +[List of possible features](https://github.com/janeczku/calibre-web/wiki/Dependencies-in-Calibre-Web-Linux-Windows) diff --git a/roles/calibre/files/white.pdf b/roles/calibre/files/white.pdf new file mode 100644 index 0000000..95ea114 Binary files /dev/null and b/roles/calibre/files/white.pdf differ diff --git a/roles/calibre/handlers/main.yml b/roles/calibre/handlers/main.yml new file mode 100644 index 0000000..735348d --- /dev/null +++ b/roles/calibre/handlers/main.yml @@ -0,0 +1,7 @@ +--- +- name: Restart cps + systemd: + name: cps.service + state: restarted + enabled: true + become: true diff --git a/roles/calibre/tasks/main.yml b/roles/calibre/tasks/main.yml new file mode 100644 index 0000000..705d167 --- /dev/null +++ b/roles/calibre/tasks/main.yml @@ -0,0 +1,56 @@ +--- +- name: Install packages + apt: + name: + - calibre + - python3-pip + - libsasl2-dev + - libldap2-dev + - libssl-dev + become: true + +- name: Check library existence + stat: + path: /opt/calibre/library + register: library + +- name: Copy first book + copy: + dest: /opt/calibre + src: white.pdf + become: true + when: not library.stat.exists + +- name: Initialize calibre library + shell: + cmd: calibredb --library-path=library add white.pdf & calibredb --library-path=library remove 1 + chdir: /opt/calibre + creates: library + become: true + +- name: Change ownership of calibre library + file: + path: /opt/calibre/library + recurse: true + owner: calibre + group: calibre + become: true + +- name: Remove first book file + file: + path: /opt/calibre/white.pdf + state: absent + become: true + when: not library.stat.exists + +- name: Install calibre web with pip + pip: + name: calibreweb[{{ features | join(",") }}] + become: true + +- name: Create systemd unit + template: + dest: /etc/systemd/system/cps.service + src: cps.service.j2 + become: true + notify: Restart cps diff --git a/roles/calibre/templates/cps.service.j2 b/roles/calibre/templates/cps.service.j2 new file mode 100644 index 0000000..005297d --- /dev/null +++ b/roles/calibre/templates/cps.service.j2 @@ -0,0 +1,14 @@ +[Unit] +Description=Calibre-Web + +[Service] +Type=simple +User=calibre +{% if ssl == true %} +ExecStart=/usr/local/bin/cps -c '/etc/ssl/certs/{{ ansible_facts.fqdn }}.pem' -k '/etc/ssl/private/{{ ansible_facts.fqdn }}.key' +{% else %} +ExecStart=/usr/local/bin/cps +{% endif %} + +[Install] +WantedBy=multi-user.target -- cgit v1.2.3