Vagrant shell 和 ansible 配置因 bitbucket 而失败 [英] Vagrant shell and ansible provisioning fail with bitbucket
问题描述
我无法强制 vagrant 配置从 bitbucket 克隆私有 git 存储库.我有流浪者 1.6.3.
I can't force vagrant provisioning to clone private git repos from bitbucket. I have vagrant 1.6.3.
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.ssh.private_key_path = "~/.vagrant.d/insecure_private_key"
config.ssh.forward_agent = true
config.vm.define "abox" do |abox|
abox.vm.box = "ubuntu/trusty32"
abox.vm.hostname = "abox"
abox.ssh.forward_agent = true
abox.vm.network "private_network", ip: "192.168.50.4"
abox.vm.network "forwarded_port", guest: 22, host: 2233
abox.vm.network "forwarded_port", guest: 6340, host: 6340
abox.vm.network "forwarded_port", guest: 8080, host: 6388
abox.vm.provision :shell,
:path => "provisioning/ssh_keys.sh", :privileged => false
abox.vm.provision :shell,
:path => "provisioning/setup_project.sh"
end
end
我在 ssh_keys 中的位置:
Where in ssh_keys I have:
function create_key() {
ssh-add -L >> ~/.ssh/authorized_keys
ssh-keyscan -t rsa 127.0.0.1 > ~/.ssh/known_hosts
}
create_key
然后在 setup_project 中调用:
Then in setup_project I call:
su - vagrant -c "ssh-keyscan bitbucket.org >> /home/vagrant/.ssh/known_hosts && \
ssh-keyscan github.com >> /home/vagrant/.ssh/known_hosts"
echo 'Clone bitbucket repo'
su - vagrant -c "cd /vagrant && git clone git@bitbucket.org:someuser/some-project-that-i-have-access-to.git"
输出为:
Permission denied (publickey).
==> abox: fatal: Could not read from remote repository.
==> abox:
==> abox: Please make sure you have the correct access rights
==> abox: and the repository exists.
Error: Error while executing git clone -q git@bitbucket.org:someuser/some-project-that-i-have-access-to.git localclone
但是,当我 vagrant ssh
进入框中,然后手动调用相同的 git clone 命令时 - 一切正常.我还测试了 ansible 配置,但问题完全相同.
However when I vagrant ssh
into the box and then call the same git clone command maually - everything works. i also tested ansible config but the problem was exactly the same.
这里出了什么问题?
推荐答案
shell 配置将在来宾机器的上下文中运行(请参阅 文档).
The shell provisioning will run within the context of the guest machine (see docs).
因此,您只需要将 setup_project
更改为(您可能还想使用 ssh-keygen
在克隆之前这样你就不会在 中得到重复的记录~/.ssh/known_hosts
):
Therefore you should just need to change setup_project
to be (you may also want to remove key using ssh-keygen
prior to cloning so you don't end up with duplicate records in ~/.ssh/known_hosts
):
ssh-keygen -R bitbucket.org
ssh-keyscan bitbucket.org >> /home/vagrant/.ssh/known_hosts
ssh-keygen -R github.com
ssh-keyscan github.com >> /home/vagrant/.ssh/known_hosts
echo 'Clone bitbucket repo'
cd /vagrant
git clone git@bitbucket.org:someuser/some-project-that-i-have-access-to.git
这篇关于Vagrant shell 和 ansible 配置因 bitbucket 而失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!