46 lines
1.6 KiB
YAML
46 lines
1.6 KiB
YAML
---
|
|
- name: Internet connection test block
|
|
block:
|
|
- name: Test reachability to ya.ru
|
|
become: true # Usually it's not necessary, but sometimes ping is disabled for non-root by default
|
|
ansible.builtin.shell: ping -c 5 ya.ru > /dev/null
|
|
changed_when: false # This task does not change the system
|
|
|
|
rescue:
|
|
# This won't work for now. CA certificate reissuing is required!
|
|
- name: Create a test file
|
|
become: false
|
|
ansible.builtin.uri:
|
|
url: "{{ ha_addr }}/api/webhook/{{ ha_webhook_token }}"
|
|
ca_path: ../files/ca.pem
|
|
delegate_to: 127.0.0.1
|
|
# TODO: REMOVE THIS AFTER REISSUING CA CERTIFICATE!
|
|
failed_when: false
|
|
|
|
- name: Disk free space test block
|
|
block:
|
|
- name: Test free disk space in root
|
|
become: false
|
|
# We have to use this complicated pipeline because of Alpine and its wierd df implementation
|
|
ansible.builtin.shell: set -o pipefail && df -h / | tail -1 | awk '{gsub(/%/, "", $5); print $5}'
|
|
register: free_disk_space_result
|
|
failed_when: free_disk_space_result.stdout | int > 85
|
|
changed_when: false # This task does not change the system
|
|
|
|
rescue:
|
|
- name: Notify with ntfy
|
|
become: false
|
|
ansible.builtin.uri:
|
|
url: "{{ ntfy_topic }}"
|
|
method: POST
|
|
body_format: json
|
|
status_code: [200, 202]
|
|
return_content: true
|
|
headers:
|
|
Authorization: "Bearer {{ ntfy_topic_token }}"
|
|
body:
|
|
- "{{ ansible_facts['hostname'] }}: Disk space is low"
|
|
delegate_to: 127.0.0.1
|
|
failed_when: false
|
|
changed_when: false # This task does not change the system
|