好,奇怪的问题。我有与Vagrant合作的SSH转发。但是我正在尝试将Ansible用作Vagrant预配器时使其工作。
我确切地知道了Ansible在执行什么,并在命令行中自己尝试了一下,当然,它在那里也失败了。
[/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 [email protected]:bryan_picsolve/poc_docker.git /home/vagrant/poc_docker' "
Permission denied (publickey,password).
但是,当我只运行vagrant ssh时,代理转发正常工作,并且可以 checkout 我的github项目。
[/common/picsolve-ansible/u12.04%]vagrant ssh
vagrant@vagrant-ubuntu-precise-64:~$ /bin/sh -c 'git clone [email protected]: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:~$
有谁知道它是如何工作的?
更新:
通过
ps awux
,我确定了Vagrant正在执行的确切命令。我复制了它,并且git checkout起作用了。
ssh [email protected] -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 [email protected]:bryan_picsolve/poc_docker.git /home/vagrant/poc_docker' "
最佳答案
从ansible 1.5(devel aa2d6e47f0)开始,最后更新时间为2014/03/24 14:23:18(GMT +100)和Vagrant 1.5.1,现在可以使用。
我的Vagrant配置包含以下内容:
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模块时,我这样做:
- name: checkout basho_bench repository
sudo: no
action: git [email protected]:basho/basho_bench.git dest=basho_bench
关于ssh - Ansible SSH转发似乎不适用于Vagrant,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20952689/