How it works...
We can extend the filter library provided by Ansible and create a custom filter using Python. In order to implement our custom filter, we create a folder called filter_plugins under our project directory, and we create a Python script with any name (we used filter.py in our example).
The custom Python filters must be placed in a folder called filter_plugins in order for Ansible to pick up these filters and process them.
Inside this Python script, we create a Python class called FilterModule. Inside this class, we declare a function named filters that returns a dictionary of all our custom filters that we define. We then start to create our filter by declaring a function called acl_state that takes the acl_def variables (which ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access