keep backslashes in Jinja template

76 views
Skip to first unread message

DD

unread,
Dec 16, 2022, 1:11:22 PM12/16/22
to Salt-users
Hi,

I have the following rows in pillar
exclude_lines:
  - '^\n$'
  - '^\*+$'

and jinja template
exclude_lines: {{ exclude_lines|list }}

As a result I get
exclude_lines: [u'^\\ n$', u'^\\*+$']

Is it possible to keep the regex and get the result
exclude_lines: ['^\ n$', '^\*+$']
?

Phipps, Thomas

unread,
Dec 16, 2022, 1:15:28 PM12/16/22
to salt-...@googlegroups.com
how are you importing that list into the variable? load_yaml? import_yaml? pulling from pillars?

--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/salt-users/ace25b84-7499-4db8-b5b0-3e523c9bec1fn%40googlegroups.com.

DD

unread,
Dec 17, 2022, 11:20:16 AM12/17/22
to Salt-users
As I've written I have it in pillar

Dne pátek 16. prosince 2022 v 19:15:28 UTC+1 uživatel whyt...@phipps.ninja napsal:

Phipps, Thomas

unread,
Dec 17, 2022, 5:03:57 PM12/17/22
to salt-...@googlegroups.com

ok. output as |yaml not |list


Dmitriy Doroshenko

unread,
Dec 18, 2022, 4:14:42 AM12/18/22
to salt-...@googlegroups.com
Thank you, but |yaml does not keep quotes

I solved it as follows:
In pillar
exclude_lines:
  - ^\n$
  - ^\*+$

In jinja template
exclude_lines: [{{ exclude_lines|map('quote')|join(',') }}]

And it back me exactly what I want
exclude_lines: ['^\n$','^\*+$']

so 17. 12. 2022 v 23:03 odesílatel Phipps, Thomas <whyt...@bad4.us> napsal:
Reply all
Reply to author
Forward
0 new messages