Ansible SSH forwarding doesn't seem to work with Vagrant

前端 未结 6 1294
Happy的楠姐
Happy的楠姐 2021-01-31 04:17

OK, strange question. I have SSH forwarding working with Vagrant. But I\'m trying to get it working when using Ansible as a Vagrant provisioner.

I found out exactly what

6条回答
  •  说谎
    说谎 (楼主)
    2021-01-31 04:59

    I struggled with a very similar problem for a few hours. Vagrant 1.7.2 ansible 1.9.4

    My symptoms:

    failed: [vagrant1] => {"cmd": "/usr/bin/git ls-remote '' -h refs/heads/HEAD", "failed": true, "rc": 128}
    stderr: Permission denied (publickey).
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    
    msg: Permission denied (publickey).
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    
    FATAL: all hosts have already failed -- aborting
    

    SSH'ing into the guest, I found that my ssh-agent was forwarding as expected:

    vagrant@vagrant-ubuntu-trusty-64:~$ ssh -T git@github.com
    Hi baxline! You've successfully authenticated, but GitHub does not provide shell access.
    

    However, from the host machine, I could not open the connection:

    $ ansible web -a "ssh-add -L"
    vagrant1 | FAILED | rc=2 >>
    Could not open a connection to your authentication agent.
    

    After confirming that my ansible.cfg file was set up, as @Lorin noted, and my Vagrantfile set config.ssh.forward_agent = true, I still came up short.

    The solution was to delete all lines in my host's ~/.ssh/known_hosts file that were associated with my guest. For me, they were the lines that started with:

    [127.0.0.1]:2201 ssh-rsa
    [127.0.0.1]:2222 ssh-rsa
    [127.0.01]:2222 ssh-rsa
    [127.0.0.1]:2200 ssh-rsa
    

    Note the third line has a funny ip address. I'm not certain, but I believe that line was the culprit. These lines are created as I destroy and create vagrant VMs.

提交回复
热议问题