Files
Watari-Ansible/playbooks/setup-dashboard.yml
2026-10-18 06:33:32 +00:00

119 lines
4.2 KiB
YAML

# setup-dashboard.yml
# Deploys AutoKuma as its own compose project (separate from /apps/docker)
# Required vault var (add to playbooks/vault.yaml):
# kuma_password
# Optional overrides (inventory / group_vars):
# kuma_url (default http://192.168.0.60:3001)
# kuma_username (default jester)
- name: Set AutoKuma defaults
ansible.builtin.set_fact:
autokuma_dir: /apps/autokuma
autokuma_data_dir: /apps/data/autokuma
autokuma_kuma_url: "{{ kuma_url | default('http://dashboard.netbird.cloud:3001') }}"
autokuma_kuma_user: "{{ kuma_username | default('admin') }}"
- name: Fail early if the Kuma password is not defined
ansible.builtin.assert:
that:
- kuma_password is defined
- kuma_password | length > 0
fail_msg: "kuma_password is missing - add it to playbooks/vault.yaml (ansible-vault edit)."
no_log: true
- name: Create AutoKuma compose directory
ansible.builtin.file:
path: "{{ autokuma_dir }}"
state: directory
owner: docker
group: docker
mode: '0755'
# Lives under /apps/data so the existing restic backup covers it. AutoKuma
# tracks the monitors it created in here; losing it can cause duplicates.
- name: Create AutoKuma data directory
ansible.builtin.file:
path: "{{ autokuma_data_dir }}"
state: directory
owner: docker
group: docker
mode: '0755'
- name: Write AutoKuma credentials (.env)
ansible.builtin.copy:
dest: "{{ autokuma_dir }}/.env"
content: |
AUTOKUMA__KUMA__USERNAME={{ autokuma_kuma_user }}
AUTOKUMA__KUMA__PASSWORD={{ kuma_password }}
owner: docker
group: docker
mode: '0600'
no_log: true
register: autokuma_env
# Image tag matters: the central Kuma runs v1 (louislam/uptime-kuma:1), so
# use the v1 build. ":latest"/":master" target Kuma v2 and won't match.
- name: Write AutoKuma docker-compose.yml
ansible.builtin.copy:
dest: "{{ autokuma_dir }}/docker-compose.yml"
content: |
services:
autokuma:
image: ghcr.io/bigboot/autokuma:uptime-kuma-v1-latest
container_name: autokuma
restart: unless-stopped
env_file:
- .env
environment:
AUTOKUMA__KUMA__URL: "{{ autokuma_kuma_url }}"
AUTOKUMA__TAG_NAME: AutoKuma
AUTOKUMA__DOCKER__HOSTS: unix:///var/run/docker.sock
# run-backups.yml stops the app stack nightly; wait before
# deleting monitors whose containers briefly disappear.
AUTOKUMA__DELETE_GRACE_PERIOD: "900"
AUTOKUMA__DEFAULT_SETTINGS: |-
*.max_retries: 3
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- {{ autokuma_data_dir }}:/data
owner: docker
group: docker
mode: '0644'
register: autokuma_compose
- name: Setup AutoKuma Service
ansible.builtin.copy:
dest: /etc/systemd/system/autokuma.service
content: |
[Unit]
Description=AutoKuma Service
After=network.target docker.service
Requires=docker.service
[Service]
Type=oneshot
RemainAfterExit=yes
User=docker
WorkingDirectory={{ autokuma_dir }}
ExecStart=/usr/bin/docker compose -f docker-compose.yml up -d
ExecStop=/usr/bin/docker compose -f docker-compose.yml stop
TimeoutStartSec=0
[Install]
WantedBy=multi-user.target
owner: root
group: root
mode: '0644'
register: autokuma_unit
- name: Reload systemd daemon
ansible.builtin.systemd:
daemon_reload: true
# "restarted" re-runs `compose up -d`, which recreates the container when
# the compose file or .env changed; otherwise just make sure it's running.
- name: Start AutoKuma Service
ansible.builtin.systemd:
name: autokuma
state: "{{ 'restarted' if (autokuma_env is changed or autokuma_compose is changed or autokuma_unit is changed) else 'started' }}"
enabled: true