厨师,流浪汉和私人git克隆

时间:2015-05-08 18:45:03

标签: ruby git vagrant chef host

我可以访问主机上的git repo,我有一个Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "ubuntu14.04"
  config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-    vagrant-disk1.box"
  config.vm.provider "virtualbox" do |vb|
    vb.memory = 1024
    vb.cpus = 2
  end
  config.ssh.forward_agent = true
  config.vm.provision :chef_solo do |chef|
  # chef.log_level = :debug
    chef.cookbooks_path = "./cookbooks"
    chef.add_recipe "git_sync"
  end
end

如果我运行vagrant和ssh,我也可以克隆我的私人仓库,(食谱" install_pkgs"是在vm上安装git)但是pecipe" git_sync"得到如下错误:

[2015-05-08T18:40:26+00:00] ERROR: Running exception handlers
[2015-05-08T18:40:26+00:00] ERROR: Exception handlers complete
[2015-05-08T18:40:26+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2015-05-08T18:40:26+00:00] ERROR: git[/home/vagrant/geomongo] (git_sync::default line 1) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '128'
---- Begin output of git ls-remote "git@bitbucket.org:galiaf95/test.git" HEAD ----
STDOUT: 
STDERR: Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
---- End output of git ls-remote "git@bitbucket.org:galiaf95/test.git" HEAD ----
Ran git ls-remote "git@bitbucket.org:galiaf95/test.git" HEAD returned 128

================================================================================
Error executing action `sync` on resource 'git[/home/vagrant/geomongo]'
================================================================================


Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '128'
---- Begin output of git ls-remote "git@bitbucket.org:galiaf95/test.git" HEAD ----
STDOUT: 
STDERR: Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
---- End output of git ls-remote "git@bitbucket.org:galiaf95/test.git" HEAD ----
Ran git ls-remote "git@bitbucket.org:galiaf95/test.git" HEAD returned 128


Resource Declaration:
---------------------
# In /tmp/vagrant-chef-1/chef-solo-1/cookbooks/git_sync/recipes/default.rb

  1: git "/home/vagrant/geomongo" do
  2:   # repository "git@bitbucket.org:osll/geomongo.git"  
  3:   # repository "https://github.com/galiaf95/test.git"
  4:   repository "git@bitbucket.org:galiaf95/test.git"
  5:   action :sync
  6: end


Compiled Resource:
------------------
# Declared in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/git_sync/recipes/default.rb:1:in `from_file'

git("/home/vagrant/geomongo") do
  provider Chef::Provider::Git
  action [:sync]
  retries 0
  retry_delay 2
  destination "/home/vagrant/geomongo"
  revision "HEAD"
  remote "origin"
  cookbook_name :git_sync
  recipe_name "default"
  repository "git@bitbucket.org:galiaf95/test.git"
end



[2015-05-08T18:38:31+00:00] INFO: Forking chef instance to converge...
[2015-05-08T18:40:26+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.

这是我的git_sync.rb食谱

git "/home/vagrant/geomongo" do"
  repository "git@bitbucket.org:galiaf95/test.git"
  action :sync
end

我是厨师和流浪汉的新手,如果有一些非常全面的例子说明如何使用厨师克隆私人仓库将会很棒。

这篇文章解决了问题https://stackoverflow.com/a/8191279/3564452但是,有人可以请说明这个食谱中发生了什么以及如何解决我的问题。

2 个答案:

答案 0 :(得分:0)

(我没有厨师专家,但我有类似的设置与Salt合作......)

问题是,当您登录时,您将ssh known_host设置为用户" vagrant",并且也为该用户设置了SSH_AUTH_SOCK变量。在配置程序中运行Chef配方时,它们以root身份运行。因此,您需要将主机添加到/root/.ssh/known_hosts,并且还需要编辑/ etc / sudoers以允许SSH_AUTH_SOCK通过,类似于此,尽管您显然需要移植我的salt-call致主厨。

config.vm.provision "setup-and-highstate", type: "shell" do |s|
    s.inline = <<SCRIPT
    grep -s SSH_AUTH_SOCK /etc/sudoers || echo 'Defaults        env_keep="SSH_AUTH_SOCK"' | (EDITOR="tee -a" visudo)
    ln -s /var/cache/salt/minion/extmods/outputters/ /var/cache/salt/minion/extmods/output
    salt-call --local 'ssh.set_known_host' 'root' enc='ecdsa' fingerprint='ff:ff:ff:23:b4:20:93:d1:2e:91:ff:3c:a8:ff' hostname='git.xxxx.yyyy.com'
SCRIPT
end

答案 1 :(得分:0)

对我来说错误字符串Host key verification failed.听起来像是三件事之一:

  1. 您没有将SSH密钥添加到BitBucket存储库
  2. 节点上的SSH密钥格式不正确(例如尾随空格或换行符)
  3. 您在节点上没有ssh-add您的SSH密钥
  4. 关于HOSTS问题,您可以在使用git@bitbucket.org资源之前使用ssh_known_hosts cookbook资源添加git地址。