Class: Vagrant::Provisioners::ChefSolo

Inherits:
Chef
  • Object
show all
Defined in:
lib/vagrant/provisioners/chef_solo.rb

Overview

This class implements provisioning via chef-solo.

Instance Method Summary collapse

Methods inherited from Chef

#chown_provisioning_folder, #setup_json

Methods included from Util

#error_and_exit, included, #logger, #wrap_output

Instance Method Details

#cookbook_path(i) ⇒ Object



50
51
52
# File 'lib/vagrant/provisioners/chef_solo.rb', line 50

def cookbook_path(i)
  File.join(Vagrant.config.chef.provisioning_path, "cookbooks-#{i}")
end

#cookbooks_pathObject



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/vagrant/provisioners/chef_solo.rb', line 54

def cookbooks_path
  result = []
  host_cookbook_paths.each_with_index do |host_path, i|
    result << cookbook_path(i)
  end

  # We're lucky that ruby's string and array syntax for strings is the
  # same as JSON, so we can just convert to JSON here and use that
  result = result.to_s if result.length == 1
  result.to_json
end

#host_cookbook_pathsObject



43
44
45
46
47
48
# File 'lib/vagrant/provisioners/chef_solo.rb', line 43

def host_cookbook_paths
  cookbooks = Vagrant.config.chef.cookbooks_path
  cookbooks = [cookbooks] unless cookbooks.is_a?(Array)
  cookbooks.collect! { |cookbook| File.expand_path(cookbook, Env.root_path) }
  return cookbooks
end

#prepareObject



5
6
7
# File 'lib/vagrant/provisioners/chef_solo.rb', line 5

def prepare
  share_cookbook_folders
end

#provision!Object



9
10
11
12
13
14
# File 'lib/vagrant/provisioners/chef_solo.rb', line 9

def provision!
  chown_provisioning_folder
  setup_json
  setup_solo_config
  run_chef_solo
end

#run_chef_soloObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/vagrant/provisioners/chef_solo.rb', line 32

def run_chef_solo
  logger.info "Running chef-solo..."
  SSH.execute do |ssh|
    ssh.exec!("cd #{Vagrant.config.chef.provisioning_path} && sudo chef-solo -c solo.rb -j dna.json") do |channel, data, stream|
      # TODO: Very verbose. It would be easier to save the data and only show it during
      # an error, or when verbosity level is set high
      logger.info("#{stream}: #{data}")
    end
  end
end

#setup_solo_configObject



22
23
24
25
26
27
28
29
30
# File 'lib/vagrant/provisioners/chef_solo.rb', line 22

def setup_solo_config
  solo_file = <<-solo
file_cache_path "#{Vagrant.config.chef.provisioning_path}"
cookbook_path #{cookbooks_path}
solo

  logger.info "Uploading chef-solo configuration script..."
  SSH.upload!(StringIO.new(solo_file), File.join(Vagrant.config.chef.provisioning_path, "solo.rb"))
end

#share_cookbook_foldersObject



16
17
18
19
20
# File 'lib/vagrant/provisioners/chef_solo.rb', line 16

def share_cookbook_folders
  host_cookbook_paths.each_with_index do |cookbook, i|
    Vagrant.config.vm.share_folder("vagrant-chef-solo-#{i}", cookbook_path(i), cookbook)
  end
end