1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Merge pull request #11365 from halberom/undocumented_filters

docs - added missing filters
This commit is contained in:
Brian Coca 2015-06-26 18:57:36 -04:00
commit bdceb154e5

View file

@ -17,9 +17,27 @@ Filters For Formatting Data
The following filters will take a data structure in a template and render it in a slightly different format. These The following filters will take a data structure in a template and render it in a slightly different format. These
are occasionally useful for debugging:: are occasionally useful for debugging::
{{ some_variable | to_json }}
{{ some_variable | to_yaml }}
For human readable output, you can use::
{{ some_variable | to_nice_json }} {{ some_variable | to_nice_json }}
{{ some_variable | to_nice_yaml }} {{ some_variable | to_nice_yaml }}
Alternatively, you may be reading in some already formatted data::
{{ some_variable | from_json }}
{{ some_variable | from_yaml }}
for example::
tasks:
- shell: cat /some/path/to/file.json
register: result
- set_fact: myvar="{{ result.stdout | from_json }}"
.. _filters_used_with_conditionals: .. _filters_used_with_conditionals:
Filters Often Used With Conditionals Filters Often Used With Conditionals
@ -300,7 +318,11 @@ Hash types available depend on the master system running ansible,
Other Useful Filters Other Useful Filters
-------------------- --------------------
To use one value on true and another on false (since 1.9):: To add quotes for shell usage::
- shell: echo={{ string_value | quote }}
To use one value on true and another on false (new in version 1.9)::
{{ (name == "John") | ternary('Mr','Ms') }} {{ (name == "John") | ternary('Mr','Ms') }}
@ -324,6 +346,10 @@ To get the real path of a link (new in version 1.8)::
{{ path | realpath }} {{ path | realpath }}
To get the relative path of a link, from a start point (new in version 1.7)::
{{ path | relpath('/etc') }}
To work with Base64 encoded strings:: To work with Base64 encoded strings::
{{ encoded | b64decode }} {{ encoded | b64decode }}