ansible.builtin.to_nice_yaml filter – Convert variable to YAML string
Note
This filter plugin is part of ansible-core
and included in all Ansible
installations. In most cases, you can use the short
plugin name
to_nice_yaml
even without specifying the collections:
keyword.
However, we recommend you use the FQCN for easy linking to the
plugin documentation and to avoid conflicting with other collections that may have
the same filter plugin name.
Synopsis
Converts an Ansible variable into a YAML string representation.
This filter functions as a wrapper to the Python PyYAML library‘s
yaml.dump
function.Ansible internally auto-converts YAML strings into variable structures so this plugin is used to force it into a YAML string.
Input
This describes the input of the filter, the value before | ansible.builtin.to_nice_yaml
.
Parameter |
Comments |
---|---|
A variable or expression that returns a data structure. |
Keyword parameters
This describes keyword parameters of the filter. These are the values key1=value1
, key2=value2
and so on in the following
example: input | ansible.builtin.to_nice_yaml(key1=value1, key2=value2, ...)
Parameter |
Comments |
---|---|
Number of spaces to indent Python structures, mainly used for display to humans. |
|
Affects sorting of dictionary keys. Choices:
|
Notes
Note
More options may be available, see PyYAML documentation for details.
These parameters to
yaml.dump
will be ignored, as they are overridden internally: default_flow_style
Examples
# dump variable in a template to create a YAML document
{{ github_workflow | to_nice_yaml }}
Return Value
Key |
Description |
---|---|
The YAML serialized string representing the variable structure inputted. Returned: success |