Skip to content

Instantly share code, notes, and snippets.

@tbielawa
Created September 7, 2016 15:34
Show Gist options
  • Save tbielawa/2e037f190845fb8f951bcea03f7e780f to your computer and use it in GitHub Desktop.
Save tbielawa/2e037f190845fb8f951bcea03f7e780f to your computer and use it in GitHub Desktop.
AnsibleDumper subclasses yaml.SafeDumper
diff --git a/filter_plugins/oo_filters.py b/filter_plugins/oo_filters.py
index 053de77..7b241e2 100644
--- a/filter_plugins/oo_filters.py
+++ b/filter_plugins/oo_filters.py
@@ -16,6 +16,7 @@ import pkg_resources
import re
import json
import yaml
+from ansible.parsing.yaml.dumper import AnsibleDumper
from ansible.utils.unicode import to_unicode
from urlparse import urlparse
@@ -621,7 +622,9 @@ class FilterModule(object):
return ""
try:
- transformed = yaml.safe_dump(data, indent=indent, allow_unicode=True, default_flow_style=False, **kw)
+ transformed = yaml.dump(data, indent=indent, allow_unicode=True, default_flow_style=False, Dumper=AnsibleDumper, **kw)
padded = "\n".join([" " * level * indent + line for line in transformed.splitlines()])
return to_unicode("\n{0}".format(padded))
except Exception as my_e:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment