summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Clay <matt@mystile.com>2019-03-13 16:43:26 -0700
committerToshio Kuratomi <a.badger@gmail.com>2019-03-13 18:29:14 -0700
commit15c5d8525109836d9a61121fe8bac18abb56d9af (patch)
tree60e3b3969ab495b91b048f132ac59585c9453671
parentbd15658f2c5473ed9302758ba4ec124960b9c28f (diff)
downloadansible-15c5d8525109836d9a61121fe8bac18abb56d9af.tar.gz
[stable-2.7] Keep existing to_yaml behavior with pyyaml >= 5.1. (#53772)
In pyyaml versions before 5.1 the default_flow_style for yaml.dump was None. Starting with 5.1 it is now False. This change explicitly sets the value to None to maintain the original to_yaml behavior. The change to pyyaml was made in the following commit: https://github.com/yaml/pyyaml/commit/507a464ce62c933bf667b2296a96ad45f0147873 (cherry picked from commit 7f0e09aa3152597cde7007ba86b29a489a9b8cbf) Co-authored-by: Matt Clay <matt@mystile.com>
-rw-r--r--changelogs/fragments/to_yaml-default_flow_style.yaml2
-rw-r--r--lib/ansible/plugins/filter/core.py3
2 files changed, 4 insertions, 1 deletions
diff --git a/changelogs/fragments/to_yaml-default_flow_style.yaml b/changelogs/fragments/to_yaml-default_flow_style.yaml
new file mode 100644
index 0000000000..5dee7c51be
--- /dev/null
+++ b/changelogs/fragments/to_yaml-default_flow_style.yaml
@@ -0,0 +1,2 @@
+minor_changes:
+ - "``to_yaml`` filter updated to maintain formatting consistency when used with ``pyyaml`` versions 5.1 and later (https://github.com/ansible/ansible/pull/53772)"
diff --git a/lib/ansible/plugins/filter/core.py b/lib/ansible/plugins/filter/core.py
index 78e62b735d..f9314accdb 100644
--- a/lib/ansible/plugins/filter/core.py
+++ b/lib/ansible/plugins/filter/core.py
@@ -64,7 +64,8 @@ UUID_NAMESPACE_ANSIBLE = uuid.UUID('361E6D51-FAEC-444A-9079-341386DA8E2E')
def to_yaml(a, *args, **kw):
'''Make verbose, human readable yaml'''
- transformed = yaml.dump(a, Dumper=AnsibleDumper, allow_unicode=True, **kw)
+ default_flow_style = kw.pop('default_flow_style', None)
+ transformed = yaml.dump(a, Dumper=AnsibleDumper, allow_unicode=True, default_flow_style=default_flow_style, **kw)
return to_text(transformed)