Rendering SLS fails due to "\" in Windows

716 views
Skip to first unread message

varun bhatnagar

unread,
Jun 21, 2017, 2:45:38 AM6/21/17
to Salt-users
Hi,

I have a saltstack (Carbon version) setup with Windows minions. I am trying to get the binary path of a service and this is how my state file looks:

# cat test.sls
{% set test_var = salt.service.info("SDRSVC") %}

run_command:
  module.run:
    - name: test.echo
    - text: "{{ test_var['BinaryPath'] }}"

WhenI execute it I am getting an error saying found unknown escape character 'W'; line 6
It considers \Windows as an escape chaaracter.

# salt -t 60 '192.168.133.129' state.apply test
    Data failed to compile:
----------
    Rendering SLS 'base:test' failed: found unknown escape character 'W'; line 6

---


run_command:
  module.run:
    - name: test.echo
    - text: "C:\Windows\system32\svchost.exe -k SDRSVC"    <======================
---

Any suggestions on how to fix this?

BR,
Varun

Viet Hung Nguyen

unread,
Jun 21, 2017, 2:59:19 AM6/21/17
to salt-...@googlegroups.com
Backslash (\) is escaping character in YAML when the string enclosed by double quote “
http://www.yaml.org/spec/1.2/spec.html#id2776092

In your SLS, YAML will understand that \W is escaping W character as it has some special meaning.

So solutions are:
- Enclosed your path by single quote ‘{{ ABC }}’, then \ will not be “thought” as escaping
- Or, keep the double quotes but replace all backslash \ with double backslashes -> \\
"C:\\Windows\\system32\\svchost.exe -k SDRSVC”


Viet Hung Nguyen

--
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/28e1e2f6-275d-40d4-8aa9-eed121fa8b8c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

varun bhatnagar

unread,
Jun 21, 2017, 3:05:03 AM6/21/17
to Salt-users
Hello Viet,

Thanks a lot for quick reply.
I went with option-1 and it worked.

Thanks!

BR,
Varun
Reply all
Reply to author
Forward
0 new messages