How Do You Use Ansible to Have Retrievable Double Quotes ‘”‘ in a Variable?

Problem scenario
You are using Ansible, and you want a playbook to have a variable with double quotes. The double quotes are disappearing from your echo var1.stdout[:] invocations. How do you get shell/bash commands to have double quotes?

Rather than "echo" a string with double quotes, use a variable assignment. Do not use this: echo "a \"long string\" for a \"test\" "

Use something like this: coolstring="a \"long string\" for a \"test\" " && echo $coolstring > /tmp/basicfile

Now /tmp/basicfile will have the double quotes the way you want them. (You do not always have to do this to preserve the double quotes. We find it can be difficult sometimes to preserve the double quotes in a string.

Leave a comment

Your email address will not be published. Required fields are marked *