Add beauty to long Jinja2 chains
Do you have a long-long Jinja2 expression with chain of filters? Need to scroll screen? Have linter errors about 80+ long lines? Wait no more! Use YAML block scalar syntax:
- set_fact:
ip_address: >-
{{ ( api_response
| map(attribute='fixed_ips')
| map('from_json')
| selectattr('ip_address', 'match', '^192')
| list
| first
).ip_address
}}
Mind the hypen -
(minus sign) after >
– this strips newline from the result, so we have expected "192.168.0.1"
and not "192.168.0.1\n"
.