diff --git a/roles/sys-ctl-alm-compose/vars/main.yml b/roles/sys-ctl-alm-compose/vars/main.yml index 916ce01b..8e3d7fd8 100644 --- a/roles/sys-ctl-alm-compose/vars/main.yml +++ b/roles/sys-ctl-alm-compose/vars/main.yml @@ -1,7 +1,15 @@ system_service_id: sys-ctl-alm-compose@ -SYSTEMCTL_ALARM_COMPOSER_SUBSERVICES: - - 'sys-ctl-alm-email' - - 'sys-ctl-alm-telegram' +SYSTEMCTL_ALARM_COMPOSER_SUBSERVICES: >- + {{ + ['sys-ctl-alm-email'] + + + ( + ['sys-ctl-alm-telegram'] + if (TELEGRAM_BOT_TOKEN | default('') | trim != '') + and (TELEGRAM_CHAT_ID | default('') | trim != '') + else [] + ) + }} SYSTEMCTL_ALARM_COMPOSER_DUMMY_MESSAGE: "[Info] Dummy Message: No Failure; Ansible is initializing {{ SOFTWARE_NAME }} on {{ inventory_hostname }}." \ No newline at end of file diff --git a/roles/sys-ctl-alm-telegram/defaults/main.yml b/roles/sys-ctl-alm-telegram/defaults/main.yml index 0770ef9c..396b1d16 100644 --- a/roles/sys-ctl-alm-telegram/defaults/main.yml +++ b/roles/sys-ctl-alm-telegram/defaults/main.yml @@ -1,2 +1,2 @@ -telegram_bot_token: '' # The token of your telegram bot -telegram_chat_id: '' # The id of your telegram chat \ No newline at end of file +TELEGRAM_BOT_TOKEN: '' # The token of your telegram bot +TELEGRAM_CHAT_ID: '' # The id of your telegram chat \ No newline at end of file diff --git a/roles/sys-ctl-alm-telegram/tasks/01_core.yml b/roles/sys-ctl-alm-telegram/tasks/01_core.yml index 7395f7de..88aec001 100644 --- a/roles/sys-ctl-alm-telegram/tasks/01_core.yml +++ b/roles/sys-ctl-alm-telegram/tasks/01_core.yml @@ -1,13 +1,13 @@ - name: Fail if Telegram bot credentials are not set assert: that: - - telegram_bot_token != "" - - telegram_chat_id != "" + - TELEGRAM_BOT_TOKEN != "" + - TELEGRAM_CHAT_ID != "" fail_msg: | Telegram configuration is incomplete! Please provide non‑empty values for: - - telegram_bot_token # Your Telegram bot’s API token - - telegram_chat_id # The Telegram chat ID to send messages to + - TELEGRAM_BOT_TOKEN # Your Telegram bot’s API token + - TELEGRAM_CHAT_ID # The Telegram chat ID to send messages to when: MODE_ASSERT | bool - include_role: diff --git a/roles/sys-ctl-alm-telegram/templates/script.sh.j2 b/roles/sys-ctl-alm-telegram/templates/script.sh.j2 index ab3662d5..097b5b9c 100644 --- a/roles/sys-ctl-alm-telegram/templates/script.sh.j2 +++ b/roles/sys-ctl-alm-telegram/templates/script.sh.j2 @@ -13,6 +13,6 @@ fi # send the Telegram message /usr/bin/curl -s -X POST \ - "https://api.telegram.org/bot{{ telegram_bot_token }}/sendMessage" \ - -d chat_id="{{ telegram_chat_id }}" \ + "https://api.telegram.org/bot{{ TELEGRAM_BOT_TOKEN }}/sendMessage" \ + -d chat_id="{{ TELEGRAM_CHAT_ID }}" \ --data-urlencode text="service ${friendly//\//-} on ${host} failed"