Files

50 lines
1.8 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: common_healthcheck_space_left_result
failed_when: common_healthcheck_space_left_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 # It's OK if it fails, not critical
changed_when: false # This task does not change the system
- name: Resize rootfs if it's an LXC
ansible.builtin.include_tasks: resize_lxc_rootfs.yaml
when: ansible_virtualization_type == 'lxc'