Skip to content

to_nice_yaml

Collection Note

This module is part of the ansible.builtin collection. To install the collection, use:

ansible-galaxy collection install ansible.builtin
Added in version historical.

Synopsis

  • Converts an Ansible variable into a YAML string representation.
  • This filter functions as a wrapper to the L(Python PyYAML library, https://pypi.org/project/PyYAML/)'s C(yaml.dump) function.
  • Ansible internally auto-converts YAML strings into variable structures so this plugin is used to force it into a YAML string.

Parameters

Parameter Defaults / Choices Comments
_input
raw
required
A variable or expression that returns a data structure.
canonical
bool
If set to V(True), export tag type to the output.
default_style
string
Choices: , ', ", |, > Indicates the style of the scalar.
encoding
string
Specify the output encoding.
explicit_end
bool
If set to V(True), adds an explicit end using "...".
explicit_start
bool
If set to V(True), adds an explicit start using "---".
indent
integer
Number of spaces to indent Python structures, mainly used for display to humans.
line_break
string
Specify the line break.
sort_keys
bool
Default: True
Affects sorting of dictionary keys.
width
int
Set the preferred line width.

Notes

Note

  • More options may be available, see L(PyYAML documentation, https://pyyaml.org/wiki/PyYAMLDocumentation) for details.
  • These parameters to C(yaml.dump) will be ignored, as they are overridden internally: I(default_flow_style), I(allow_unicode).

Examples

# dump variable in a template to create a YAML document
{{ github_workflow | to_nice_yaml }}

Return Values

Key Data Type Description Returned
_value string The YAML serialized string representing the variable structure inputted.

Authors

  • Core Team