-1

I want to define an array with multiline strings.

I tried this approach and it works

vars:
  multi_line_strings_array: ["Hello\nWorld\n", "This\nis really\ngreat", "that\nit works"]

It works for small multiline strings.But if the string becomes a little big there will be a problem of readablility.

Is there any better way to define an array of multi-line strings such that readability is not a problem.

  • A YAML sequence is an array, please see the answer here : https://stackoverflow.com/questions/23657086/yaml-multi-line-arrays – Eran Chetzroni Jul 04 '19 at 14:05

1 Answers1

3

You can define multi-line variables like below - https://adminswerk.de/multi-line-string-yaml-ansible-I/

---
- hosts: localhost
  connection: local
  vars:
    my_pattern: |
      With his own sword,
      Which he did wave against my throat, I have ta’en
      His head from him.
  tasks:
    - debug:
        var: my_pattern
Prakash Krishna
  • 1,239
  • 6
  • 12