From 79145b6a7892858d6794f3684b91fe2f85c218d0 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Mon, 18 Nov 2013 23:40:29 -0500 Subject: [PATCH 1/2] updated docs to add new filters Signed-off-by: Brian Coca --- docsite/rst/playbooks_variables.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docsite/rst/playbooks_variables.rst b/docsite/rst/playbooks_variables.rst index a2486fc510a..1318f8e73ae 100644 --- a/docsite/rst/playbooks_variables.rst +++ b/docsite/rst/playbooks_variables.rst @@ -167,6 +167,22 @@ This allows an explicit check with this feature off:: The variable value will be used as is, but the template evaluation will raise an error if it is undefined. +.. _set_theory_filters: + +Set Theory Filters +-------------------- +These mostly deal with set (lists), no filter for union as this already works:: + + {{ list1 + list2 }} + +To get the intersection of 2 lists (unique list of all items in both):: + + {{ list1 |intersect(list2)}} + +To get a unique set from a list:: + + {{ list1 |unique }} + .. _other_useful_filters: Other Useful Filters From 246689c2fd363a17ff2ae5f9cdd5e15b37d62365 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Tue, 19 Nov 2013 14:37:53 -0500 Subject: [PATCH 2/2] added version added + union, diff and sym_diff filters Signed-off-by: Brian Coca --- docsite/rst/playbooks_variables.rst | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/docsite/rst/playbooks_variables.rst b/docsite/rst/playbooks_variables.rst index 1318f8e73ae..410ebf74442 100644 --- a/docsite/rst/playbooks_variables.rst +++ b/docsite/rst/playbooks_variables.rst @@ -171,17 +171,28 @@ The variable value will be used as is, but the template evaluation will raise an Set Theory Filters -------------------- -These mostly deal with set (lists), no filter for union as this already works:: +All these functions return a unique set from sets or lists. +.. versionadded:: 1.4 - {{ list1 + list2 }} +To get a unique set from a list:: + + {{ list1 |unique }} + +To get a union of two lists:: + + {{ list1 | union(list2) }} To get the intersection of 2 lists (unique list of all items in both):: {{ list1 |intersect(list2)}} -To get a unique set from a list:: +To get the difference of 2 lists (items in 1 that don't exist in 2):: - {{ list1 |unique }} + {{ list1 |difference(list2)}} + +To get the symetric difference of 2 lists (items exclusive to each list):: + + {{ list1 |symetric_difference(list2)}} .. _other_useful_filters: