Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter to convert size for human readable usage #5693

Closed
wants to merge 1 commit into from

Conversation

renard
Copy link

@renard renard commented Jan 21, 2014

Size such as disk or memory can now be converted to human readable
values in filters.

For example:

Variable is defined as:

sda_size: "{{ ansible_devices['sda'].sectors|int * ansible_devices['sda'].sectorsize|int }}"

This can be used:

  • name: between 8Gb and 16Gb
    command: echo "{{ sda_size }}"
    when: sda_size|to_GiB <= 16 and sda_size|to_GiB > 8

New filters:

  • to_KiB (binary unit 1024^1), to_KB (SI unit 1000^1)
  • to_MiB (binary unit 1024^2), to_MB (SI unit 1000^2)
  • to_GiB (binary unit 1024^3), to_GB (SI unit 1000^3)
  • to_TiB (binary unit 1024^4), to_TB (SI unit 1000^4)

Size such as disk or memory can now be converted to human readable
values in filters.

For example:

Variable is defined as:

  sda_size: "{{ ansible_devices['sda'].sectors|int  *  ansible_devices['sda'].sectorsize|int }}"

This can be used:

  - name: between 8Gb and 16Gb
    command: echo "{{ sda_size }}"
    when: sda_size|to_GiB <= 16 and sda_size|to_GiB > 8

New filters:

* to_KiB (binary unit 1024^1), to_KB (SI unit 1000^1)
* to_MiB (binary unit 1024^2), to_MB (SI unit 1000^2)
* to_GiB (binary unit 1024^3), to_GB (SI unit 1000^3)
* to_TiB (binary unit 1024^4), to_TB (SI unit 1000^4)
@mpdehaan mpdehaan added the P4 label Apr 18, 2014
@amenonsen
Copy link
Contributor

I like this feature quite a lot, the implementation is straightforward, and the merge conflict should be trivial to fix in devel, but there should be a couple of examples added to the documentation for it.

@renard, do you feel like resubmitting?

@bcoca
Copy link
Member

bcoca commented Jul 20, 2015

actually, current devel has a human_readable filter already, closing this as it is already implemented

@bcoca bcoca closed this Jul 20, 2015
jimi-c pushed a commit that referenced this pull request Dec 6, 2016
@ansibot ansibot added feature This issue/PR relates to a feature request. and removed feature_pull_request labels Mar 4, 2018
@ansible ansible locked and limited conversation to collaborators Apr 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature This issue/PR relates to a feature request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants