File tree Expand file tree Collapse file tree 3 files changed +31
-10
lines changed
kolla/inventory/group_vars Expand file tree Collapse file tree 3 files changed +31
-10
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/python
2
+
3
+ from ansible .errors import AnsibleFilterError
4
+
5
+ class FilterModule (object ):
6
+ def filters (self ):
7
+ return {
8
+ 'select_enabled' : self .select_enabled
9
+ }
10
+
11
+ # Takes a list of dict
12
+ # Returns a list of values of the key 'key' where the key 'enabled' is True
13
+ # If key is a list, flatten into single result list
14
+ def select_enabled (self , items , key = 'items' ):
15
+ result = []
16
+ for item in items :
17
+ try :
18
+ if item ["enabled" ]:
19
+ result += item [key ] if isinstance (item [key ], list ) else [item [key ]]
20
+ except KeyError as e :
21
+ raise AnsibleFilterError ("Key %s not found in item: %s" % (e , item ))
22
+ return result
Original file line number Diff line number Diff line change 6
6
# prometheus_blackbox_exporter_endpoints_kayobe is another set of default
7
7
# endpoints that are templated by Kayobe rather than Kolla Ansible. See
8
8
# kolla/globals.yml for more details.
9
- prometheus_blackbox_exporter_endpoints_custom: |
10
- {% set endpoints = [] %}
11
- {% for dict_item in (prometheus_blackbox_exporter_endpoints_kayobe | default([]) + stackhpc_prometheus_blackbox_exporter_endpoints_default) %}
12
- {% if dict_item.enabled | bool %}
13
- {% for endpoint in dict_item.endpoints %}
14
- {% set _ = endpoints.append(endpoint) %}
15
- {% endfor %}
16
- {% endif %}
17
- {% endfor %}
18
- {{ (endpoints + stackhpc_prometheus_blackbox_exporter_endpoints_custom) | unique | select | list }}
9
+ prometheus_blackbox_exporter_endpoints: (prometheus_blackbox_exporter_endpoints_kayobe | default([]) + stackhpc_prometheus_blackbox_exporter_endpoints_default) | select_enabled('endpoints') | unique | select | list
19
10
20
11
# A list of custom prometheus Blackbox exporter endpoints. Each element should
21
12
# have the following format:
Original file line number Diff line number Diff line change
1
+ ---
2
+ features :
3
+ - |
4
+ Added a new file ``filters.py`` containing custom Ansible filters.
5
+ Custom filters can be used to replace complex jinja expressions with
6
+ simplified python code. The first filter ``select_enabled`` replaces
7
+ an expression to template Blackbox Exporter endpoints. It also serves as an
8
+ example for future filters.
You can’t perform that action at this time.
0 commit comments