Pcornel
Browse topics
Options
Recent
Favorites
Automation · Technical reference

Filters

Direct answer

Template filters transform values during rendering, such as {{ name | upper }}, {{ list | join(',') }} or ipaddr filters for subnets in Ansible.

When to use this

Use this when transforming values in templates.

First 30 seconds

1. Filters transform values (default, join, to_nice_yaml, ipaddr).

2. Use built-ins before custom code.

3. Test custom filters.

4. Chain readably.

5. Check collection requirements.

Operational verification

value → filters → transformed value

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
template rendering automation
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

Platformtemplate rendering automation · Automation implementations are tool and platform specific. Use the adjacent Domain for the technology being automated and this Domain for automation behavior.
Scope / prerequisiteUse this when transforming values in templates.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Verification path Verify boundary

The negative fixture should deliberately exercise risks such as undefined values, unsafe escaping, implicit type conversion, environment-specific filters, secret exposure, whitespace-sensitive syntax and valid render producing invalid target configuration, choosing the cases most relevant to filter input/output types, undefined/null handling, ordering/composition and target-specific escaping after transformation.

Step 2 Common mistakes Narrow the fault
  • Filters missing because the collection is not installed.
Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points
  • Filters transform values: upper, join, default, ipaddr.
  • Filters can be chained.
  • Test outputs.
Key checks
  • {{ name | upper }} / {{ ip | ansible.utils.ipaddr('address') }} — filters
  • ansible-doc -t filter -l | head — available filters
  • Custom filters tested — quality
ReferenceWhy it matters1 section · depth on demand

What it is

Filters transform values in templates: default, upper, join, ipaddr (ansible.utils), to_nice_yaml.

ReferenceImportant terms & boundaries2 sections · depth on demand

In depth

Filters transform values in Jinja2 templates: a value is piped into a filter with optional arguments, and filters can be chained left to right. They keep formatting logic out of the data.

{{ mtu | default(1500) }}                         {# fallback value #}
{{ site | upper }}                                {# OSLO #}
{{ vlans | unique | sort | join(',') }}           {# 10,20,30 #}
{{ intfs | selectattr('enabled') | list }}        {# only enabled interfaces #}
{{ intfs | map(attribute='name') | list }}        {# list of names #}
{{ '10.0.0.1/24' | ansible.utils.ipaddr('netmask') }}   {# 255.255.255.0 #}

The most used filters are default, case filters, join, sort/unique, selectattr/rejectattr and map. Custom filters — Python functions registered in the environment or as an Ansible filter plugin — are better than complex logic inside templates, because they can be unit-tested.

Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor doctemplate rendering automation current

Authoritative/upstream documentation reviewed for bounded claims in Templates > Filters. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://jinja.palletsprojects.com/en/stable/templates/ · confidence 94%
Depth when you need it

Deep reference

Healthy vs suspicious evidence

Output interpretation

For filter input/output types, undefined/null handling, ordering/composition and target-specific escaping after transformation, prefer typed fields and stable IDs over human presentation text.

Confirmation

Confirm action

Continue?