1

我很高兴使用 Vagrant 和 Chef Solo,但我读到使用 Chef Zero 会更容易过渡到完整的 Chef Server(这可能会在项目的不久的将来发生)。当我开始使用 vagrant plus chef-zero 时,我在 Chef 运行期间收到错误,如下所述。
Vagrant: 1.7.4
Chef(在客户机上) - 12.4.1
当我做 a 时$ vagrant up db,这是 Chef 的输出

==> db: [2015-07-28T09:14:13+00:00] INFO: Chef-client pid: 2525
==> db: [2015-07-28T09:14:14+00:00] INFO: HTTP Request Returned 404 Not Found: Object not found: chefzero://localhost:8889/nodes/db-machine
==> db: [2015-07-28T09:14:14+00:00] INFO: Setting the run_list to ["role[mysql]"] from CLI options
==> db: [2015-07-28T09:14:14+00:00] INFO: HTTP Request Returned 404 Not Found: Object not found: chefzero://localhost:8889/roles/mysql
==> db: [2015-07-28T09:14:14+00:00] ERROR: Role mysql (included by 'top        level') is in the runlist but does not exist. Skipping expand. 
==> db: Error expanding the run_list:
==> db: 
==> db: 
==> db: Missing Role(s) in Run List:
==> db: ----------------------------
==> db: * mysql included by 'top level'
==> db:
==> db: Original Run List
==> db: -----------------
==> db: * role[mysql]

这是我的 Vagrantfile 的相关位

machine.vm.provision "chef_zero" do |chef| 
    chef.node_name = @hostname
    chef.cookbooks_path = "#{@chef_repo}/cookbooks"
    chef.roles_path = "#{@chef_repo}/roles"
    chef.environments_path = "#{@chef_repo}/environments"
    chef.environment = @environment
    roles.each do |role|
        chef.add_role role
    end
    chef.json = {
        "guest_folder_path" => guest_path,
        "ubuntu_user" => @ubuntu_user
    }
end

当我登录到虚拟机(db)并转到/tmp/chef-vagrant

   $ cd /tmp/vagrant-chef/
    vagrant@db-machine:/tmp/vagrant-chef$ ls
    2107f3d10c0db9887cdf980054c11e35/  client.rb                          dna.json
    8a1f8968cff1cd79d46fc9ca5bd46931/  df5881620e1c72537e51bddcbc6ceb3a/
    vagrant@db-machine:/tmp/vagrant-chef$ cat client.rb 
    node_name "db-machine"
    file_cache_path    "/var/chef/cache"
    file_backup_path   "/var/chef/backup"
    cookbook_path ["/tmp/vagrant-chef/df5881620e1c72537e51bddcbc6ceb3a/cookbooks"]
    role_path "/tmp/vagrant-chef/2107f3d10c0db9887cdf980054c11e35/roles"
    log_level :info
    verbose_logging false
    enable_reporting false
    encrypted_data_bag_secret nil
    environment_path "/tmp/vagrant-chef/8a1f8968cff1cd79d46fc9ca5bd46931/environments"
    environment "develop"
    chef_zero.enabled true
    local_mode true
    add_formatter "null"

这是 /roles 的内容

vagrant@db-machine:/tmp/vagrant-chef/2107f3d10c0db9887cdf980054c11e35/roles$ ls
mysql.rb
vagrant@db-machine:/tmp/vagrant-chef/2107f3d10c0db9887cdf980054c11e35/roles$ cat mysql.rb 
name "mysql"
description "Role for a machine with a mysql db on it"
run_list "recipe[db]"
env_run_lists "_default"=>[],
"production" => ["recipe[git_deploy]", "recipe[db::aws]", "recipe[db]"],
"staging" =>["recipe[git_deploy]", "recipe[db::aws]", "recipe[db]"],
"develop" => ["recipe[db]"]


default_attributes "mysql_bind_address" =>"0.0.0.0", 
    "mysql_db_name"=> "some_db_name", 
    "mysql_password"=> "root",
    "mysql_datadir" => "/var/lib/mysql",
    "db_name" => "some_db_name",
    "db_init_runlist" => [
                "some_file.sql", 
                "some_other_file.sql"
    ]
4

1 回答 1

3

显然,厨师零仅 JSON 不支持 rb 角色定义。

厨师零错误报告

那个是封闭的,但指的是另一个仍然开放的。

我有同样的问题,所以我的解决方案是使用这个gist将我的角色转换为 JSON,然后将它们与 vagrant 一起使用。

于 2015-09-18T10:03:14.397 回答