我有一个使用厨师帮助安装东西的流浪文件:
Vagrant.configure(2) do |config|
config.vm.box = 'opscode-ubuntu-12.04_chef-11.4.0'
config.vm.box_url = 'https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_chef-11.4.0.box'
config.vm.network :forwarded_port, guest: 3000, host: 3000
config.vm.provider(:virtualbox) do |vb|
vb.customize [
"modifyvm", :id,
"--memory", "1024",
"--cpus", "4"
]
end
config.vm.provision :shell, inline: %Q{
sudo apt-get install -y postgresql-client
}
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = ["cookbooks"]
chef.add_recipe :apt
chef.add_recipe 'postgresql::server'
chef.add_recipe 'build-essential'
chef.add_recipe 'rvm::vagrant'
chef.add_recipe 'rvm::system'
chef.add_recipe 'git'
chef.json = {
:postgresql => {
:version => '9.3'
},
"postgresql" => {
"password" => {
"postgres" => "kshgfi3ret3hihjfbkivtbo3ity835"
}
},
"database" => {
"create" => ["aisisplatform"]
},
:git => {
:prefix => "/usr/local"
},
:rvm => {
'rubies' => [ 'ruby-2.1.0' ],
'default_ruby' => 'ruby-2.1.0',
'vagrant' => {
:system_chef_solo => '/usr/bin/chef-solo'
}
},
}
end
end
这有一些问题:
在vagrant up
启动时,我收到如下警告:
/tmp/vagrant-chef-1/chef-solo-1/cookbooks/rvm/libraries/rvm_chef_user_environment.rb:32: warning: class variable access from toplevel
下一个问题是事情无法正常工作,有些时候vm看到PostgreSQL,通过psql
命令,有时它不知道它是什么,并声明它没有安装。当它看到它时,它声明psql: FATAL: role "vagrant" does not exist
最后一个问题是,当vm启动时,常规和安全性的更新超过200次。我想通过vagrant up
在第一次设置vm时注意这个问题。我试过了:
config.vm.provision:shell,inline:%Q { sudo apt-get update sudo apt-get upgrade -y }
但是当脚本运行时,我会得到关于stdn
的错误的 TON ,依此类推。那么,我该怎么做才能解决这些问题呢?我的流浪档案有什么问题?
答案 0 :(得分:4)
我调整了vagrant文件以使用omnibus和berkshelf插件。前者将确保厨师达到所需的版本,后者将使烹饪书保持最新状态。
我还注意到“类变量访问”警告,其根本原因可能是埋在rvm食谱中。我没有看得更深,因为我的Vagrant跑步完成没有错误。
$ tree
.
├── Berksfile
└── Vagrantfile
site :opscode
cookbook "apt"
cookbook "postgresql"
cookbook "build-essential"
cookbook "rvm", :github => "fnichol/chef-rvm"
cookbook "git"
Vagrant.require_plugin "vagrant-omnibus"
Vagrant.require_plugin "vagrant-berkshelf"
Vagrant.configure(2) do |config|
# Box config
config.vm.box = 'precise64'
config.vm.box_url = 'http://files.vagrantup.com/precise64.box'
# Plugin config
config.omnibus.chef_version = :latest
config.berkshelf.enabled = true
# Network config
config.vm.network :forwarded_port, guest: 3000, host: 3000
# Virtual config
config.vm.provider(:virtualbox) do |vb|
vb.customize [
"modifyvm", :id,
"--memory", "1024",
"--cpus", "4"
]
end
# Provisioner config
config.vm.provision :chef_solo do |chef|
chef.add_recipe 'apt'
chef.add_recipe 'postgresql::client'
chef.add_recipe 'postgresql::server'
chef.add_recipe 'build-essential'
chef.add_recipe 'rvm::system'
chef.add_recipe 'git'
chef.json = {
:postgresql => {
:version => '9.3'
},
"postgresql" => {
"password" => {
"postgres" => "kshgfi3ret3hihjfbkivtbo3ity835"
}
},
"database" => {
"create" => ["aisisplatform"]
},
:git => {
:prefix => "/usr/local"
},
:rvm => {
'rubies' => [ 'ruby-2.1.0' ],
'default_ruby' => 'ruby-2.1.0',
'vagrant' => {
:system_chef_solo => '/usr/bin/chef-solo'
}
},
}
end
end
注意: