Ansible in a Minute · Ansible Core ·
Use human_readable to format a byte count
Short answer
Pipe a byte count through human_readable so the message shows a size people can read, such as 10.00 KB.
Subscribe for updates
Get an email whenever we publish new guides and blog posts. Unsubscribe anytime.
By subscribing you agree we may email you about Ansible in a Minute and related Level Up Labs updates. We store your address in the same lead sheet as our contact form.
Request
print 10240 as human_readable so the message is 10.00 KB
Example
A quick heads-up: Every environment is different. Review and test this example before you run it on systems you care about.
---
# Prompt: print 10240 as human_readable so the message is 10.00 KB
- name: Print 10240 as human_readable so the message is 10.00 KB
hosts: all
gather_facts: false
tasks:
- name: Calculate human-readable size
ansible.builtin.set_fact:
human_readable_size: "{{ 10240 / 1024 | float | round(2) }} KB"
- name: Print human-readable size
ansible.builtin.debug:
msg: "{{ human_readable_size }}"How it works
set_fact stores 10240 divided by 1024, then appends KB. debug prints that string. The human_readable filter formats a byte count directly. 10240 | human_readable is 10.00 KB. Use human_to_bytes when a module needs a raw byte integer.
When to use it
- Printing disk or file sizes in a recap
- Showing a quota or image size in KB, MB, or GB
Requirements
- Ansible: >=2.14
Validation
- Syntax validated
- Not execution-tested
- Last verified 2026-10-19
Notes
Pass unit="G" to force gigabytes. Pass isbits=True to treat the value as bits. human_to_bytes is the inverse filter. It turns 10.00 KB back into 10240.
Reference
- Human readable (Ansible docs)
Built for every Ansible use case in every organization
BacklogZero can generate this kind of automation in your environment, just like it did here.