Skip to content

Instantly share code, notes, and snippets.

@ktbyers
Last active August 18, 2021 23:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ktbyers/bdba984447636d5ac4e3d93011a861ad to your computer and use it in GitHub Desktop.
Save ktbyers/bdba984447636d5ac4e3d93011a861ad to your computer and use it in GitHub Desktop.
Use Ansible Jinja2 Filters in Python
from jinja2.environment import Environment
from jinja2 import FileSystemLoader, StrictUndefined
from ansible_collections.ansible.netcommon.plugins.filter.ipaddr import ipmath
from ansible_collections.ansible.netcommon.plugins.filter.ipaddr import ipaddr
env = Environment(undefined=StrictUndefined)
env.loader = FileSystemLoader(['.', './templates/'])
env.filters["ipmath"] = ipmath
env.filters["ipaddr"] = ipaddr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment