From a6a86a5bdbcfef8d41dc0cd62cfde3c3e1a14d47 Mon Sep 17 00:00:00 2001 From: Gerard Lynch Date: Fri, 26 Jun 2015 21:49:04 +0100 Subject: [PATCH] added missing filters, changed since to new in version --- docsite/rst/playbooks_filters.rst | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/docsite/rst/playbooks_filters.rst b/docsite/rst/playbooks_filters.rst index 0cb42213b44..4e35cee522e 100644 --- a/docsite/rst/playbooks_filters.rst +++ b/docsite/rst/playbooks_filters.rst @@ -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 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_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 Often Used With Conditionals @@ -300,7 +318,11 @@ Hash types available depend on the master system running ansible, 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') }} @@ -324,6 +346,10 @@ To get the real path of a link (new in version 1.8):: {{ 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:: {{ encoded | b64decode }}