# Problem with SSH Forwarding using Ansible and Vagrant

**URL:** <https://forum.ansible.com/t/problem-with-ssh-forwarding-using-ansible-and-vagrant/16597>\
**Category:** Ansible Project\
**Created:** [October 24, 2014, 9:30am UTC](https://forum.ansible.com/t/problem-with-ssh-forwarding-using-ansible-and-vagrant/16597 "2014-10-24T09:30:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Navid\_Paya](https://avatars.discourse-cdn.com/v4/letter/n/9fc29f/32.png) [@Navid\_Paya](https://forum.ansible.com/u/Navid_Paya)\
**Post date:** [October 24, 2014, 9:30am UTC](https://forum.ansible.com/t/problem-with-ssh-forwarding-using-ansible-and-vagrant/16597/1 "2014-10-24T09:30:00Z")

</div>

Hi all  
I’m trying to use SSH forwarding to clone some private repos from github using Ansible on a Vagrant instance but it fails. Here are the involved artifacts. I’ve read pretty much all the related Google searches but can’t figure out what’s wrong after a couple of days.

[Vagrantfile](http://pastebin.com/mQAyggGi#)

[local.yml](http://pastebin.com/qeuY3qR4)

[nodes.yml](http://pastebin.com/vhS65c8X)

Any this is the log I get when running the playbook.

\<127.0.0.1\> ESTABLISH CONNECTION FOR USER: vagrant  
\<127.0.0.1\> REMOTE\_MODULE git repo=ssh:**@github.com:myteksi/dispatcher-API.git accept\_hostkey=yes dest=/tmp/-API  
\<127.0.0.1\> EXEC [‘ssh’, ‘-C’, ‘-tt’, ‘-vvv’, ‘-o’, ‘ForwardAgent=yes’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/Users/navid/.ansible/cp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘StrictHostKeyChecking=no’, ‘-o’, ‘Port=2222’, ‘-o’, ‘IdentityFile=“/Users/navid/.vagrant.d/insecure\_private\_key”’, ‘-o’, ‘KbdInteractiveAuthentication=no’, ‘-o’, ‘PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey’, ‘-o’, ‘PasswordAuthentication=no’, ‘-o’, ‘User=vagrant’, ‘-o’, ‘ConnectTimeout=10’, ‘127.0.0.1’, “/bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1414142060.76-115960370897689 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1414142060.76-115960370897689 && echo $HOME/.ansible/tmp/ansible-tmp-1414142060.76-115960370897689’”]  
\<127.0.0.1\> PUT /var/folders/5y/f05p3ryx575fjvsrmrv2w1100000gn/T/tmpnk8Suv TO /home/vagrant/.ansible/tmp/ansible-tmp-1414142060.76-115960370897689/git  
\<127.0.0.1\> EXEC [‘ssh’, ‘-C’, ‘-tt’, ‘-vvv’, ‘-o’, ‘ForwardAgent=yes’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/Users/navid/.ansible/cp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘StrictHostKeyChecking=no’, ‘-o’, ‘Port=2222’, ‘-o’, ‘IdentityFile=“/Users/navid/.vagrant.d/insecure\_private\_key”’, ‘-o’, ‘KbdInteractiveAuthentication=no’, ‘-o’, ‘PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey’, ‘-o’, ‘PasswordAuthentication=no’, ‘-o’, ‘User=vagrant’, ‘-o’, ‘ConnectTimeout=10’, ‘127.0.0.1’, u"/bin/sh -c ‘LANG=en\_US.UTF-8 LC\_CTYPE=en\_US.UTF-8 /usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1414142060.76-115960370897689/git; rm -rf /home/vagrant/.ansible/tmp/ansible-tmp-1414142060.76-115960370897689/ \>/dev/null 2\>&1’"]  
failed: [default] =\> (item=-API) =\> {“cmd”: "/usr/bin/git ls-remote ssh:**", “failed”: true, “item”: “-API”, “rc”: 128}  
stderr: ERROR: Repository not found.  
fatal: Could not read from remote repository.

Please make sure you have the correct access rights  
and the repository exists.

msg: ERROR: Repository not found.  
fatal: Could not read from remote repository.

Please make sure you have the correct access rights  
and the repository exists.

Now if I do a “vagrant ssh” and then do “ssh-add -L”, I can see the key is forwarded and I can clone the same repo just fine. The log doesn’t look like I’m doing sudo for that task as well, although I added this to my shudders file to test that as well:

Defaults env\_keep += “SSH\_AUTH\_SOCK”

Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [October 24, 2014, 1:40pm UTC](https://forum.ansible.com/t/problem-with-ssh-forwarding-using-ansible-and-vagrant/16597/2 "2014-10-24T13:40:25Z")

</div>

“I’m trying to use SSH forwarding to clone some private repos from github using Ansible on a Vagrant instance but it fails”

Would it be possible to put your private key on the development machine, since it’s local to you anyway?

You could then use the key\_file parameter and save yourself the trouble.

Unfortunately I don’t know a lot about Vagrant but a lot of people get confused by the provisioner when trying to do fancy things with it, and the extra level of SSH involved may be hiccuping things.

[http://docs.ansible.com/git\_module.html](http://docs.ansible.com/git_module.html)

---

<div class="post-metadata">

**Author:** ![Navid\_Paya](https://avatars.discourse-cdn.com/v4/letter/n/9fc29f/32.png) [@Navid\_Paya](https://forum.ansible.com/u/Navid_Paya)\
**Post date:** [October 25, 2014, 3:54am UTC](https://forum.ansible.com/t/problem-with-ssh-forwarding-using-ansible-and-vagrant/16597/3 "2014-10-25T03:54:07Z")

</div>

Yes, I could do that. It’s just that my SSH key has full access to everything and didn’t want to even take a chance leaving it in the box once it’s generated and I want to share it with others but I guess you are right. Not that hard to get around it using synced folders or something of that kind. Just one question. How can I get the exact command that Ansible tries to run when connecting to the vagrant host?I see the EXEC part in the debug message. Is that the one?
