Pārlūkot izejas kodu

Added oo_len filter

Thomas Wiest 10 gadi atpakaļ
vecāks
revīzija
4935246c7b
1 mainītis faili ar 7 papildinājumiem un 0 dzēšanām
  1. 7 0
      filter_plugins/oo_filters.py

+ 7 - 0
filter_plugins/oo_filters.py

@@ -9,6 +9,12 @@ def oo_pdb(arg):
   pdb.set_trace()
   return arg
 
+def oo_len(arg):
+  ''' This returns the size of the argument
+        Ex: "{{ hostvars | oo_size }}"
+  '''
+  return len(arg)
+
 def get_attr(data, attribute=None):
   ''' This looks up dictionary attributes of the form a.b.c and returns the value.
         Ex: data = {'a': {'b': {'c': 5}}}
@@ -65,5 +71,6 @@ class FilterModule (object):
     return {
       "oo_select_keys": oo_select_keys,
       "oo_collect": oo_collect,
+      "oo_len": oo_len,
       "oo_pdb": oo_pdb
     }