mirror of
https://github.com/ChristianLempa/boilerplates.git
synced 2025-02-16 18:40:46 +01:00
Ensure that the `hosts` definition is always defined, defaulting to an empty set. Due to the lack of an Ansible inventory file this is most likely meant to be set as an Ansible extra variable [1]. We also rename the variable named `hosts` to `my_hosts` because `hosts` is a reserved name in Ansible. Reserved names in Ansible are for example all class variable names of plays, roles, blocks, and tasks [2], and `hosts` for example is used by plays [3]. [1] https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html#defining-variables-at-runtime [2] https://github.com/ansible/ansible/blob/v2.16.4/lib/ansible/vars/reserved.py#L39 [3] https://github.com/ansible/ansible/blob/v2.16.4/lib/ansible/playbook/play.py#L58
21 lines
670 B
YAML
21 lines
670 B
YAML
---
|
|
- name: check disk space
|
|
hosts: "{{ my_hosts | d([]) }}"
|
|
tasks:
|
|
- name: get disk usage
|
|
ansible.builtin.command: df -h
|
|
register: disk_usage
|
|
- name: check disk space available
|
|
ansible.builtin.shell: df -Ph / | awk 'NR==2 {print $5}'
|
|
register: disk_usage
|
|
# - name: send discord message when disk space is over 80%
|
|
# uri:
|
|
# url: "your-webhook"
|
|
# method: POST
|
|
# body_format: json
|
|
# body: '{"content": "Disk space on {{ inventory_hostname }} is above 80%!"}'
|
|
# headers:
|
|
# Content-Type: application/json
|
|
# status_code: 204
|
|
# when: disk_usage.stdout[:-1]|int > 80
|