Formatting data: YAML and JSON
You can switch a data structure in a template from or to JSON or YAML format, with options for formatting, indenting, and loading data. The basic filters are occasionally useful for debugging:
Seeansible.builtin.to_jsonandansible.builtin.to_yamlfor documentation on these filters.
For human readable output, you can use:
Seeansible.builtin.to_nice_jsonandansible.builtin.to_nice_yamlfor documentation on these filters.
You can change the indentation of either format:
Theansible.builtin.to_yamlandansible.builtin.to_nice_yamlfilters use thePyYAML librarywhich has a default 80 symbol string length limit. That causes an unexpected line break after 80th symbol (if there is a space after 80th symbol)
To avoid such behavior and generate long lines, use thewidthoption. You must use a hardcoded number to define the width, instead of a construction likefloat("inf"), because the filter does not support proxying Python functions. For example: