Linebreak Ansible Filters

22 views
Skip to first unread message

Ron Gebauer

unread,
May 9, 2019, 12:45:20 PM5/9/19
to Ansible Project
Hi,

I want to fix the Ansible Linter issue "[204] Lines should be no longer than 160 chars".

But how I can linebreak filters?

local_filters_in_templates_list: "{{ local_filters_in_templates.files | map(attribute='path') | map('regex_replace','^(.*)/') | map('regex_replace','.j2$') | list }}"


simply break after "|"?

Best regards,
Mazorius

Kai Stian Olstad

unread,
May 10, 2019, 11:37:16 AM5/10/19
to ansible...@googlegroups.com
On 09.05.2019 18:45, Ron Gebauer wrote:
> Hi,
>
> I want to fix the Ansible Linter issue "*[204]* Lines should be no longer
> than 160 chars".

In my opinion the best this is often to disable the to long line check.


> But how I can linebreak filters?
>
> local_filters_in_templates_list: "{{ local_filters_in_templates.files |
> map(attribute='path') | map('regex_replace','^(.*)/') |
> map('regex_replace','.j2$') | list }}"
>
> simply break after "|"?

If you use multiline yaml you can break anywhere you can have a space.
So this is valid

local_filters_in_templates_list: >
{{ local_filters_in_templates.files
|
map(attribute='path')
|
map('regex_replace','^(.*)/')
|
map('regex_replace','.j2$')
|
list }}

Of course this is not very readable, so break it where you like it to be.

And it's important not to use the double quotes when using the multiline, if you do it will be a string and not a list.


--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages