You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.0 KiB
35 lines
1.0 KiB
---
|
|
- name: Check space
|
|
hosts: all:!splunk_uf_Linux
|
|
become: yes
|
|
become_user: root
|
|
|
|
tasks:
|
|
|
|
- name: Get available space in /home
|
|
shell: df -k /home | tail -1 | awk '{print $4}'
|
|
register: home_avail
|
|
|
|
- name: Convert available space to MB
|
|
set_fact:
|
|
home_avail_mb: "{{ home_avail.stdout | int // 1024 }}"
|
|
|
|
- name: Debug space available
|
|
debug:
|
|
msg: "Available space in /home: {{ home_avail_mb }} MB"
|
|
|
|
- name: Fail if available space is less than 1GB
|
|
fail:
|
|
msg: "Not enough space in /home. Only {{ home_avail_mb }} MB available."
|
|
when: home_avail_mb | int < 1000
|
|
|
|
- name: Set global fail flag if space check fails
|
|
set_fact:
|
|
global_fail: "{{ home_avail_mb | int < 1000 }}"
|
|
run_once: true
|
|
|
|
- name: Fail play if any host failed the space check
|
|
fail:
|
|
msg: "The playbook is stopping due to insufficient space on one or more hosts."
|
|
when: global_fail | bool
|
|
run_once: true |