配方在crete_if_missing上失败

时间:2014-12-04 19:51:47

标签: ruby vagrant chef

我正在学习本教程:http://www.gotealeaf.com/blog/chef-basics-for-rails-developers,他们让我们制作自己的食谱。下面的代码是配方。问题在于以cookbook_file" id_rsa"开头的代码块。并在结束之前结束,#添加Github作为已知主机,评论。我能够通过cookbook_file" id_rsa"块和cookbook_file" id_rsa.pub"通过将我的id_rsa和id_rsa.pub文件移动到rails-stack / files / default /目录中来阻止,但现在它在尝试sudo_without_password块时会中断。令人惊讶的是,如果我在操作抛出的每个错误之后设置vagrant:create_if_missing阻止配置获取到cookbooks_file"授权密钥"阻止,但它被困在那里;即使在配置完成后我第一次收到错误。关于发生了什么的任何想法?请尽量描述,我对devops相对较新,只知道一些流浪汉和厨师的来龙去脉。提前致谢!

execute "apt-get update" do
  command "apt-get update"
end

# OS Dendencies
%w(git ruby-dev build-essential libsqlite3-dev libssl-dev).each do |pkg|
  package pkg
end

# Deployer user, sudoer and with known RSA keys
user_account 'deployer' do
  create_group true
end
group "sudo" do
  action :modify
  members "deployer"
  append true
end
cookbook_file "id_rsa" do
  source "id_rsa"
  path "/home/deployer/.ssh/id_rsa"
  group "deployer"
  owner "deployer"
  mode 0600
  action :create_if_missing
end
cookbook_file "id_rsa.pub" do
  source "id_rsa.pub"
  path "/home/deployer/.ssh/id_rsa.pub"
  group "deployer"
  owner "deployer"
  mode 0644
  action :create_if_missing
end

# Allow sudo command without password for sudoers
cookbook_file "sudo_without_password" do
  source "sudo_without_password"
  path "/etc/sudoers.d/sudo_without_password"
  group "root"
  owner "root"
  mode 0440
  action :create_if_missing
end

# Authorize yourself to connect to server
cookbook_file "authorized_keys" do
  source "authorized_keys"
  path "/home/deployer/.ssh/authorized_keys"
  group "deployer"
  owner "deployer"
  mode 0600
  action :create
end

# Add Github as known host
ssh_known_hosts_entry 'github.com'

# Install Ruby Version
include_recipe 'ruby_build'

ruby_build_ruby '2.1.2'

link "/usr/bin/ruby" do
  to "/usr/local/ruby/2.1.2/bin/ruby"
end

gem_package 'bundler' do
  options '--no-ri --no-rdoc'
end

# Install Rails Application
include_recipe "runit"
application 'capistrano-first-steps' do
  owner 'deployer'
  group 'deployer'
  path '/var/www/capistrano-first-steps'
  repository 'git@github.com:gotealeaf/capistrano-first-steps.git'
  rails do
    bundler true
    database do
      adapter "sqlite3"
      database "db/production.sqlite3"
    end
  end
  unicorn do
    worker_processes 2
  end
end

**** ******* EDIT

自从第一次提出问题以来,我已经注释掉了sudo_without_password块,并且能够通过添加

来找到解决方法
ssh_keygen true

到user_account'部署者'块。

我还在rails-stack / files / default /中放置了一个空的authorized_keys文件,这有助于cookbook_file' authorized_keys'块运行没有错误。

现在,当vagrant / chef试图拉动示例回购时,我得到了这个错误

==> default: [2014-12-04T22:44:18+00:00] ERROR: deploy_revision[capistrano-first-steps] (/tmp/vagrant-chef-3/chef-solo-2/cookbooks/application/providers/default.rb line 123) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '128'
==> default: ---- Begin output of git ls-remote "git@github.com:gotealeaf/capistrano-first-steps.git" "HEAD" ----
==> default: STDOUT: 
==> default: STDERR: Warning: Permanently added the RSA host key for IP address '192.30.252.129' to the list of known hosts.
==> default: Permission denied (publickey).
==> default: fatal: Could not read from remote repository.
==> default: 
==> default: Please make sure you have the correct access rights
==> default: and the repository exists.
==> default: ---- End output of git ls-remote "git@github.com:gotealeaf/capistrano-first-steps.git" "HEAD" ----
==> default: Ran git ls-remote "git@github.com:gotealeaf/capistrano-first-steps.git" "HEAD" returned 128
==> default: [2014-12-04T22:44:18+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

2 个答案:

答案 0 :(得分:1)

答案很简单,我记得我和木偶有类似的问题。出于某种原因,不确定为什么使用

git@github.com:gotealeaf/capistrano-first-steps.git

不适合流浪汉/厨师/傀儡。所以,我所做的就是将上面一行改为

https://github.com/gotealeaf/capistrano-first-steps

并且这样做了,我的盒子配置工作,没有问题!

答案 1 :(得分:0)

您可能必须将application资源指向将用于克隆存储库的私钥。

application 'capistrano-first-steps' do
  ...
  deploy_key lazy { File.read("/home/deployer/.ssh/id_rsa") }
  ...
end

更多信息 - https://supermarket.chef.io/cookbooks/application