certbot cannot issue for internal hostnames (*.nas.local), which made nginx-enabled services with internal names fail on deploy. Add a <service>_nginx_letsencrypt flag (default false) and computed <service>_nginx_ssl_certificate/_key paths: when off the vhost uses the shared self-signed cert (nginx_default_ssl_cert), when on it uses the Let's Encrypt lineage. Gate the certbot include on the flag and apply the pattern to all service roles (deluge, fdroid, gitea, grafana, immich, metabase, ntfy, prowlarr, radarr, seerr, static_web, uptime_kuma).
104 lines
3.4 KiB
YAML
104 lines
3.4 KiB
YAML
---
|
|
- name: Create uptime-kuma project directory
|
|
ansible.builtin.file:
|
|
path: "{{ podman_projects_dir | default('/opt/podman') }}/uptime-kuma"
|
|
state: directory
|
|
owner: "{{ ansible_user }}"
|
|
group: "{{ ansible_user }}"
|
|
mode: "0755"
|
|
|
|
- name: Create uptime-kuma data directory
|
|
ansible.builtin.file:
|
|
path: "{{ uptime_kuma_data_dir }}"
|
|
state: directory
|
|
owner: "{{ ansible_user }}"
|
|
group: "{{ ansible_user }}"
|
|
mode: "0755"
|
|
|
|
- name: Get current uptime_kuma image ID
|
|
ansible.builtin.command: "podman image inspect --format {% raw %}{{.Id}}{% endraw %} {{ uptime_kuma_image }}:{{ uptime_kuma_version }}"
|
|
register: uptime_kuma_image_id_before
|
|
failed_when: false # image may not exist yet on first deploy
|
|
changed_when: false
|
|
become: false
|
|
become_user: "{{ ansible_user }}"
|
|
|
|
- name: Pull Uptime Kuma container image
|
|
ansible.builtin.command: "podman pull --quiet {{ uptime_kuma_image }}:{{ uptime_kuma_version }}"
|
|
register: pull_result
|
|
changed_when: pull_result.stdout != uptime_kuma_image_id_before.stdout
|
|
become: false
|
|
become_user: "{{ ansible_user }}"
|
|
notify: Restart uptime-kuma
|
|
|
|
- name: Deploy Kubernetes YAML for uptime-kuma
|
|
ansible.builtin.template:
|
|
src: uptime-kuma.yaml.j2
|
|
dest: "{{ podman_projects_dir | default('/opt/podman') }}/uptime-kuma/uptime-kuma.yaml"
|
|
owner: "{{ ansible_user }}"
|
|
group: "{{ ansible_user }}"
|
|
mode: "0644"
|
|
notify: Restart uptime-kuma
|
|
|
|
- name: Get home directory for {{ ansible_user }}
|
|
ansible.builtin.getent:
|
|
database: passwd
|
|
key: "{{ ansible_user }}"
|
|
|
|
- name: Set user home directory fact
|
|
ansible.builtin.set_fact:
|
|
user_home_dir: "{{ ansible_facts['getent_passwd'][ansible_user][4] }}"
|
|
|
|
- name: Create systemd user directory for uptime-kuma
|
|
ansible.builtin.file:
|
|
path: "{{ user_home_dir }}/.config/systemd/user"
|
|
state: directory
|
|
owner: "{{ ansible_user }}"
|
|
group: "{{ ansible_user }}"
|
|
mode: "0755"
|
|
|
|
- name: Create systemd service for uptime-kuma (user scope)
|
|
ansible.builtin.template:
|
|
src: uptime-kuma.service.j2
|
|
dest: "{{ user_home_dir }}/.config/systemd/user/uptime-kuma.service"
|
|
owner: "{{ ansible_user }}"
|
|
group: "{{ ansible_user }}"
|
|
mode: "0644"
|
|
notify: Reload systemd user
|
|
|
|
- name: Enable lingering for user {{ ansible_user }}
|
|
ansible.builtin.command: "loginctl enable-linger {{ ansible_user }}"
|
|
when: ansible_user != 'root'
|
|
|
|
- name: Enable and start uptime-kuma service (user scope)
|
|
ansible.builtin.systemd:
|
|
name: uptime-kuma.service
|
|
enabled: true
|
|
state: started
|
|
scope: user
|
|
become: false
|
|
become_user: "{{ ansible_user }}"
|
|
|
|
- name: Provision TLS certificate for uptime-kuma
|
|
ansible.builtin.include_tasks: "{{ role_path }}/../nginx/tasks/certbot.yml"
|
|
vars:
|
|
certbot_hostname: "{{ uptime_kuma_nginx_hostname }}"
|
|
when: uptime_kuma_nginx_enabled and uptime_kuma_nginx_letsencrypt
|
|
|
|
- name: Deploy nginx vhost configuration for uptime-kuma
|
|
ansible.builtin.template:
|
|
src: nginx-vhost.conf.j2
|
|
dest: "{{ nginx_conf_dir | default('/etc/nginx/conf.d') }}/uptime-kuma.conf"
|
|
owner: root
|
|
group: root
|
|
mode: "0644"
|
|
when: uptime_kuma_nginx_enabled
|
|
notify: Reload nginx
|
|
|
|
- name: Remove nginx vhost configuration for uptime-kuma
|
|
ansible.builtin.file:
|
|
path: "{{ nginx_conf_dir | default('/etc/nginx/conf.d') }}/uptime-kuma.conf"
|
|
state: absent
|
|
when: not uptime_kuma_nginx_enabled
|
|
notify: Reload nginx
|