# ansible-core 2.12 - changes to "to\_nice\_yaml" output

**URL:** <https://forum.ansible.com/t/ansible-core-2-12-changes-to-to-nice-yaml-output/35979>\
**Category:** Ansible Project\
**Created:** [November 9, 2021, 10:08am UTC](https://forum.ansible.com/t/ansible-core-2-12-changes-to-to-nice-yaml-output/35979 "2021-11-09T10:08:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ClausHolbechArista](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/clausholbecharista/32/265_2.png) [@ClausHolbechArista](https://forum.ansible.com/u/ClausHolbechArista)\
**Post date:** [November 9, 2021, 10:08am UTC](https://forum.ansible.com/t/ansible-core-2-12-changes-to-to-nice-yaml-output/35979/1 "2021-11-09T10:08:55Z")

</div>

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”  
}

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [November 9, 2021, 2:28pm UTC](https://forum.ansible.com/t/ansible-core-2-12-changes-to-to-nice-yaml-output/35979/2 "2021-11-09T14:28:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ClausHolbechArista](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/clausholbecharista/32/265_2.png) [@ClausHolbechArista](https://forum.ansible.com/u/ClausHolbechArista)\
**Post date:** [November 9, 2021, 3:20pm UTC](https://forum.ansible.com/t/ansible-core-2-12-changes-to-to-nice-yaml-output/35979/3 "2021-11-09T15:20:33Z")

</div>

Thanks Matt  
Is there a way I can force Ansible 2.11.x into using the C extension/libyaml variant?

---

<div class="post-metadata">

**Author:** ![ClausHolbechArista](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/clausholbecharista/32/265_2.png) [@ClausHolbechArista](https://forum.ansible.com/u/ClausHolbechArista)\
**Post date:** [November 9, 2021, 4:17pm UTC](https://forum.ansible.com/t/ansible-core-2-12-changes-to-to-nice-yaml-output/35979/4 "2021-11-09T16:17:57Z")

</div>

Your points lead me to this article: [https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_filters.html#formatting-data-yaml-and-json](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!
