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?
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.
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.
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”
}
Well, it’s a bit hacky but it gives the best result so far, and that’ll do. Thanks!
`
ok: [localhost] => {
“multi_line_string.split(‘\n’)”: [
“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.”,
“”
]
}