On 27. sep. 2017 00:55, rurpy via Ansible Project wrote:
Hello,

I am new to Ansible and trying to see if it fits my needs but quickly ran
into the following problem:

   $ ansible ubtest -m shell -a 'echo -n "line 1\nline 2" >/tmp/foo'

/tmp/foo is created with one line containing the two characters
"\" and "n" in the middle rather than a single linefeed ("\n")
character as I want and expected.

I apologize in advance if this has an obvious solution; I have just started
with Ansible and there is a lot of material in the documentation but I
didn't see anything addressing this immediately, nor did google turn up
anything encouraging.  I'm hoping there is some filter or other simple way
to produce the desired results.
I can't confirm this behavior against Kubuntu, in my test I get to lines in the file.

In Ansible shell is using /bin/sh, on Kubuntu /bin/sh is a link to dash. Since echo is a builtin on most shells if not all shell, they may differ some. So it depends on you distribution and what /bin/sh is actually running.

To avoid this problem you could use the Ansible's copy module instead
ansible ubtest -m copy -a 'dest=/tmp/foo content="line 1\nline 2"'

--
Kai Stian Olstad

--
You received this message because you are subscribed to the Google Groups "Ansible 
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/82cb9b85-6730-d696-f96c-85b62b43c3f6%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to