openwrt/image: proper fix for empty directories in mixins
[noc.git] / ansible / roles / openwrt / image / filter_plugins / openwrt.py
diff --git a/ansible/roles/openwrt/image/filter_plugins/openwrt.py b/ansible/roles/openwrt/image/filter_plugins/openwrt.py
new file mode 100644 (file)
index 0000000..8443b30
--- /dev/null
@@ -0,0 +1,22 @@
+from __future__ import (absolute_import, division, print_function)
+__metaclass__ = type
+
+from ansible import errors
+
+
+def openwrt_mixin_type(data, mixin_type):
+    try:
+        return [{'key': x, 'value': data[x]} for x in data if mixin_type in data[x]]
+
+    except Exception as e:
+        raise errors.AnsibleFilterError("openwrt_mixin_type(): %s" % str(e))
+
+
+class FilterModule(object):
+
+    filter_map = {
+        'openwrt_mixin_type': openwrt_mixin_type,
+    }
+
+    def filters(self):
+        return self.filter_map