add uptime_kuma role
This commit is contained in:
66
roles/uptime_kuma/tasks/configure.yml
Normal file
66
roles/uptime_kuma/tasks/configure.yml
Normal file
@@ -0,0 +1,66 @@
|
||||
---
|
||||
- name: "Wait for uptime-kuma to start"
|
||||
ansible.builtin.wait_for:
|
||||
port: "{{ kuma_port }}"
|
||||
timeout: 30
|
||||
|
||||
- name: "Set up uptime-kuma credentials"
|
||||
lucasheld.uptime_kuma.setup:
|
||||
api_url: http://127.0.0.1:{{ kuma_port }}
|
||||
api_username: "{{ kuma_api_username }}"
|
||||
api_password: "{{ kuma_api_password }}"
|
||||
|
||||
- name: "Login with credentials once and register the result"
|
||||
register: result
|
||||
lucasheld.uptime_kuma.login:
|
||||
api_url: http://127.0.0.1:{{ 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:
|
||||
kuma_api_token: "{{ 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:{{ kuma_port }}
|
||||
api_token: "{{ 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:{{ kuma_port }}
|
||||
api_token: "{{ kuma_api_token }}"
|
||||
type: "group"
|
||||
name: "{{ item }}"
|
||||
|
||||
- name: "Create monitors"
|
||||
loop: "{{ kuma_monitors }}"
|
||||
lucasheld.uptime_kuma.monitor:
|
||||
api_url: http://127.0.0.1:{{ kuma_port }}
|
||||
api_token: "{{ 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(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) }}"
|
||||
27
roles/uptime_kuma/tasks/deploy.yml
Normal file
27
roles/uptime_kuma/tasks/deploy.yml
Normal file
@@ -0,0 +1,27 @@
|
||||
---
|
||||
- name: "Ensure project directory exists"
|
||||
ansible.builtin.file:
|
||||
path: "{{ 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: "{{ 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: "{{ kuma_project_dir }}"
|
||||
|
||||
- name: "Install Python dependencies"
|
||||
ansible.builtin.pip:
|
||||
name: "uptime-kuma-api"
|
||||
version: "{{ kuma_api_version }}"
|
||||
break_system_packages: true
|
||||
6
roles/uptime_kuma/tasks/main.yml
Normal file
6
roles/uptime_kuma/tasks/main.yml
Normal 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"
|
||||
Reference in New Issue
Block a user