-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilesystemsize2.yaml
69 lines (64 loc) · 2.58 KB
/
filesystemsize2.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
---
- name: Check root filesystem usage
hosts: all
become: true
vars:
filesystem: "/"
mount_all: []
tasks:
# - name: get filesystem usage from ansible facts
# ansible.builtin.debug:
# var: ansible_facts['mounts']
- set_fact:
mount: "{{ ansible_mounts | first }}"
- set_fact: disk_usage="{{ mount.size_total - mount.size_available }}"
- set_fact: disk_usage_ratio="{{ disk_usage|float / mount.size_total }}"
- set_fact: disk_usage_s="{{ (disk_usage|float / 1000000000) | round(1, 'common') }}GB"
- set_fact: disk_total_s="{{ (mount.size_total / 1000000000) | round(1, 'common') }}GB"
- set_fact: disk_usage_ratio_s="{{ 100 * (disk_usage_ratio|float) | round(1, 'common') }}%"
- debug:
msg: "{{ ansible_mounts }}"
- debug:
msg: "disk usage {{ disk_usage_s }} of total {{ disk_total_s }} ({{ disk_usage_ratio_s }})"
# Get List of device
- set_fact:
mount_all: "{{ mount_all + [{'host':ansible_host,'dev':item.device,'mount':item.mount,'free':(((item.size_available/1024)/1024)/1024)|round(2,'common'),'total':(((item.size_total/1024)/1024)/1024)|round(2,'common')}] }}"
when: (item.size_total - item.size_available) > (item.size_total|float * 0.80)
with_items: "{{ ansible_mounts | list }}"
- name: filesystemc > 80%
debug:
msg: "{{ mount_all }} "
# - name: Get filesystem usage
# ansible.builtin.shell: df -h {{ filesystem }} | awk 'NR==2 {print $5}' | sed 's/%//'
# register: filesystem_usage
# changed_when: false
#
# - name: Set fact for filesystem usage
# ansible.builtin.set_fact:
# root_fs_usage: "{{ filesystem_usage.stdout | int }}"
#
# - name: delete files is root filesystem is more than 80% full
# when: root_fs_usage > "80"
# block:
# - name: Categorize filesystem usage
# ansible.builtin.debug:
# msg: >
# Root filesystem usage is ({{ root_fs_usage }}%) utilized
#
# - name: Analyzing the directories to delete...
# ansible.builtin.find:
# paths: /tmp
# patterns: "*.file"
# age: 5
# age_stamp: atime
# register: files_to_delete
#
# - name: Displaying the result...
# ansible.builtin.debug:
# var: files_to_delete.files
#
# - name: Deleting the files...
# ansible.builtin.file:
# path: "{{ item.path }}"
# state: absent
# with_items: "{{ files_to_delete.files }}"