How to escape double and single quotes in YAML within the same string

Question:

I need to properly escape single and double quotes in an ansible playbook in order to set the environment variable. None of this works:

Looked at this:

http://yaml.org/spec/current.html#id2532720

https://github.com/dotmaster/toYaml/issues/1

The error message I get is:

Answer:

> starts a block scalar, in which you do not need to escape anything at all (and there are no escape sequences processed). So assuming you want single quotes around your JSON-like value, just do:

Edit: Also be aware that a folded scalar by default includes a trailing newline character. If you do not want to have this, just use >- instead of >.

Leave a Reply