I want to use Salt states to change the PROMPT_COMMAND
on a network of systems, but I haven't been able to figure out the proper string escaping strategy. The prompt command is:
PROMPT_COMMAND='PS1="`if [[ \$? -eq "0" ]]; then echo "\\[\\033[32m\\]"; else echo "\\[\\033[31m\\]"; fi`\! \[\033[36m\]\u@\h \[\033[33m\]\W \[\033[0m\]$ "'
First I tried:
/etc/bash.bashrc:
file.append:
- text:
- PROMPT_COMMAND='PS1="`if [[ \$? -eq "0" ]]; then echo "\\[\\033[32m\\]"; else echo "\\[\\033[31m\\]"; fi`\! \[\033[36m\]\u@\h \[\033[33m\]\W \[\033[0m\]$ "'
But the state won't compile. I tried twice more (once with single quotes and again with double) by quoting the string and escaping nested instances within. Neither succeeded. Then I placed the directive in a text file (bashrc.txt
) and tried:
/etc/bash.bashrc:
file.append:
- source: salt://_fragments/bashrc.txt
But this breaks the rendering system also, even though you'll note that I purposefully omit a - template: jinja
argument.
Is there some other escaping mechanism available through Salt or Jinja that will be resilient against the myriad nested ticks, quotes, and backslashes present in this particularly gruesome string?
Have you tried this?
/etc/bash.bashrc:
file.append:
- text: |
PROMPT_COMMAND='PS1="`if [[ \$? -eq "0" ]]; then echo "\\[\\033[32m\\]"; else echo "\\[\\033[31m\\]"; fi`\! \[\033[36m\]\u@\h \[\033[33m\]\W \[\033[0m\]$ "'