Re: [ansible-project] YAML line breaks (newlines) when performing lookups of files or templates
Thanks for the insight. Turns out the problem is in one of Ansible's modules, not the formatting of the lookup result. On Monday, October 15, 2018 at 10:10:36 AM UTC-6, Kai Stian Olstad wrote: > > On Saturday, 13 October 2018 18.37.22 CEST Dmitriy Panteleyev wrote: > > 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'. > > They are not converted, this is just how the default callback plugin > chooses to show the content in the debug module. > > > > This does not > > happen for other file types (like json). Is this the expected behavior? > > Yes > > > > Is there a way around it? > > Ansible is not a reporting tool, so if that is what you are looking for > you probably need some other tool. > That being said you have many callback plugins to choose[1] and if non of > them suites your need to can always create you own. > > > [1] https://docs.ansible.com/ansible/2.7/plugins/callback.html#plugin-list > > -- > Kai Stian Olstad > > > -- 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/0a4c820b-0ac0-44a0-bc51-6181f9998cee%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [ansible-project] YAML line breaks (newlines) when performing lookups of files or templates
On Saturday, 13 October 2018 18.37.22 CEST Dmitriy Panteleyev wrote: > 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'. They are not converted, this is just how the default callback plugin chooses to show the content in the debug module. > This does not > happen for other file types (like json). Is this the expected behavior? Yes > Is there a way around it? Ansible is not a reporting tool, so if that is what you are looking for you probably need some other tool. That being said you have many callback plugins to choose[1] and if non of them suites your need to can always create you own. [1] https://docs.ansible.com/ansible/2.7/plugins/callback.html#plugin-list -- Kai Stian Olstad -- 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/2542385.SYnOA5c5cv%40x1. For more options, visit https://groups.google.com/d/optout.
[ansible-project] YAML line breaks (newlines) when performing lookups of files or templates
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: > ok: [localhost] => { > "msg": { > "content": "Or we\ncan auto\nconvert line breaks\nto save space", > "json": [ > "rigid", > "better for data interchange" > ], > "object": { > "array": [ > { > "null_value": null > }, > { > "boolean": true > }, > { > "integer": 1 > } > ], > "key": "value" > }, > "paragraph": "Blank lines denote\nparagraph breaks\n", > "yaml": [ > "slim and flexible", > "better for configuration" > ] > } > } -- 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/b4025b7e-c566-4113-b114-8ec0db1e01ce%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.