Class: Vagrant::Provisioners::Chef

Inherits:
Base
  • Object
show all
Includes:
Util::Counter
Defined in:
lib/vagrant/provisioners/chef.rb,
lib/vagrant/provisioners/chef.rb,
lib/vagrant/provisioners/chef.rb

Overview

This class is a base class where the common functionality shared between chef-solo and chef-client provisioning are stored. This is not an actual provisioner. Instead, ChefSolo or ChefServer should be used.

Direct Known Subclasses

ChefClient, ChefSolo

Defined Under Namespace

Classes: ChefError, Config

Instance Attribute Summary

Attributes inherited from Base

#action_env, #config

Instance Method Summary collapse

Methods included from Util::Counter

#get_and_update_counter, #mutex

Methods inherited from Base

#cleanup, #env, #provision!, register, registered, #vm

Constructor Details

#initialize(env, config) ⇒ Chef

Returns a new instance of Chef.



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

def initialize(env, config)
  super

  config.provisioning_path ||= "/tmp/vagrant-chef-#{get_and_update_counter(:provisioning_path)}"
end

Instance Method Details

#chef_binary_path(binary) ⇒ Object

Returns the path to the Chef binary, taking into account the binary_path configuration option.



29
30
31
32
# File 'lib/vagrant/provisioners/chef.rb', line 29

def chef_binary_path(binary)
  return binary if !config.binary_path
  return File.join(config.binary_path, binary)
end

#chown_provisioning_folderObject



34
35
36
37
38
39
# File 'lib/vagrant/provisioners/chef.rb', line 34

def chown_provisioning_folder
  vm.ssh.execute do |ssh|
    ssh.sudo!("mkdir -p #{config.provisioning_path}")
    ssh.sudo!("chown #{env.config.ssh.username} #{config.provisioning_path}")
  end
end

#prepareObject

Raises:



15
16
17
# File 'lib/vagrant/provisioners/chef.rb', line 15

def prepare
  raise ChefError, :invalid_provisioner
end

#setup_config(template, filename, template_vars) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/vagrant/provisioners/chef.rb', line 41

def setup_config(template, filename, template_vars)
  config_file = TemplateRenderer.render(template, {
    :log_level => config.log_level.to_sym,
    :http_proxy => config.http_proxy,
    :http_proxy_user => config.http_proxy_user,
    :http_proxy_pass => config.http_proxy_pass,
    :https_proxy => config.https_proxy,
    :https_proxy_user => config.https_proxy_user,
    :https_proxy_pass => config.https_proxy_pass,
    :no_proxy => config.no_proxy
  }.merge(template_vars))

  vm.ssh.upload!(StringIO.new(config_file), File.join(config.provisioning_path, filename))
end

#setup_jsonObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/vagrant/provisioners/chef.rb', line 56

def setup_json
  env.ui.info I18n.t("vagrant.provisioners.chef.json")

  # Set up initial configuration
  data = {
    :config => env.config.to_hash,
    :directory => env.config.vm.shared_folders["v-root"][:guestpath],
  }

  # And wrap it under the "vagrant" namespace
  data = { :vagrant => data }

  # Merge with the "extra data" which isn't put under the
  # vagrant namespace by default
  data.merge!(config.merged_json)

  json = data.to_json

  vm.ssh.upload!(StringIO.new(json), File.join(config.provisioning_path, "dna.json"))
end

#verify_binary(binary) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/vagrant/provisioners/chef.rb', line 19

def verify_binary(binary)
  vm.ssh.execute do |ssh|
    # Checks for the existence of chef binary and error if it
    # doesn't exist.
    ssh.sudo!("which #{binary}", :error_class => ChefError, :_key => :chef_not_detected, :binary => binary)
  end
end