Member-only story
How to Break a String Over Multiple Lines with Ansible and YAML
How to use multi-line YAML variables in Ansible using the “|”, Literal Block Scalar, and the “>”, Folded Block Scalar, operators. Plus how to elide the new line “\n” at the end of the line and print multi-line with debug module on a terminal.
5 min readNov 22, 2023
Introduction
Welcome to another episode of Ansible Pilot! I’m Luca Berton and today, we’ll explore a handy technique in Ansible — breaking strings over multiple lines using YAML. This can be especially useful when dealing with multiline text in your Ansible playbooks. Let’s dive in and explore the two operators that make this possible: the |
(Literal Block Scalar) and the >
(Folded Block Scalar).
The Basics: |
and >
Operators
In Ansible, breaking a string over multiple lines is accomplished using two main operators:
|
(Literal Block Scalar): This operator instructs Ansible to treat the string as a literal block scalar, preserving the newlines within the string.>
(Folded Block Scalar): This…