Ansible provides a rich set of filters from Jinja2, as well as some additional built-in filters to manipulate data; however, in some cases, you may find that there is no filter available to satisfy your requirements. In this recipe, we will outline how to build custom filters in Python to extend Ansible functionality to manipulate data.
Creating custom Python filters for Ansible
How to do it...
- In the project directory (ch13_ansible_best_practice), create a new folder, filter_plugins.
- Create a new Python script called filter.py under the filter_plugins folder, with the following content:
class FilterModule(object):
def filters(self):
return {
'acl_state': self.acl_state
}
def acl_state...