Ansible in a Minute · Ansible Core ·
Use human_to_bytes to parse a size string
Short answer
Pipe a size string through human_to_bytes so a task gets a raw byte integer such as 10240.
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 10.00 KB with human_to_bytes so the message is 10240
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 10.00 KB with human_to_bytes so the message is 10240
- name: Print 10240 from 10.00 KB
hosts: all
gather_facts: false
tasks:
- name: Print 10240 from 10.00 KB
ansible.builtin.debug:
msg: "{{ '10.00 KB' | human_to_bytes }}"How it works
human_to_bytes turns a human size string into a byte count. 10.00 KB becomes 10240. Use this filter when a module argument must be an integer.
When to use it
- Converting a quota string before a disk or file task
- Passing a byte size to a module that does not accept KB
Requirements
- Ansible: >=2.14
Validation
- Syntax validated
- Not execution-tested
- Last verified 2026-10-02
Notes
Pass isbits=True when the string uses bit units such as Kb. Values between 0 and 1 round to the nearest byte. Use human_readable when people must read the size.
Reference
- Human to bytes (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.