简体   繁体   English

厨师,无业游民和私人git克隆

[英]Chef, Vagrant and private git cloning

i have acces to git repo on host, and i have a Vagrantfile: 我在主机上具有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

if i run vagrant and ssh into it, i could also git clone my private repo, (recipe "install_pkgs" is to install git on vm) but the pecipe "git_sync" gets an error like: 如果我运行vagrant并对其进行ssh,我也可以git clone我的私有仓库,(配方“ 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.

Here is my git_sync.rb recipe 这是我的git_sync.rb食谱

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

I'm new to chef and vagrant and it would be great to have some very comprehensive examples of how to clone private repo using chef. 我是厨师和流浪者的新手,非常高兴有一些非常全面的示例,介绍如何使用厨师克隆私人仓库。

Problem solved with this post https://stackoverflow.com/a/8191279/3564452 But can someone, please, discribe what's going on in this recipe and how this fixes my problem. 这篇文章解决了问题https://stackoverflow.com/a/8191279/3564452但是有人可以请描述一下此食谱中的内容以及如何解决我的问题。

(I'm no chef expert, but I have a similar setup working with Salt...) (我不是厨师专家,但我在Salt上使用类似的设置...)

The issue is that when you log on, you set up the ssh known_host as the user "vagrant", and the SSH_AUTH_SOCK variable is set for that user too. 问题是登录时,将SSH_AUTH_SOCK设置为用户“ vagrant”,并且也为该用户设置了SSH_AUTH_SOCK变量。 When you run your Chef recipes in the provisioner, they run as root. 当您在预配器中运行Chef食谱时,它们将以root身份运行。 So, you need to add your host to the /root/.ssh/known_hosts and also you need to edit /etc/sudoers to allow SSH_AUTH_SOCK to be passed through, something like so, although you'll obviously need to port my salt-call line to Chef. 因此,您需要将主机添加到/root/.ssh/known_hosts,还需要编辑/ etc / sudoers以允许通过SSH_AUTH_SOCK,尽管如此,尽管您显然需要移植我的salt-call给厨师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

With the error string Host key verification failed. 带有错误字符串的Host key verification failed. to me it sounds like one of three things: 对我来说,这听起来像三件事之一:

  1. you didn't add your SSH keys to your BitBucket repository 您没有将SSH密钥添加到BitBucket存储库
  2. the SSH key on your node is formatted incorrectly (a trailing space or newline for instance) 节点上的SSH密钥格式不正确(例如尾随空格或换行符)
  3. you didn't ssh-add your SSH key on your node 您没有在节点上ssh-add SSH密钥

In regards to the HOSTS issue, you can use the ssh_known_hosts cookbook resource to add the git@bitbucket.org address prior to using the git resource. 关于HOSTS问题,可以在使用git资源之前使用ssh_known_hosts食谱资源添加git@bitbucket.org地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM