to_yaml¶
Collection Note
This module is part of the ansible.builtin collection. To install the collection, use:
Added in versionhistorical.
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 automatically converts YAML strings into variable structures so this plugin is used to forcibly retain a YAML string.
Parameters¶
| Parameter | Defaults / Choices | Comments |
|---|---|---|
| _input raw required |
A variable or expression that returns a data structure. | |
| indent integer |
Number of spaces to indent Python structures, mainly used for display to humans. | |
| sort_keys bool |
Default: True |
Affects sorting of dictionary keys. |
Notes¶
Note
- More options may be available, see L(PyYAML documentation, https://pyyaml.org/wiki/PyYAMLDocumentation) for details.
Examples¶
# dump variable in a template to create a YAML document
{{ github_workflow | to_yaml }}
# same as above but 'prettier' (equivalent to to_nice_yaml filter)
{{ docker_config | to_yaml(indent=4) }}
Return Values¶
| Key | Data Type | Description | Returned |
|---|---|---|---|
| _value | string | The YAML serialized string representing the variable structure inputted. |
Authors¶
- Core Team