我是Chef的新手,我正在尝试使用Digital Ocean作为提供者和Chef作为供应者来设置Vagrant Box。问题似乎与角色有关,但据我所知,它们匹配得很好。感谢。
这是我的Vagrantfile:
Vagrant.configure('2') do |config|
config.omnibus.chef_version = :latest
config.vm.provider :digital_ocean do |provider, override|
config.vm.hostname = 'majestic-chaos-ubuntu14.04x64'
override.ssh.private_key_path = '~/.ssh/id_rsa'
override.vm.box = 'digital_ocean'
provider.token = 'XXXXXXXXXXXX'
provider.image = 'Ubuntu 14.04 x64'
provider.region = 'nyc2'
provider.size = '512mb'
end
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = ['../../cookbooks']
chef.roles_path = ['../../roles']
chef.add_role ("majestic-chaos-ubuntu14.04x64")
end
end
和我的角色档案:
name "majestic-chaos-ubuntu-14.04x64"
ssl_verify_mode :verify_peer
run_list(
"recipe[apt]",
"recipe[open-ssl]",
"recipe[build-essential]",
"recipe[chef-ruby_build]",
"recipe[nodejs-cookbook]",
"recipe[rbenv::user]",
"recipe[rbenv::vagrant]",
"recipe[zsh]",
"recipe[vim]",
"recipe[imagemagick]",
)
override_attributes(
rbenv: {
user_installs: [{
user: 'vagrant',
rubies: ["2.1.2"],
global: "2.1.2",
gems: {
"2.1.2" => [
{ name: "bundler" }
]
}
}]
}
)
这就是我得到的错误:
[2014-09-18T16:05:48-04:00] INFO: *** Chef 11.16.2 ***
[2014-09-18T16:05:48-04:00] INFO: Chef-client pid: 2934
[2014-09-18T16:05:51-04:00] INFO: Setting the run_list to ["role[majestic-chaos-
ubuntu14.04x64]"] from CLI options
default: [2014-09-18T16:05:51-04:00] ERROR: Role majestic-chaos-ubuntu14.04x64 (included
by 'top level') is in the runlist but does not exist. Skipping expand.
[2014-09-18T16:05:51-04:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-
stacktrace.out
[2014-09-18T16:05:51-04:00] ERROR: The expanded run list includes nonexistent roles:
majestic-chaos-ubuntu14.04x64
[2014-09-18T16:05:51-04:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process
exited unsuccessfully (exit code 1)
答案 0 :(得分:0)
在启动Vagrant映像时,我遇到了类似的问题,其中没有获取角色文件。我找到的解决方案是,对于kitchen.yml
文件,角色文件应该是JSON格式。 (上面列出的角色文件看起来不像JSON)。
如此处所述:https://docs.chef.io/config_yml_kitchen.html
roles_path
角色数据所在目录的相对路径。 此数据必须定义为JSON。
以下是一些将您的.rb
转换为JSON
require 'chef'
role = Chef::Role.new
role.from_file("./roles/useful_api_role.rb")
puts JSON.pretty_generate(role)
作为一个副作用,上面的代码将加载一个rb配置,你可以验证它是否产生了你期望的角色变量。
答案 1 :(得分:-2)
尝试使用角色和烹饪书的绝对路径:
chef.cookbooks_path = File.expand_path('../../cookbooks', __FILE__)
chef.roles_path = File.expand_path('../../roles', __FILE__)