Vagrant and Chef Zero - Missing Role

1.1k Views Asked by At

I was happily using Vagrant and Chef Solo, but I read that using Chef Zero will lead to an easier transition to the full Chef Server (something which might happen in the near future of the project). When I started using vagrant plus chef-zero, I get the error during the Chef run, described below.
Vagrant: 1.7.4
Chef(on the guest machine) - 12.4.1
And when I do a $ vagrant up db, this is the output from 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]

This is the relevant bit of my 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

When I log in to the virtual machine(db) and go to /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"

And this is the content of /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

There are 1 best solutions below

1
On BEST ANSWER

Apparently rb role definitions are not supported in chef zero only JSON ones.

Chef Zero Bug reported

That one is closed but refers to other that is still open.

I have the same problem, so my solution it's going to be to use this gist to translate my roles to JSON and use them that way with vagrant.