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:
---
- name: Retrieve ssh config from vagrant
shell: vagrant ssh-config --host vagrant chdir={{ project_path }}
changed_when: False
register: vagrant_ssh_config
- name: Add config header
lineinfile: dest=~/.ssh/config line="Host vagrant" create=yes state=
present
- name: Add ssh config to ~/.ssh/config
lineinfile: dest=~/.ssh/config line="{{ item }}" insertafter="Host
vagrant"
with_items: vagrant_ssh_config.stdout_lines
If the lineinfile module correctly processed newline characters (in the
regexp= argument as well) and didn't add the surrounding quotes to
multiline strings this could be done in two steps and likely resolve a few
edge cases. In particular the procedure I'm using may produce unwanted
lines if my vagrant ssh-config output changes.
On Saturday, August 2, 2014 3:20:15 PM UTC-4, Amr Ali wrote:
>
> maybe it's because of the multiline output?
>
> you should try it with stdout_lines instead of stdout, you'd probably have
> to change your regexp parameter to an insertafter
>
> - name: Add ssh config to ~/.ssh/config
> lineinfile: path=~/.ssh/config line={{ item }} insertafter="^Host
> vagrantguest\n.*\n"
> with_items: vagrant_ssh_config.stdout_lines
>
>
>
> On Saturday, August 2, 2014 8:42:13 PM UTC+2, Synaesthete wrote:
>>
>> 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.
>>
>> I'm running the most recent build, v1.7
>>
>>
>>
>> On Saturday, August 2, 2014 2:24:44 PM UTC-4, Michael DeHaan wrote:
>>>
>>> Let me know what version of Ansible you are running?
>>>
>>> In light of some security fixes, it took a few revs to nail quoting in
>>> some cases.
>>>
>>> All being said, 1.6.10 is good stuff on that front.
>>>
>>>
>>>
>>>
>>> On Sat, Aug 2, 2014 at 1:16 PM, Amr Ali <[email protected]> wrote:
>>>
>>>> This is strange, does the output itself have the quotes or it gets
>>>> added by jinja? can you post the "vagrant_ssh_config" output?
>>>>
>>>> maybe you can try doing this it will stop jinja from automatically
>>>> escaping your variables based on your environment :
>>>>
>>>> {{ vagrant_ssh_config.stdout | safe }}
>>>>
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Ansible Project" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected].
>>>> To post to this group, send email to [email protected].
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/ansible-project/62c15bc7-768e-485c-8850-557c4ef14251%40googlegroups.com
>>>>
>>>> <https://groups.google.com/d/msgid/ansible-project/62c15bc7-768e-485c-8850-557c4ef14251%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/5f19d455-3298-422f-a2a8-2d087c44e026%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.