Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Which is jinja2 filter does netaddr use?


Asked by Kyle Flynn on Dec 06, 2021 FAQ



1.9 新版功能. ipaddr () is a Jinja2 filter designed to provide an interface to netaddr Python package from within Ansible.
Thereof,
Let's jump straight in. Jinja2 filter is something we use to transform data held in variables. We apply filters by placing pipe symbol | after the variable followed by name of the filter. Filters can change the look and format of the source data, or even generate new data derived from the input values.
Additionally, In general, use the filters and tests provided by Ansible 2.8 wherever possible: https://docs.ansible.com/ansible/2.8/user_guide/playbooks_templating.html If you must use a Jinja2 feature (like map or selectattr ), and you want to make sure it works with Jinja 2.7, it is a bit tricky, because there are no docs.
Moreover,
Jinja2 doesn't care where the data comes from, this could come from JSON returned by some API, be loaded from static YAML file, or simply be a Python Dict defined in our app. All that matters is that we have Jinja template and some data to render it with. We now know what Jinja is and why would one use it.
Subsequently,
What is Jinja2? Jinja2 is a feature rich templating language widely used in the Python ecosystem. It can be used directly in your Python programs and a lot of larger applications use it as their template rendering engine. Templating languages allow creation of text based documents where some of the content can be dynamically generated.