Update filter documentation (#50255)
Added documentation for following filters - * Product * human_readable * human_to_bytes Signed-off-by: Satyajit Bulage <sbulage@redhat.com>
This commit is contained in:
parent
d3107d9915
commit
13d94ed681
1 changed files with 70 additions and 0 deletions
|
@ -1261,6 +1261,24 @@ Combinations always require a set size::
|
|||
|
||||
Also see the :ref:`zip_filter`
|
||||
|
||||
Product Filters
|
||||
```````````````
|
||||
|
||||
The product filter returns the `cartesian product <https://docs.python.org/3/library/itertools.html#itertools.product>`_ of the input iterables.
|
||||
|
||||
This is roughly equivalent to nested for-loops in a generator expression.
|
||||
|
||||
For example::
|
||||
|
||||
- name: generate multiple hostnames
|
||||
debug:
|
||||
msg: "{{ ['foo', 'bar'] | product(['com']) | map('join', '.') | join(',') }}"
|
||||
|
||||
This would result in::
|
||||
|
||||
{ "msg": "foo.com,bar.com" }
|
||||
|
||||
|
||||
Debugging Filters
|
||||
`````````````````
|
||||
|
||||
|
@ -1273,6 +1291,58 @@ type of a variable::
|
|||
{{ myvar | type_debug }}
|
||||
|
||||
|
||||
Computer Theory Assertions
|
||||
```````````````````````````
|
||||
|
||||
The ``human_readable`` and ``human_to_bytes`` functions let you test your
|
||||
playbooks to make sure you are using the right size format in your tasks - that
|
||||
you're providing Byte format to computers and human-readable format to people.
|
||||
|
||||
Human Readable
|
||||
``````````````
|
||||
|
||||
Asserts whether the given string is human readable or not.
|
||||
|
||||
For example::
|
||||
|
||||
- name: "Human Readable"
|
||||
assert:
|
||||
that:
|
||||
- '"1.00 Bytes" == 1|human_readable'
|
||||
- '"1.00 bits" == 1|human_readable(isbits=True)'
|
||||
- '"10.00 KB" == 10240|human_readable'
|
||||
- '"97.66 MB" == 102400000|human_readable'
|
||||
- '"0.10 GB" == 102400000|human_readable(unit="G")'
|
||||
- '"0.10 Gb" == 102400000|human_readable(isbits=True, unit="G")'
|
||||
|
||||
This would result in::
|
||||
|
||||
{ "changed": false, "msg": "All assertions passed" }
|
||||
|
||||
Human to Bytes
|
||||
``````````````
|
||||
|
||||
Returns the given string in the Bytes format.
|
||||
|
||||
For example::
|
||||
|
||||
- name: "Human to Bytes"
|
||||
assert:
|
||||
that:
|
||||
- "{{'0'|human_to_bytes}} == 0"
|
||||
- "{{'0.1'|human_to_bytes}} == 0"
|
||||
- "{{'0.9'|human_to_bytes}} == 1"
|
||||
- "{{'1'|human_to_bytes}} == 1"
|
||||
- "{{'10.00 KB'|human_to_bytes}} == 10240"
|
||||
- "{{ '11 MB'|human_to_bytes}} == 11534336"
|
||||
- "{{ '1.1 GB'|human_to_bytes}} == 1181116006"
|
||||
- "{{'10.00 Kb'|human_to_bytes(isbits=True)}} == 10240"
|
||||
|
||||
This would result in::
|
||||
|
||||
{ "changed": false, "msg": "All assertions passed" }
|
||||
|
||||
|
||||
A few useful filters are typically added with each new Ansible release. The development documentation shows
|
||||
how to extend Ansible filters by writing your own as plugins, though in general, we encourage new ones
|
||||
to be added to core so everyone can make use of them.
|
||||
|
|
Loading…
Reference in a new issue