From c4c8493f1b5480d3bebf659dac15ce55e3608327 Mon Sep 17 00:00:00 2001 From: deyvsh Date: Wed, 7 Oct 2015 12:33:39 +0100 Subject: [PATCH] Add an example for map() to the filters page --- docsite/rst/playbooks_filters.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docsite/rst/playbooks_filters.rst b/docsite/rst/playbooks_filters.rst index b8a847a5e7d..301e556f1d0 100644 --- a/docsite/rst/playbooks_filters.rst +++ b/docsite/rst/playbooks_filters.rst @@ -527,11 +527,18 @@ To escape special characters within a regex, use the "regex_escape" filter:: # convert '^f.*o(.*)$' to '\^f\.\*o\(\.\*\)\$' {{ '^f.*o(.*)$' | regex_escape() }} + +To make use of one attribute from each item in a list of complex variables, use the "map" filter (see the `Jinja2 map() docs`_ for more):: + + # get a comma-separated list of the mount points (e.g. "/,/mnt/stuff") on a host + {{ ansible_mounts|map(attribute='mount')|join(',') }} 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. +.. _Jinja2 map() docs: http://jinja.pocoo.org/docs/dev/templates/#map + .. _builtin filters: http://jinja.pocoo.org/docs/templates/#builtin-filters .. seealso::