diff --git a/hosts.ini b/hosts.ini index 44212dd..06902bf 100644 --- a/hosts.ini +++ b/hosts.ini @@ -41,3 +41,6 @@ [photoview] 192.168.0.3 static_ip=192.168.0.3 + +[calathea] +192.168.0.2 static_ip=192.168.0.2 diff --git a/roles/calathea-web/meta/main.yml b/roles/calathea-web/meta/main.yml new file mode 100644 index 0000000..1dbd0f6 --- /dev/null +++ b/roles/calathea-web/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - role: caddy diff --git a/roles/calathea-web/tasks/main.yml b/roles/calathea-web/tasks/main.yml new file mode 100644 index 0000000..9bec970 --- /dev/null +++ b/roles/calathea-web/tasks/main.yml @@ -0,0 +1,9 @@ +--- +- name: Ensure Caddyfile is present + template: + src: 'calathea.Caddyfile.j2' + dest: '/etc/caddy/calathea.Caddyfile' + owner: root + group: root + mode: '0644' + notify: caddy-reload diff --git a/roles/calathea-web/templates/calathea.Caddyfile.j2 b/roles/calathea-web/templates/calathea.Caddyfile.j2 new file mode 100644 index 0000000..dd1eec5 --- /dev/null +++ b/roles/calathea-web/templates/calathea.Caddyfile.j2 @@ -0,0 +1,3 @@ +plants.roosens.me { + reverse_proxy {{ hostvars[groups['calathea'][0]].static_ip }}:8013 +} diff --git a/roles/calathea/files/calathea.data.backup.sh b/roles/calathea/files/calathea.data.backup.sh new file mode 100644 index 0000000..0161e32 --- /dev/null +++ b/roles/calathea/files/calathea.data.backup.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +data_dir='/mnt/data1/calathea' +snapshot_dir="${data_dir}.snapshot" + +# Read-only snapshot for atomic backup +btrfs subvolume snapshot -r "$data_dir" "$snapshot_dir" || exit $? + +/usr/local/bin/restic backup "$snapshot_dir" + +# Always remove snapshot subvolume, even if restic fails +btrfs subvolume delete "$snapshot_dir" diff --git a/roles/calathea/files/calathea.service b/roles/calathea/files/calathea.service new file mode 100644 index 0000000..66e091a --- /dev/null +++ b/roles/calathea/files/calathea.service @@ -0,0 +1,13 @@ +[Unit] +Description=Simple plant tracker +After=docker.service +Requires=docker.service + +[Service] +Type=exec +WorkingDirectory=/etc/calathea +ExecStart=/usr/bin/docker compose up +ExecStop=/usr/bin/docker compose down + +[Install] +WantedBy=multi-user.target diff --git a/roles/calathea/files/compose.yml b/roles/calathea/files/compose.yml new file mode 100644 index 0000000..4c3489c --- /dev/null +++ b/roles/calathea/files/compose.yml @@ -0,0 +1,8 @@ +services: + app: + image: 'git.rustybever.be/chewing_bever/calathea:latest' + + ports: + - '8013:8000' + volumes: + - '/mnt/data1/calathea/data:/data' diff --git a/roles/calathea/handlers/main.yml b/roles/calathea/handlers/main.yml new file mode 100644 index 0000000..0101ea2 --- /dev/null +++ b/roles/calathea/handlers/main.yml @@ -0,0 +1,5 @@ +--- +- name: 'restart calathea' + ansible.builtin.service: + name: 'calathea' + state: 'restarted' diff --git a/roles/calathea/tasks/main.yml b/roles/calathea/tasks/main.yml new file mode 100644 index 0000000..126e0df --- /dev/null +++ b/roles/calathea/tasks/main.yml @@ -0,0 +1,68 @@ +--- +- name: Ensure data directory is present + ansible.builtin.file: + path: '/mnt/data1/calathea' + state: directory + mode: '0755' + owner: 'root' + group: 'root' + +- name: Ensure data subvolumes are present + community.general.btrfs_subvolume: + name: '/calathea/{{ item }}' + loop: + - 'data' + +- name: Ensure subvolume permissions are correct + ansible.builtin.file: + path: "/mnt/data1/calathea/{{ item }}" + state: directory + mode: '0755' + owner: '82' + group: '82' + loop: + - 'data' + +- name: Ensure configuration directory is present + ansible.builtin.file: + path: '/etc/calathea' + state: directory + mode: '0755' + +- name: Ensure compose file is present + ansible.builtin.copy: + src: 'compose.yml' + dest: '/etc/calathea/compose.yml' + mode: '0644' + owner: 'root' + group: 'root' + notify: 'restart calathea' + +- name: Ensure backup scripts are present + ansible.builtin.copy: + src: "calathea.{{ item }}.backup.sh" + dest: "/etc/backups/calathea.{{ item }}.backup.sh" + owner: 'root' + group: 'root' + mode: '0644' + loop: + - 'data' + +- name: Ensure service file is present + ansible.builtin.copy: + src: 'calathea.service' + dest: '/lib/systemd/system/calathea.service' + owner: 'root' + group: 'root' + mode: '0644' + register: res + +- name: systemd-reload + ansible.builtin.systemd_service: + daemon_reload: true + when: 'res.changed' + +- name: Ensure calathea service is enabled + ansible.builtin.service: + name: 'calathea' + enabled: true diff --git a/ruby.yml b/ruby.yml index d9b900c..7738e2b 100644 --- a/ruby.yml +++ b/ruby.yml @@ -70,8 +70,14 @@ - kanboard tags: kanboard -- hosts: nas +- hosts: ruby become: yes roles: - matrix tags: matrix + +- hosts: ruby + become: yes + roles: + - calathea + tags: calathea diff --git a/web.yml b/web.yml index 4a6274a..1320aac 100644 --- a/web.yml +++ b/web.yml @@ -64,3 +64,9 @@ roles: - photoview-web tags: photoview + +- hosts: web + become: yes + roles: + - calathea-web + tags: calathea