Merge pull request #38 from corvus-migratorius/add-kuma

Add kuma
This commit is contained in:
Fogucoco
2025-12-18 15:42:31 +03:00
committed by GitHub
24 changed files with 396 additions and 1 deletions

View File

@@ -27,6 +27,7 @@
- [sshd](roles/sshd/README.md)
- [swapfile](roles/swapfile/README.md)
- [ufw](roles/ufw/README.md)
- [uptime_kuma](roles/uptime_kuma/README.md)
- [users](roles/users/README.md)
- [wg_hub](roles/wg_hub/README.md)
- [wg_spoke](roles/wg_spoke/README.md)

View File

@@ -1,7 +1,7 @@
---
namespace: genlab
name: common
version: 0.25.0
version: 0.26.0
readme: README.md
authors:
- Alexander Gorelyshev (corvus-migratorius@proton.me)

View File

@@ -6,3 +6,4 @@ collections:
- name: community.docker
- name: community.crypto
- name: maxhoesel.borgbackup
- name: lucasheld.uptime_kuma

View File

@@ -0,0 +1,16 @@
---
profile: production
strict: true
# Enable checking of loop variable prefixes in roles
loop_var_prefix: "^(__|{role}_)"
skip_list:
- var-naming[no-role-prefix]
warn_list:
- role-name[path]
- var-naming[no-role-prefix]
exclude_paths:
- .github/

13
roles/uptime_kuma/.gitignore vendored Normal file
View File

@@ -0,0 +1,13 @@
# IDE
.vscode
.idea
# test files
ansible.cfg
inventory.yml
playbook.yml
old/
uptime-kuma-data/

View File

@@ -0,0 +1,8 @@
---
rules:
brackets:
forbid: false
min-spaces-inside: 0
max-spaces-inside: 2
min-spaces-inside-empty: -1
max-spaces-inside-empty: 2

View File

