Your points lead me to this article:
https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#formatting-data-yaml-and-json
Which notes the difference with default width of 80 with pyyaml. I changed
the width to 2147483647 on the "to_nice_yaml":
- debug:
msg: "{{ lookup('template','test.j2') | from_yaml | to_nice_yaml(indent=2,
sort_keys=False, width=2147483647) }}"
and now I see the same output from 2.11 and 2.12.
Thank you for the quick support!
On Tuesday, November 9, 2021 at 4:20:33 PM UTC+1 Claus Holbech wrote:
> Thanks Matt
> Is there a way I can force Ansible 2.11.x into using the C
> extension/libyaml variant?
>
> On Tuesday, November 9, 2021 at 3:29:24 PM UTC+1 Matt Martz wrote:
>
>> The only changes to YAML in 2.12 were to properly prefer the C
>> extension/libyaml over the pure python implementation. So it's possible
>> there is some emitter difference between the pyyaml (python) and libyaml
>> (C) implementations.
>>
>>
>>
>> On Tue, Nov 9, 2021 at 4:09 AM 'Claus Holbech' via Ansible Project <
>> [email protected]> wrote:
>>
>>> We are seeing a small change to the output of "to_nice_yaml" and
>>> "to_yaml" when using ansible-core 2.12 versus 2.11.5 and older. The changes
>>> are only about escaping for wrapped multi-line strings.
>>>
>>> If this in on purpose, please let me know how I can get the older
>>> ansible versions to produce the same output.
>>>
>>> Thanks
>>> Claus
>>>
>>> Simple playbook:
>>> - hosts: localhost
>>> gather_facts: false
>>> vars:
>>> test_var: |
>>> test line 1 which is very long so it wraps around during templating
>>> ..................
>>> test line 2 which is indented
>>> tasks:
>>> - debug:
>>> msg: '{{ lookup("template","test.j2") }}'
>>> - debug:
>>> msg: '{{ lookup("template","test.j2") | from_yaml }}'
>>> - debug:
>>> msg: '{{ lookup("template","test.j2") | from_yaml |
>>> to_nice_yaml(indent=2, sort_keys=False) }}'
>>>
>>> And very simple template:
>>> test: |
>>> {{ test_var | indent(2,false) }}
>>>
>>> Output from 2.11.5:
>>> TASK [debug]
>>> **********************************************************************************************************************************************************************************
>>> tirsdag 09 november 2021 10:54:14 +0100 (0:00:00.013) 0:00:00.013 ******
>>> ok: [localhost] => { "msg": "test: |\n test line 1 which is very long so it
>>> wraps around during templating ..................\n test line 2 which is
>>> indented\n" } TASK [debug]
>>> **********************************************************************************************************************************************************************************
>>>
>>> tirsdag 09 november 2021 10:54:14 +0100 (0:00:00.025) 0:00:00.039 ******
>>> ok: [localhost] => { "msg": { "test": "test line 1 which is very long so it
>>> wraps around during templating ..................\n test line 2 which is
>>> indented\n" } } TASK [debug]
>>> **********************************************************************************************************************************************************************************
>>>
>>> tirsdag 09 november 2021 10:54:14 +0100 (0:00:00.030) 0:00:00.069 ******
>>> ok: [localhost] => { "msg": "test: \"test line 1 which is very long so it
>>> wraps around during templating ..................\\n\\\n \\ test line 2
>>> which is indented\\n\"\n" }
>>>
>>> Output from 2.12.0:
>>> TASK [debug]
>>> **********************************************************************************************************************************************************************************
>>> tirsdag 09 november 2021 11:03:48 +0100 (0:00:00.014) 0:00:00.014
>>> ******
>>> ok: [localhost] => {
>>> "msg": "test: |\n test line 1 which is very long so it wraps around
>>> during templating ..................\n test line 2 which is indented\n"
>>> }
>>>
>>> TASK [debug]
>>> **********************************************************************************************************************************************************************************
>>> tirsdag 09 november 2021 11:03:48 +0100 (0:00:00.028) 0:00:00.042
>>> ******
>>> ok: [localhost] => {
>>> "msg": {
>>> "test": "test line 1 which is very long so it wraps around
>>> during templating ..................\n test line 2 which is indented\n"
>>> }
>>> }
>>>
>>> TASK [debug]
>>> **********************************************************************************************************************************************************************************
>>> tirsdag 09 november 2021 11:03:48 +0100 (0:00:00.029) 0:00:00.072
>>> ******
>>> ok: [localhost] => {
>>> "msg": "test: \"test line 1 which is very long so it wraps around
>>> during templating ..................\\n\n \\ test line 2 which is
>>> indented\\n\"\n"
>>> }
>>>
>>>
>>>
>>>
>>> --
>>> 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 [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ansible-project/7d3611d3-b680-487f-92a5-1a843efeb01bn%40googlegroups.com
>>>
>>> <https://groups.google.com/d/msgid/ansible-project/7d3611d3-b680-487f-92a5-1a843efeb01bn%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>
>>
>> --
>> Matt Martz
>> @sivel
>> sivel.net
>>
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/9a5b3cca-6879-4f3a-b238-46e7fcc4fdd5n%40googlegroups.com.