Vagrant/Chef-Solo (or Chef-Zero) using nodes/hostname.json

25 views
Skip to first unread message

Joaquin Menchaca

unread,
Jun 24, 2015, 3:18:22 PM6/24/15
to vagra...@googlegroups.com
I was wondering how to get this configured.  I essentially would like to use a set of recipes and variables based on the host name. 

I am familiar with

knife solo cook HOSTNAME

And I would hope that a vagrant provision could use the nodes/hostname.json that can contain the "run_list" [ ... ]. I have been adding recipes in my Vagrantfile with chef.add_recipe as a workaround, but I would like it work through a vagrant provision

Ideas?

Joaquin Menchaca

unread,
Jul 2, 2015, 3:11:32 PM7/2/15
to vagra...@googlegroups.com
SOLUTION: A lot of other people were asking this, and fortunately there's a known solution out there:

In your Vagrantfile, you'd have something like this:

  config.vm.hostname = "name_of_some_server.dev"
  VAGRANT_JSON = JSON.parse(Pathname(__FILE__).dirname.join('../../nodes', "#{config.vm.hostname}.json").read)


and later

  config.vm.provision :chef_solo do |chef|
    # Remove, Extract, Add Runlist
    chef.run_list = VAGRANT_JSON.delete('run_list') if VAGRANT_JSON['run_list']
    # Add JSON Attributes
    chef.json = VAGRANT_JSON
  end
Reply all
Reply to author
Forward
0 new messages