mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-29 23:08:06 +02:00
Changed systemd-notifier namings
This commit is contained in:
41
roles/systemd-notifier-telegram/README.md
Normal file
41
roles/systemd-notifier-telegram/README.md
Normal file
@@ -0,0 +1,41 @@
|
||||
## Description
|
||||
|
||||
This Ansible role installs the necessary components for sending Telegram notifications through systemd when any service fails. It configures the `systemd-notifier-telegram` service and handles the setup of Telegram bot parameters and notification templates.
|
||||
|
||||
Features include:
|
||||
|
||||
- Installation and configuration of a Telegram notifier service.
|
||||
- Customizable templates for Telegram messages sent on service failure.
|
||||
|
||||
This role is part of the `systemd-notifier` suite, which provides a comprehensive solution for service failure notifications in a systemd environment.
|
||||
|
||||
## Requirements
|
||||
|
||||
This role has the following requirements:
|
||||
|
||||
- Access to a Telegram bot token for sending messages.
|
||||
- Availability of the `curl` package on the target system.
|
||||
|
||||
## Role Variables
|
||||
|
||||
The following variables can be customized in the role's `vars/main.yml` file:
|
||||
|
||||
- `systemd_telegram_folder`: The path to the folder where Telegram-related scripts and configurations will be stored.
|
||||
- `systemd_telegram_script`: The full path to the systemd-telegram.sh script.
|
||||
|
||||
This role was created as part of a conversation with OpenAI's ChatGPT and can be found [here](https://chat.openai.com/share/96e4ca12-0888-41c0-9cfc-29c0180f0dba).
|
||||
|
||||
## Usage
|
||||
|
||||
To use this role, include it as a dependency in your playbook or role that requires Telegram notifications. Ensure that the `systemd-notifier-telegram` role is correctly referenced and configured.
|
||||
|
||||
## License
|
||||
|
||||
This Ansible role is licensed under the AGPL v3 License. See the LICENSE file for the full license text.
|
||||
|
||||
## Contact Information
|
||||
|
||||
For any questions or feedback, please contact the author:
|
||||
|
||||
Author: Kevin Veen-Birkenbach
|
||||
Email: kevin@veen.world
|
4
roles/systemd-notifier-telegram/handlers/main.yml
Normal file
4
roles/systemd-notifier-telegram/handlers/main.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
- name: "restart systemd-notifier-telegram service"
|
||||
systemd:
|
||||
name: systemd-notifier-telegram.service
|
||||
daemon_reload: yes
|
21
roles/systemd-notifier-telegram/tasks/main.yml
Normal file
21
roles/systemd-notifier-telegram/tasks/main.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
- name: install curl
|
||||
pacman:
|
||||
name: curl
|
||||
state: present
|
||||
|
||||
- name: Create a directory with a subdirectory
|
||||
ansible.builtin.file:
|
||||
path: "{{systemd_telegram_folder}}"
|
||||
state: directory
|
||||
mode: '0755'
|
||||
|
||||
- name: configure systemd-notifier-telegram.sh
|
||||
template:
|
||||
src: systemd-notifier-telegram.sh.j2
|
||||
dest: "{{ systemd_telegram_script }}"
|
||||
|
||||
- name: configure systemd-notifier-telegram.service
|
||||
template:
|
||||
src: systemd-notifier-telegram@.service.j2
|
||||
dest: "/etc/systemd/system/systemd-notifier-telegram@.service"
|
||||
notify: "restart systemd-notifier-telegram service"
|
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
/usr/bin/curl -s -X POST https://api.telegram.org/bot{{ telegram_bot_token }}/sendMessage -d chat_id={{ telegram_chat_id }} -d text="service $1 failed"
|
@@ -0,0 +1,8 @@
|
||||
[Unit]
|
||||
Description=status Telegram message for %i to user
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/bin/bash {{ systemd_telegram_script }} %i
|
||||
User=root
|
||||
Group=systemd-journal
|
2
roles/systemd-notifier-telegram/vars/main.yml
Normal file
2
roles/systemd-notifier-telegram/vars/main.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
systemd_telegram_folder: "/opt/ansible-roles/systemd-notifier-telegram/"
|
||||
systemd_telegram_script: "{{systemd_telegram_folder}}systemd-notifier-telegram.sh"
|
Reference in New Issue
Block a user