Ansible SSH 转发似乎不适用于 Vagrant [英] Ansible SSH forwarding doesn't seem to work with Vagrant

查看:29
本文介绍了Ansible SSH 转发似乎不适用于 Vagrant的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,奇怪的问题.我有与 Vagrant 合作的 SSH 转发.但是我试图在使用 Ansible 作为 Vagrant 配置器时让它工作.

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.

我确切地发现了 Ansible 正在执行的内容,并自己从命令行尝试了它,果然,它也失败了.

I found out exactly what Ansible is executing, and tried it myself from the command line, sure enough, it fails there too.

[/common/picsolve-ansible/u12.04%]ssh -o HostName=127.0.0.1 \
 -o User=vagrant -o  Port=2222 -o UserKnownHostsFile=/dev/null \
 -o StrictHostKeyChecking=no -o PasswordAuthentication=no \
 -o IdentityFile=/Users/bryanhunt/.vagrant.d/insecure_private_key \
 -o IdentitiesOnly=yes -o LogLevel=FATAL \
 -o ForwardAgent=yes "/bin/sh  \
 -c 'git clone git@bitbucket.org:bryan_picsolve/poc_docker.git /home/vagrant/poc_docker' "
Permission denied (publickey,password).

但是当我只运行 vagrant ssh 时,代理转发工作正常,我可以检查 R/W 我的 github 项目.

But when I just run vagrant ssh the agent forwarding works correctly, and I can checkout R/W my github project.

[/common/picsolve-ansible/u12.04%]vagrant ssh
vagrant@vagrant-ubuntu-precise-64:~$ /bin/sh  -c 'git clone git@bitbucket.org:bryan_picsolve/poc_docker.git /home/vagrant/poc_docker'
Cloning into '/home/vagrant/poc_docker'...
remote: Counting objects: 18, done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 18 (delta 4), reused 0 (delta 0)
Receiving objects: 100% (18/18), done.
Resolving deltas: 100% (4/4), done.
vagrant@vagrant-ubuntu-precise-64:~$

有人知道它是如何工作的吗?

Has anyone got any idea how it is working?

更新:

通过 ps awux 我确定了 Vagrant 正在执行的确切命令.

By means of ps awux I determined the exact command being executed by Vagrant.

我复制了它并且 git checkout 工作了.

I replicated it and git checkout worked.

 ssh vagrant@127.0.0.1 -p 2222 \
  -o Compression=yes \
  -o StrictHostKeyChecking=no \
  -o LogLevel=FATAL \ 
  -o StrictHostKeyChecking=no \
  -o UserKnownHostsFile=/dev/null \
  -o IdentitiesOnly=yes \
  -i /Users/bryanhunt/.vagrant.d/insecure_private_key \
  -o ForwardAgent=yes \
  -o LogLevel=DEBUG \
   "/bin/sh  -c 'git clone git@bitbucket.org:bryan_picsolve/poc_docker.git /home/vagrant/poc_docker' "

推荐答案

As of ansible 1.5 (devel aa2d6e47f0) last updated 2014/03/24 14:23:18 (GMT +100) and Vagrant 1.5.1 this now works.

As of ansible 1.5 (devel aa2d6e47f0) last updated 2014/03/24 14:23:18 (GMT +100) and Vagrant 1.5.1 this now works.

我的 Vagrant 配置包含以下内容:

My Vagrant configuration contains the following:

config.vm.provision "ansible" do |ansible|
   ansible.playbook = "../playbooks/basho_bench.yml"
   ansible.sudo = true
   ansible.host_key_checking = false
   ansible.verbose =  'vvvv'
   ansible.extra_vars = { ansible_ssh_user: 'vagrant', 
                 ansible_connection: 'ssh',
                 ansible_ssh_args: '-o ForwardAgent=yes'}

显式禁用 sudo 使用也是一个好主意.例如,当使用 Ansible git 模块时,我这样做:

It is also a good idea to explicitly disable sudo use. For example, when using the Ansible git module, I do this:

- name: checkout basho_bench repository 
  sudo: no
  action: git repo=git@github.com:basho/basho_bench.git dest=basho_bench

这篇关于Ansible SSH 转发似乎不适用于 Vagrant的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