debug module does not escape double quotes

26 views
Skip to first unread message

rasha hajlaoui

unread,
Mar 5, 2018, 6:15:02 AM3/5/18
to Ansible Project

Hello guys,

I've got a problem with ansible playbook. In fact, I use debug module to display a file content. 


the content of myfile is : 


 <network ip="1.2.3.[0-255]" />


my playbook.yml is as follow: 


- name: Display file content
      shell: cat myfile
      register: file

- debug:
      msg: "{{file.stdout_lines}}"



playbook.yml output : 


TASK [debug] ***************************************************************************************************************************
ok: [serveur] => {
    "msg": [
        " <network ip=\"1.2.3.[0-255]\" />"
    ]
}


I don't want ansible to add anti-slashes before double quotes. I just want it to display the file content as it is. 

I'll appreciate any help to fix this. 

Thanks in advance.

Rasha 

Jordan Borean

unread,
Mar 5, 2018, 2:49:42 PM3/5/18
to Ansible Project
You may be able to do it with a different callback plugin but by default the output is displayed in JSON. JSON uses double quotes to quote keys and values so if the value has double quotes in them they need to be escaped with a backslash, e.g. the value of 'abc "123"' would become "'abc \"123\"' in JSON

Thanks

Jordan

Kai Stian Olstad

unread,
Mar 6, 2018, 2:40:34 AM3/6/18
to ansible...@googlegroups.com
On Monday, 5 March 2018 12.15.02 CET rasha hajlaoui wrote:
> I've got a problem with ansible playbook. In fact, I use debug module to
> display a file content.
>
>
> *the content of myfile is : *
>
>
> <network ip="1.2.3.[0-255]" />
>
>
> *my playbook.yml is as follow: *
>
>
> - name: Display file content
> shell: cat myfile
> register: file
>
> - debug:
> msg: "{{file.stdout_lines}}"

You are printing out stdout_lines which is a list, you need to use {{ file.stdout }} instead.


--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages