Vagrant File Chef Attributes

Go To StackoverFlow.com

16

I am trying to configure my Vagrant file to have some chef attributes, but I must be doing something wrong because the chef recipes are using the defaults instead of my the attributes I am trying to set. Here is my config section of my vagrant file:

config.vm.provision :chef_solo do |chef|
    chef.json = {
      :mysql => {
        :server_root_password => 'password'
      },
      :nodejs => {
        :version => '0.6.14',
        :dir => '/usr/local',
        :npm => '1.1.13'
      }
    }
    chef.cookbooks_path = "config/env/cookbooks"
    chef.add_recipe "apt"
    chef.add_recipe "mongodb::10gen_repo"
    chef.add_recipe "mongodb"
    chef.add_recipe "mysql::client"
    chef.add_recipe "mysql::server"
    chef.add_recipe "nodejs"
    chef.add_recipe "nodejs::npm"
    #chef.add_recipe "mymc_service"

end

Is my Ruby wrong or is there a better way to do this?

2012-04-04 17:42
by Clint


21

I'm brand new to Vagrant, Ruby, and Chef, but this is what worked for me:

config.vm.provision :chef_solo do |chef|
    chef.json = {
        "mysql" => {
            "server_root_password" => "password"
        }
    }
    chef.add_recipe "mysql" # etc
end
2012-05-11 15:40
by Mike Branski
Mike, you are the man! Some examples had the colon in front of the variable names, and I am not sure why. Thanks for the solution - Clint 2012-05-11 16:23
the colon in front of variable name is ruby syntax for a key - jmontross 2013-05-14 17:45
@Clint the :something is a Symbol literal in Ruby, whereas a "something" is a String. They are two distinct types. Chef (at least the in client-server mode) does treats both Symbols and Strings when used as hash keys the same way, so they can be used interchangeably. If you want to read more about the difference between Strings and Symbols go here - Maciej Biłas 2014-03-06 12:43


3

I recently ran into this same issue. While Mike's answer did not solve my problem, possibly due to the newer Vagrant/Chef versions, it pointed me in the right direction. The following is what i had to do for MySQL server to work:

config.vm.provision :chef_solo do |chef|
    chef.json = {
        :mysql => {
            :server_root_password => "password",
            :server_repl_password => "password",
            :server_debian_password => "password"
        }
    }
    chef.add_recipe "mysql::server"
end
2012-12-13 18:29
by beaudierman
Worked for me! Thanks - Cory Walker 2013-05-31 18:46
Ads