- name: check for file size
stat:
path: /apps/InstallDir/data
register: myDir
- debug: var=myDir.stat.size
how to get output in required format MB or GB and debug msg when it's greater than threshold
- name: check for file size
stat:
path: /apps/InstallDir/data
register: myDir
- debug: var=myDir.stat.size
how to get output in required format MB or GB and debug msg when it's greater than threshold
I understand that the main question here is: "How to convert, How to output in MB, MiB, GB or GiB, instead of bytes?".
You achieve this by using constructs like
- name: Check file size
stat:
path: "/home/{{ ansible_user }}/testfile"
register: file_size
tags: check_fs
- name: Report file size
debug:
msg:
- "{{ ( file_size.stat.size / 1024 / 1024 ) | int }}MiB"
- "{{ ( file_size.stat.size / 1024 | pow(2) ) | round | int }}MiB"
- "{{ file_size.stat.size | filesizeformat(True) }}"
- "{{ file_size.stat.size | filesizeformat }}"
tags: check_fs
Credits to