Difference: AnsibleTipsTricks (16 vs. 17)

Revision 1712 Jun 2023 - IvoVanGeel

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Ansible tips & tricks

Line: 22 to 22
 Use a backslash (\) to split long lines:
Changed:
<
<
- fail:
>
>
- set_fact:
  msg: "This is the first part and second part of the string"
Added:
>
>
- debug: var: msg
 

Results in:

Deleted:
<
<
fatal: [localhost]: FAILED! => {"changed": false, "msg": "This is the first part and second part of the string"}
 
Changed:
<
<
For other ways of splitting long lines, see: https://stackoverflow.com/questions/3790454/how-do-i-break-a-string-in-yaml-over-multiple-lines
>
>
"msg": "This is the first part and second part of the string"

Use a greater-than sign (>) to split long lines, without interior line breaks:

    - set_fact:
        msg: >
          This is the first part
          and second part of the string

    - debug:
        var: msg

Results in:

"msg": "This is the first part and second part of the string\n"

Use a pipe sign (|) to split long lines, preserving interior line breaks:

    - set_fact:
        msg: |
          This is the first part
          and second part of the string

    - debug:
        var: msg

Results in:

"msg": "This is the first part \nand second part of the string\n"

Add a minus sign (-) after a greater-than or pipe symbol to remove the line break at the end of the line (use >- or |-)

See: https://stackoverflow.com/questions/3790454/how-do-i-break-a-string-in-yaml-over-multiple-lines

 

Dump all variables

 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2010-2019 by LANIS