Kai Stian Olstad
unread,Oct 2, 2017, 2:06:26 PM10/2/17Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ansible...@googlegroups.com
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