-
Notifications
You must be signed in to change notification settings - Fork 0
/
disk-mem-final.yml
38 lines (32 loc) · 1.29 KB
/
disk-mem-final.yml
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
---
- name: Print Memory Usage
hosts: all
gather_facts: true
tasks:
- name: Calculate Memory Usage Percentage
set_fact:
memory_usage_percentage: "{{ (ansible_memtotal_mb | float - ansible_memfree_mb | float) * 100 / ansible_memtotal_mb | float | int }}"
- name: Print Memory Information
debug:
msg: "Free Memory: {{ ansible_memfree_mb | int }} MB, Used Memory: {{ ansible_memtotal_mb | int - ansible_memfree_mb | int }} MB, Memory Usage: {{ memory_usage_percentage }}%, {% if memory_usage_percentage | int > 80 %}Memory usage is HIGH!{% else %}Memory usage is Normal{% endif %}"
- name: Check Disk Utilization
shell: df -h
register: df_output
- name: Display Disk Utilization
debug:
var: df_output.stdout_lines
when: "'%' in df_output.stdout_lines[1]"
- name: Show Disk Utilization Status
debug:
msg: "Disk Utilization is HIGH (>80%)"
when: "item.split()[4] | int > 80"
with_items: "{{ df_output.stdout_lines[1:] }}"
loop_control:
loop_var: item
- name: Show Disk Utilization Status
debug:
msg: "Disk Utilization is NORMAL (<=80%)"
when: "item.split()[4] | int <= 80"
with_items: "{{ df_output.stdout_lines[1:] }}"
loop_control:
loop_var: item