流浪汉和厨师零 - 缺少角色

时间:2015-07-28 09:48:40

标签: vagrant chef chef-zero

我很高兴使用Vagrant和Chef Solo,但我读到使用Chef Zero可以更轻松地过渡到完整的Chef Server(这可能会在项目的不久的将来发生)。当我开始使用vagrant plus chef-zero时,我在Chef运行期间收到错误,如下所述 流浪者:1.7.4
厨师(在客用机器上) - 12.4.1
当我做$ 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"
    ]

1 个答案:

答案 0 :(得分:3)

显然,厨师零只有JSON版本不支持rb角色定义。

Chef Zero Bug reported

那个是关闭的,但指的是其他仍然开放的。

我遇到了同样的问题,所以我的解决方案就是使用这个gist将我的角色转换为JSON,然后以流浪汉的方式使用它们。