Escaping characters in conext

1,000 views
Skip to first unread message

Karl Latiss

unread,
Feb 25, 2013, 6:12:54 AM2/25/13
to salt-...@googlegroups.com
I'm just beginning with salt so I wouldn't be suprised if this is painfully obvious however I can't find the solution and would appreciate some direction.

I'm using a context value to populate a templated sshd_config file however the context value contains within it the sequence \n

    - context:
      sshd_config_allowgroups: "agroup DOMAIN\newgroup anothergroup"

I've tried escaping the \n sequence with a ' (eg '\n) as well as with a \ (eg \\n) and have tried a number of jinja filters (escape, safe, string) with no luck. In all cases that don't error out I see the following:

-AllowGroups agroup DOMAIN\newgroup anothergroup
+AllowGroups agroup DOMAIN
+ewgroup anothergroup

Any pointers gladly accepted.

Karl.

Jack Kuan

unread,
Feb 25, 2013, 9:34:28 AM2/25/13
to salt-...@googlegroups.com
hmm, doubling the backslash  works for me:

/Users/jkuan/hoho.txt:
  file:
    - managed
    - source: salt://hoho.txt
    - template: jinja
    - context:
      myvalue: "this is a\\ntest"

hoho.txt is:
{{myvalue}}

Then after state.highstate, I got /Users/jkuan/hoho.txt:
this is a \ntest

Jack

-- 
Jack Kuan
Sent with Sparrow

--
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.
For more options, visit https://groups.google.com/groups/opt_out.
 
 


This email and any files transmitted with it are confidential and intended solely for the recipient(s). If you are not the named addressee you should not disseminate, distribute, copy or alter this email. Any views or opinions presented in this email are solely those of the author and might not represent those of theScore, Inc. or any of its affiliates. Warning: Although theScore, Inc. has taken reasonable precautions to ensure no viruses are present in this email, the company cannot accept responsibility for any loss or damage arising from the use of this email or attachments.

Mrten

unread,
Feb 25, 2013, 11:11:17 AM2/25/13
to salt-...@googlegroups.com
I use (in pillar, for ssh-keys):

sshkey: |
lorem ipsum
dolor sit amet

(pipe character)

Works as long as the indenting is there.

https://salt.readthedocs.org/en/latest/ref/states/all/salt.states.file.html?highlight=salt.states.file

under 'salt.states.file.append' is another example.

M.

Karl Latiss

unread,
Feb 25, 2013, 3:53:24 PM2/25/13
to salt-...@googlegroups.com
On Tue, Feb 26, 2013 at 1:34 AM, Jack Kuan <jack...@thescore.com> wrote:
hmm, doubling the backslash  works for me:

/Users/jkuan/hoho.txt:
  file:
    - managed
    - source: salt://hoho.txt
    - template: jinja
    - context:
      myvalue: "this is a\\ntest"

hoho.txt is:
{{myvalue}}

Then after state.highstate, I got /Users/jkuan/hoho.txt:
this is a \ntest


OK - looks like the double backslash works and I'm changing too many things at once between tests.

Thanks for the quick response and apologies for the noise.

Karl.


 
Jack

-- 
Jack Kuan
Sent with Sparrow

On Monday, 25 February, 2013 at 6:12 AM, Karl Latiss wrote:

I'm just beginning with salt so I wouldn't be suprised if this is painfully obvious however I can't find the solution and would appreciate some direction.

I'm using a context value to populate a templated sshd_config file however the context value contains within it the sequence \n

    - context:
      sshd_config_allowgroups: "agroup DOMAIN\newgroup anothergroup"

I've tried escaping the \n sequence with a ' (eg '\n) as well as with a \ (eg \\n) and have tried a number of jinja filters (escape, safe, string) with no luck. In all cases that don't error out I see the following:

-AllowGroups agroup DOMAIN\newgroup anothergroup
+AllowGroups agroup DOMAIN
+ewgroup anothergroup

Any pointers gladly accepted.

Karl.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.
 
 


This email and any files transmitted with it are confidential and intended solely for the recipient(s). If you are not the named addressee you should not disseminate, distribute, copy or alter this email. Any views or opinions presented in this email are solely those of the author and might not represent those of theScore, Inc. or any of its affiliates. Warning: Although theScore, Inc. has taken reasonable precautions to ensure no viruses are present in this email, the company cannot accept responsibility for any loss or damage arising from the use of this email or attachments.

--
You received this message because you are subscribed to a topic in the Google Groups "Salt-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/salt-users/L98XKoWH0Uk/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to salt-users+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages