I’ve been banging my head against this for two days. Maybe I’m missing something. When fetching a YAML file or template with lookup function, all the newlines are not preserved, but converted to ‘\n’. This does not happen for other file types (like json). Is this the expected behavior? Is there a way around it?
Examples follow:
given file ‘test.yml’
`
json:
- rigid
- better for data interchange
yaml: - slim and flexible
- better for configuration
object:
key: value
array: - null_value:
- boolean: true
- integer: 1
paragraph: >
Blank lines denote
paragraph breaks
content: |-
Or we
can auto
convert line breaks
to save space
`
printing out a lookup:
`
- debug:
msg: “{{ lookup(‘file’, test.yml’) }}”
`
results in:
ok: [localhost] => {
“msg”: “json:\n - rigid\n - better for data interchange\nyaml:\n - slim and flexible\n - better for configuration\nobject:\n key: value\n array:\n - null_value:\n - boolean: true\n - integer: 1\nparagraph: >\n Blank lines denote\n\n paragraph breaks\ncontent: |-\n Or we\n can auto\n convert line breaks\n to save space”
}
On the other hand, given the same info in JSON (‘test.json’):
`
{
“json”: [
“rigid”,
“better for data interchange”
],
“yaml”: [
“slim and flexible”,
“better for configuration”
],
“object”: {
“key”: “value”,
“array”: [
{
“null_value”: null
},
{
“boolean”: true
},
{
“integer”: 1
}
]
},
“paragraph”: “Blank lines denote\nparagraph breaks\n”,
“content”: “Or we\ncan auto\nconvert line breaks\nto save space”
}
`
and printing out the same lookup:
`
- debug:
msg: “{{ lookup(‘file’, test.json’) }}”
`
results in: