[qubes-users] Failing Salt code: out of ideas and wrong error

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

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

Thank you so much! Addition of the darn `-` made my problem disappear
... this one really had me pulling my hear out!

Sincerely, Joh