Обновить playbooks/update.yml
This commit is contained in:
+43
-4
@@ -4,6 +4,14 @@
|
|||||||
become: yes
|
become: yes
|
||||||
gather_facts: yes
|
gather_facts: yes
|
||||||
|
|
||||||
|
vars:
|
||||||
|
# Telegram bot token (из задания)
|
||||||
|
telegram_token: "8820292312:AAECFO1AEWOJTh30zNuhyjC5C81o_qJHQcM"
|
||||||
|
# ID чата, куда отправлять уведомления (из вашего сообщения)
|
||||||
|
telegram_chat_id: "407968638"
|
||||||
|
# Прокси для Telegram API (формат для curl)
|
||||||
|
telegram_proxy: "socks5h://administrator:60NthRegT@192.168.0.218:1080"
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
# 1. Показываем текущую версию ОС и ядра (для контекста)
|
# 1. Показываем текущую версию ОС и ядра (для контекста)
|
||||||
- name: Show OS and kernel version
|
- name: Show OS and kernel version
|
||||||
@@ -70,7 +78,38 @@
|
|||||||
# post_reboot_delay: 30
|
# post_reboot_delay: 30
|
||||||
# when: reboot_required_file.stat.exists
|
# when: reboot_required_file.stat.exists
|
||||||
|
|
||||||
# - name: Reboot not required
|
- name: Reboot not required
|
||||||
# debug:
|
debug:
|
||||||
# msg: "No reboot required."
|
msg: "No reboot required."
|
||||||
# when: not reboot_required_file.stat.exists
|
when: not reboot_required_file.stat.exists
|
||||||
|
|
||||||
|
# ===== ОПОВЕЩЕНИЕ В TELEGRAM =====
|
||||||
|
- name: Build notification message
|
||||||
|
set_fact:
|
||||||
|
message_text: |
|
||||||
|
<b>Host:</b> {{ inventory_hostname }}
|
||||||
|
<b>OS:</b> {{ ansible_distribution }} {{ ansible_distribution_version }}
|
||||||
|
<b>Kernel:</b> {{ ansible_kernel }}
|
||||||
|
<b>Update result:</b> {% if apt_upgrade_result.changed %}✅ Updates applied{% else %}✅ No updates needed{% endif %}
|
||||||
|
{% if apt_upgrade_result.changed and upgradable_before.stdout_lines is defined and upgradable_before.stdout_lines | length > 0 %}
|
||||||
|
<b>Upgraded packages (old → new):</b>
|
||||||
|
{{ upgradable_before.stdout_lines | select('match', '^[^/]+/') | list | join('\n') }}
|
||||||
|
{% endif %}
|
||||||
|
<b>Reboot required:</b> {% if reboot_required_file.stat.exists %}⚠️ YES{% else %}No{% endif %}
|
||||||
|
|
||||||
|
- name: Send Telegram notification
|
||||||
|
shell: |
|
||||||
|
# Экранируем текст для JSON
|
||||||
|
MESSAGE=$(cat <<'EOF' | python3 -c 'import sys, json; print(json.dumps(sys.stdin.read()))'
|
||||||
|
{{ message_text }}
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
curl -x {{ telegram_proxy }} \
|
||||||
|
-s -X POST \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "{\"chat_id\": \"{{ telegram_chat_id }}\", \"text\": $MESSAGE, \"parse_mode\": \"HTML\"}" \
|
||||||
|
https://api.telegram.org/bot{{ telegram_token }}/sendMessage
|
||||||
|
when:
|
||||||
|
- telegram_token | default('') != ''
|
||||||
|
- telegram_chat_id | default('') != ''
|
||||||
|
ignore_errors: yes
|
||||||
Reference in New Issue
Block a user