Some quick background. I’m using ansible to automate setup of development environments for new projects. These are active development environments, not freshly provisioned machines, so some challenges come with the territory–in particular there are times when I would use a template to configure a new machine, but in an active dev environment I have to modify existing config files.
In one case I am configuring the ~/.ssh/config file to make it possible to SSH in to a vagrant box using a regular ‘ssh vagrantguest’ by taking the resulting config block from ‘vagrant ssh-config’. This is a multi-line block. I have a playbook that does something like this:
The variable, vagrant_ssh_config.stdout is added to the file but is surrounded in single-quotes. Is this a bug or expected behavior? Is there a way to remove these quotes? Or is there a better solution to this altogether?
I checked and on a debug message do not see single-quotes in the stdout. Adding the | safe also didn’t help. So it seems that still either jinja or ansible is throwing single-quotes around the variable data before writing it to file. I don’t see this same behavior when writing the same block using the template module, so this may be specific to lineinfile.
Good tip. I did manage to get this to work and had to add an extra step to make sure that first “Host vagrant” line is there. My tasks look like this and work fine in ansible 1.7:
glad it worked for you, someone more experienced with the code can probably tell why it’s wrapping multilines in quotes, not sure if it’s a python thing or an issue with the lineinfile module or even with how ansible registers multiline outputs.
if you have the time maybe you can test something - not even sure if this will work haven’t tried joining jinja varaibles using a newling before…