servers/filter_plugins/util.py
Timotej Lazar bf4fd2c82d alpine: support non-VM hosts in interfaces template
Ignore OOB management interface, allow configuring loopback interface
with NetBox data, and setting MTU.
2025-05-15 14:55:43 +02:00

21 lines
650 B
Python

#!/usr/bin/python
class FilterModule(object):
'''Helper filters to make Ansible less unpleasant'''
def filters(self):
return {
'defaultattr': self.defaultattr,
'list2dict': self.list2dict,
}
def defaultattr(self, objects, attr, val=None):
'''
Set a default value if the given attribute is not defined for an object.
'''
yield from (obj | { attr: obj.get(attr, val) } for obj in objects)
def list2dict(self, items, key):
'''
Like items2dict but keep entire dictionaries as values.
'''
return {item[key]: item for item in items}