Failing Salt code: out of ideas and wrong error

3 views
Skip to first unread message

Johannes Graumann

unread,
May 24, 2022, 5:54:35 PM5/24/22
to qubes-users
Can any one point me to why the following fails? I have been banging my
head against this for a while ...

--- SNIP ---
create bind dirs config file:
file.managed:
- name: /rw/config/qubes-bind-dirs.d/50_user.conf
- makedirs: True
- mode: 644
- dir_mode: 755

{% set binddirs = ['/usr/local'] %}

{% for binddir in binddirs %}
configure '{{ binddir }}' to be persistent:
file.replace:
- name: /rw/config/qubes-bind-dirs.d/50_user.conf
- pattern: "^binds+=( '{{ binddir }}' )$"
- repl: "binds+=( '{{ binddir }}' )"
- append_if_not_found: True
{% endfor %}
--- SNIP ---

The corresponding error ("State 'create bind dirs config file' in SLS
'custom_dom0.sys-vpn-mpihlr_assert_vpn_setup' is not formed as a list")
is a complete red herring, as the so called first part by itself works
just fine and only fails when I add the latter (jinja) part ...

How do I properly deal with the single quotes in `pattern` and `repl`?

Thanks for any pointers.

Sincerely, Joh


unman

unread,
May 25, 2022, 10:08:07 AM5/25/22
to Johannes Graumann, qubes-users
Hi Joh

Change the closing tag on the for statement to "-%}"
This is, I think, salt specific - according to the jinja specs it will remove whitespace
Your use of single quotes in pattern and repl will be fine.

A simpler (and lazier) formulation would use file.append:

{% for binddir in binddirs %}
configure '{{ binddir }}' to be persistent:
file.append:
- name: /rw/config/qubes-bind-dirs.d/50_user.conf
- text: "binds+=( '{{ binddir }}' )"
- makedirs: True
{% endfor %}

You can drop the explicit file.managed in this case.

unman
--
I **never** presume to speak for the Qubes team.
When I comment in the Forum or in the mailing lists I speak for myself.

Johannes Graumann

unread,
May 28, 2022, 5:04:04 AM5/28/22
to unman, qubes-users
Thank you so much! Addition of the darn `-` made my problem disappear
... this one really had me pulling my hear out!

Sincerely, Joh
Reply all
Reply to author
Forward
0 new messages