Skip to content

Instantly share code, notes, and snippets.

@adarazs
Last active September 16, 2016 14:48
Show Gist options
  • Save adarazs/5836e388f5bd26ac644646e3bf0b633a to your computer and use it in GitHub Desktop.
Save adarazs/5836e388f5bd26ac644646e3bf0b633a to your computer and use it in GitHub Desktop.
Folded vs literal YaML quoting in Ansible

Folded vs literal YaML quoting in Ansible

Here's the folded and literal style definition: http://www.yaml.org/spec/1.2/spec.html#id2795688

Let's take this simple ansible playbook:

- name: folded vs literal
  hosts: localhost
  tasks:
    - name: literal text
      shell: |
        echo this is \
        one command
        echo this is another
    - name: folded text
      shell: >
        echo hello
        one command;
        echo this is another

This would result in the following output if ran with the customary -vv verbosity:

< TASK: literal text >
 --------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||


<localhost> REMOTE_MODULE command echo this is one command echo this is another #USE_SHELL
changed: [localhost] => {"changed": true, "cmd": "echo this is one command\n echo this is another", "delta": "0:00:00.001210", "end": "2016-07-12 17:35:52.414363", "rc": 0, "start": "2016-07-12 17:35:52.413153", "stderr": "", "stdout": "this is one command\nthis is another", "warnings": []}
 ___________________
< TASK: folded text >
 -------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||


<localhost> REMOTE_MODULE command echo hello one command; echo this is another #USE_SHELL
changed: [localhost] => {"changed": true, "cmd": "echo hello one command; echo this is another", "delta": "0:00:00.001185", "end": "2016-07-12 17:35:52.481240", "rc": 0, "start": "2016-07-12 17:35:52.480055", "stderr": "", "stdout": "hello one command\nthis is another", "warnings": []}

Notice that in the second case you can directly copy command from the output, instead of having to reformat it. If we're formatting the folded text properly (having ; at the end of lines) then we can pretty much copy and paste from both the playbook and from the output, while the literal text can be only copied from the playbook, and causes problems from the output.

This is why I usually recommend using >.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment