Hi all,
Recently, I was talking with amenonsen about a PR with the aim to provide a way to convert a string into bytes. You can check it out at the following location: https://github.com/ansible/ansible/pull/12074
Here is a simple example:
- name: Verify human_bytes
tags: "human_bytes"
assert:
that:
- "{{'0'|human_bytes}} == 0"
- "{{'0.1'|human_bytes}} == 0"
- "{{'0.9'|human_bytes}} == 1"
- "{{'1'|human_bytes}} == 1"
- "{{'10.00 KB'|human_bytes}} == 10240"
- "{{ '11 MB'|human_bytes}} == 11534336"
- "{{ '1.1 GB'|human_bytes}} == 1181116006"
The filter is not quite usefull but combined with another PR of mine (https://github.com/ansible/ansible/pull/12066), it can help people to retrieve available space of a given path. Here’s an example showing a way to use it in order to check available space on /tmp before trying to do anything else:
- name: "Check /tmp space"
hosts: localhost
tasks:
- debug: msg={{'/tmp'|getmountfrompath(ansible_mounts)}}
- name: "Check there's enough space"
fail: msg="Not enough space available"
when: ('/tmp'|getmountfrompath(ansible_mounts)).size_available < '1M' | human_bytes
Actually, amenonsen found that human_bytes is not a very good name and that we may found better alternative. So here we are people, what do you think about? Any advice?