To simplify out the fact that my multi-line string was YAML, how about this 
example:

Example string:
multi_line_string: |
  Lorem ipsum dolor sit amet,
  consectetur adipiscing elit,
  sed do eiusmod tempor incididunt
  ut labore et dolore magna aliqua. Ut enim
  ad minim veniam, quis nostrud exercitation
  ullamco laboris nisi ut aliquip ex ea commodo
  consequat.
  Duis aute irure dolor in reprehenderit in
  voluptate velit esse cillum dolore eu fugiat nulla
  pariatur. Excepteur sint occaecat cupidatat non proident,
  sunt in culpa qui officia deserunt mollit anim id est laborum.


Task:
- name: Cloud-init user_data
  debug: var=multi_line_string

Output:
ok: [localhost] => {
    "multi_line_string": "Lorem ipsum dolor sit amet,\nconsectetur 
adipiscing elit,\nsed do eiusmod tempor incididunt\nut labore et dolore 
magna aliqua. Ut enim\nad minim veniam, quis nostrud exercitation\nullamco 
laboris nisi ut aliquip ex ea commodo\nconsequat.\nDuis aute irure dolor in 
reprehenderit in\nvoluptate velit esse cillum dolore eu fugiat 
nulla\npariatur. Excepteur sint occaecat cupidatat non proident,\nsunt in 
culpa qui officia deserunt mollit anim id est laborum.\n"
}





On Monday, 15 September 2014 15:59:29 UTC-7, Michael DeHaan wrote:
>
> Let me take that back - it's because it's JSON.   It would not be valid 
> JSON if it were not.
>
> Sorry, this is what you're pretty much going to have here, unless we teach 
> debug to have an format=yaml option or something, which I'd be ok with.
>
> But even then, YAML needs hints and might get it wrong.
>
> On Mon, Sep 15, 2014 at 6:58 PM, Michael DeHaan <mic...@ansible.com 
> <javascript:>> wrote:
>
>> That's because they are escaped newlines, versus real newlines, I'm 
>> suspecting.
>>
>>
>>
>> On Mon, Sep 15, 2014 at 6:51 PM, AJ Daws <tony....@gmail.com 
>> <javascript:>> wrote:
>>
>>> Unfortunately that still shows escaped newline characters so isn't any 
>>> more readable.  For example:
>>>
>>> TASK: [ec2-launcher-v2 | debug var=cloudinit_user_data] 
>>> ***********************
>>> ok: [localhost] => {
>>>     "cloudinit_user_data": "#cloud-config\nusers:\n - name: core\n   
>>> ssh-authorized-keys:\n     - ssh-rsa AAAA..."
>>>
>>>
>>> On Monday, 15 September 2014 14:32:43 UTC-7, James Cammarata wrote:
>>>>
>>>> Hi AJ,
>>>>
>>>> Using "- debug: var=cloudinit_user_data" will show you the 
>>>> pretty-printed version of the var, without any escaped values, though you 
>>>> won't be able to control the indentation of that data.
>>>>
>>>> Thanks!
>>>>
>>>> On Fri, Sep 12, 2014 at 7:55 PM, AJ Daws <tony....@gmail.com> wrote:
>>>>
>>>>> I have a large, multi-line string that I would like to output in a 
>>>>> role.  Currently I'm using the debug module like this:
>>>>>
>>>>> - name: Cloud-init user_data
>>>>>   debug:
>>>>>     msg: "{{ cloudinit_user_data|indent(6) }}"
>>>>>
>>>>> However this generates JSON output which is quite hard to read as 
>>>>> newlines are represented as "\n" rather than an actual new line.  Is 
>>>>> there 
>>>>> a simple way to simply output a string as-is?
>>>>>
>>>>>  -- 
>>>>> 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 ansible-proje...@googlegroups.com.
>>>>> To post to this group, send email to ansible...@googlegroups.com.
>>>>> To view this discussion on the web visit https://groups.google.com/d/
>>>>> msgid/ansible-project/ea53aba8-c5c4-449b-875d-
>>>>> 8440606426bc%40googlegroups.com 
>>>>> <https://groups.google.com/d/msgid/ansible-project/ea53aba8-c5c4-449b-875d-8440606426bc%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>
>>>>  -- 
>>> 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 ansible-proje...@googlegroups.com <javascript:>.
>>> To post to this group, send email to ansible...@googlegroups.com 
>>> <javascript:>.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/ansible-project/6aad5e54-d5ae-46ac-a08e-153591f35b95%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/ansible-project/6aad5e54-d5ae-46ac-a08e-153591f35b95%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/ab76c13a-0880-41af-8b8d-21ee08dc4db2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to