@@ -0,0 +1,49 @@
ansible-uptime-kuma
=========
[![linters](https://github.com/corvus-migratorius/ansible-uptime-kuma/actions/workflows/linters.yaml/badge.svg)](https://github.com/corvus-migratorius/ansible-uptime-kuma/actions/workflows/linters.yaml)
[![kics](https://github.com/corvus-migratorius/ansible-uptime-kuma/actions/workflows/kics.yml/badge.svg)](https://github.com/corvus-migratorius/ansible-uptime-kuma/actions/workflows/kics.yml)
[![molecule](https://github.com/corvus-migratorius/ansible-uptime-kuma/actions/workflows/molecule.yaml/badge.svg)](https://github.com/corvus-migratorius/ansible-uptime-kuma/actions/workflows/molecule.yaml)
Deploy and confugure a containerized instance of [uptime-kuma](https://github.com/louislam/uptime-kuma).
Requirements
------------
None
Role Variables
--------------
- `uptime_kuma_img_version`: Kuma container version
- `uptime_kuma_project_dir`: where to put Docker Compose file and keep Kuma's data
- `uptime_kuma_port`: listening port for Kuma API and web interface
- `uptime_kuma_api_version`: version of the Python API
- `uptime_kuma_limit_cpus`: CPU cores limit for Kuma
- `uptime_kuma_limit_ram`: RAM limit for Kuma
- `kuma_tg_notif_name`: Name for Telegram notification method
- `kuma_tg_notif_is_default`: make this notification method default (default: `true`)
- `kuma_tg_notif_apply_existing`: connect all existing monitors to this notification method (default: `true`)
- `kuma_tg_bot_token`: Telegram bot token for the bot that will be delivering messages
- `kuma_tg_chat_id`: Telegram chat/group where the bot should deliver messages (bot must be a member there)
- `kuma_tg_notif_state`: `present` (default) or `absent`
Dependencies
------------
- `genlab.docker_ubuntu`
Example Playbook
----------------
See `molecule/default/converge`.
License
-------
BSD
Author Information
------------------
corvus-migratorius@proton.me

View File

@@ -0,0 +1,11 @@
---
name: ansible-uptime-kuma
channels:
- conda-forge
dependencies:
- actionlint
- python~=3.12.0
- pip>=24.2
- pip:
- -r requirements.txt
- -r requirements.ci.txt

View File

@@ -0,0 +1,9 @@
---
name: ansible-uptime-kuma
channels:
- conda-forge
dependencies:
- python~=3.12.0
- pip>=24.2
- pip:
- -r requirements.txt

View File

@@ -0,0 +1,8 @@
---
uptime_kuma_img_version: "1.23.16-alpine"
uptime_kuma_project_dir: "/uptime-kuma"
uptime_kuma_port: 3001
uptime_kuma_api_version: "1.2.0"
uptime_kuma_limit_cpus: 2
uptime_kuma_limit_ram: "2G"
uptime_kuma_default_notification_names: []

View File

@@ -0,0 +1 @@
---

View File

@@ -0,0 +1,17 @@
---
galaxy_info:
role_name: "uptime_kuma"
namespace: genlab
author: "Alexander Gorelyshev"
company: "Genlab, LLC"
description: ""
license: "MIT"
min_ansible_version: "2.1"
platforms:
- name: "Ubuntu"
versions: ["focal", "jammy"]
galaxy_tags: []
dependencies: []

View File

@@ -0,0 +1,25 @@
# kics-scan ignore
---
- name: Converge
hosts: all
vars:
test_admin_username: admin
test_admin_password: SDjj3$k4g9dhsjd__1dj
roles:
- genlab.common.docker_ubuntu
tasks:
- name: "Test the role"
tags: [role]
ansible.builtin.include_role:
name: "genlab.common.uptime_kuma"
vars:
kuma_api_username: "{{ test_admin_username }}"
kuma_api_password: "{{ test_admin_password }}"
kuma_tg_bot_token: 8161628020:AAF9doUFKSwdK4NZ8z58zVpqq0H1EdrKnI1
kuma_tg_chat_id: -4877676122
uptime_kuma_default_notification_names: ["Telegram alerts"]
kuma_monitors:
- name: "push-test"
type: push
interval: 30
description: "Test push monitor"

View File

@@ -0,0 +1,27 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: ubuntu
image: geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2204}-ansible:latest
pre_build_image: true
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
provisioner:
name: ansible
verifier:
name: ansible
lint: |
set -e
yamllint .
ansible-lint .

View File

@@ -0,0 +1,51 @@
# kics-scan disable=2e8d4922-8362-4606-8c14-aa10466a1ce3
---
- name: Verify
hosts: all
gather_facts: false
any_errors_fatal: true
vars:
test_admin_username: admin
# kics-scan ignore-line
test_admin_password: SDjj3$k4g9dhsjd__1dj
pre_tasks:
- name: "Include default vars"
ansible.builtin.include_vars:
dir: '{{ lookup("env", "MOLECULE_PROJECT_DIRECTORY") }}/defaults/'
extensions:
- 'yml'
tasks:
- name: "Verify uptime-kuma responds to HTTP requests"
register: uptime_kuma_this
until: uptime_kuma_this is ansible.builtin.success
retries: 3
delay: 3
ansible.builtin.uri:
url: "http://127.0.0.1:{{ uptime_kuma_port }}"
method: GET
status_code: 200
- name: "Get monitor information"
register: uptime_kuma_monitors
lucasheld.uptime_kuma.monitor_info:
api_url: http://127.0.0.1:3001
api_username: "{{ test_admin_username }}"
api_password: "{{ test_admin_password }}"
- name: "Get test monitor information"
failed_when: uptime_kuma_monitor_info is not defined
ansible.builtin.set_fact:
uptime_kuma_monitor_info: "{{ uptime_kuma_monitors.monitors | selectattr('name', 'equalto', 'push-test') | list | first }}"
- name: "Check test monitor configuration"
loop:
- {key: "type", value: "push"}
- {key: "interval", value: 30}
- {key: "description", value: "Test push monitor"}
- {key: notificationIDList, value: [1]} # names are not stored, only integer IDs
ansible.builtin.assert:
that: "uptime_kuma_monitor_info[item.key] == item.value"
success_msg: "Test monitor has correctly configured {{ item.key }}: {{ item.value }}"
fail_msg: "Incorrect test monitor configuration for {{ item.key }}: expected {{ item.value }}, got: {{ uptime_kuma_monitor_info[item.key] }}"

View File

@@ -0,0 +1,6 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:recommended"
]
}

View File

@@ -0,0 +1,6 @@
ansible-lint~=25.2.1
docker~=7.1.0
molecule~=24.12.0
molecule-plugins[docker]~=23.6.0
requests==2.31.0 # pinned to the latest version not breaking Docker SDK
yamllint~=1.35.1

View File

@@ -0,0 +1 @@
ansible

View File

@@ -0,0 +1,8 @@
---
roles:
- name: genlab.docker_ubuntu
src: https://github.com/corvus-migratorius/ansible-docker-ubuntu.git
collections:
- name: lucasheld.uptime_kuma
version: "1.2.0"

View File

@@ -0,0 +1,66 @@
---
- name: "Wait for uptime-kuma to start"
ansible.builtin.wait_for:
port: "{{ uptime_kuma_port }}"
timeout: 30
- name: "Set up uptime-kuma credentials"
lucasheld.uptime_kuma.setup:
api_url: http://127.0.0.1:{{ uptime_kuma_port }}
api_username: "{{ kuma_api_username }}"
api_password: "{{ kuma_api_password }}"
- name: "Login with credentials once and register the result"
register: uptime_kuma_result
lucasheld.uptime_kuma.login:
api_url: http://127.0.0.1:{{ uptime_kuma_port }}
api_username: "{{ kuma_api_username }}"
api_password: "{{ kuma_api_password }}"
- name: "Extract the token from the result and set it as fact"
ansible.builtin.set_fact:
uptime_kuma_api_token: "{{ uptime_kuma_result.token }}"
- name: "Configure Telegram notification method"
when:
- kuma_tg_bot_token is defined
- kuma_tg_chat_id is defined
lucasheld.uptime_kuma.notification:
api_url: http://127.0.0.1:{{ uptime_kuma_port }}
api_token: "{{ uptime_kuma_api_token }}"
type: telegram
name: "{{ kuma_tg_notif_name | default('Telegram alerts') }}"
isDefault: "{{ kuma_tg_notif_is_default | default(true) }}"
applyExisting: "{{ kuma_tg_notif_apply_existing | default(true) }}"
telegramBotToken: "{{ kuma_tg_bot_token }}"
telegramChatID: "{{ kuma_tg_chat_id }}"
state: "present"
- name: "Create monitor groups"
when: kuma_monitor_groups is defined
loop: "{{ kuma_monitor_groups }}"
lucasheld.uptime_kuma.monitor:
api_url: http://127.0.0.1:{{ uptime_kuma_port }}
api_token: "{{ uptime_kuma_api_token }}"
type: "group"
name: "{{ item }}"
- name: "Create monitors"
loop: "{{ kuma_monitors }}"
lucasheld.uptime_kuma.monitor:
api_url: http://127.0.0.1:{{ uptime_kuma_port }}
api_token: "{{ uptime_kuma_api_token }}"
type: "{{ item.type }}"
name: "{{ item.name }}"
upsideDown: "{{ item.upside_down | default(false) }}"
url: "{{ item.url | default(omit) }}"
hostname: "{{ item.hostname | default(omit) }}"
port: "{{ item.port | default(omit) }}"
interval: "{{ item.interval | default(60) }}"
description: "{{ item.description | default(omit) }}"
parent_name: "{{ item.parent_name | default(omit) }}"
notification_names: "{{ item.notification_names | default(uptime_kuma_default_notification_names) }}"
state: "{{ kuma_tg_notif_state | default('present') }}"
ignoreTls: "{{ item.ignore_tls | default(false) }}"
jsonPath: "{{ item.query | default(omit) }}"
expectedValue: "{{ item.expected_value | default(omit) }}"

View File

@@ -0,0 +1,27 @@
---
- name: "Ensure project directory exists"
ansible.builtin.file:
path: "{{ uptime_kuma_project_dir }}"
state: directory
owner: root
group: root
mode: "0770"
- name: "Push the Compose file"
ansible.builtin.template:
src: "docker-compose.yml.j2"
dest: "{{ uptime_kuma_project_dir }}/docker-compose.yml"
owner: root
group: root
mode: "0660"
- name: "Deploy uptime-kuma via Docker Compose"
community.docker.docker_compose_v2:
state: present
project_src: "{{ uptime_kuma_project_dir }}"
- name: "Install Python dependencies"
ansible.builtin.pip:
name: "uptime-kuma-api"
version: "{{ uptime_kuma_api_version }}"
break_system_packages: true

View File

@@ -0,0 +1,6 @@
---
- name: "Include deployment tasks"
ansible.builtin.include_tasks: "deploy.yml"
- name: "Include configuration tasks"
ansible.builtin.include_tasks: "configure.yml"

View File

@@ -0,0 +1,37 @@
# kics-scan disable=ce76b7d0-9e77-464d-b86f-c5c48e03e22d
---
services:
uptime-kuma:
image: louislam/uptime-kuma:{{ uptime_kuma_img_version }}
container_name: uptime-kuma
volumes:
- {{ uptime_kuma_project_dir }}/data:/app/data
restart: unless-stopped
cap_drop:
- ALL
cap_add:
- CAP_NET_ADMIN
- CAP_NET_RAW
- CAP_SETGID
- CAP_SETUID
security_opt:
- no-new-privileges:true
network_mode: host
healthcheck:
test: ["CMD-SHELL", "node extra/healthcheck.js"]
interval: 60s
timeout: 10s
retries: 3
logging:
driver: journald
options:
tag: uptime-kuma
deploy:
replicas: 1
resources:
limits:
cpus: {{ uptime_kuma_limit_cpus }}
memory: {{ uptime_kuma_limit_ram }}
volumes:
uptime-kuma-data:

View File

@@ -0,0 +1 @@
---