Class: Vagrant::Provisioners::Chef

Inherits:
Base
  • Object
show all
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

ChefServer, ChefSolo

Defined Under Namespace

Classes: ChefError, Config

Instance Attribute Summary

Attributes inherited from Base

#action_env, #config

Instance Method Summary collapse

Methods inherited from Base

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

Constructor Details

This class inherits a constructor from Vagrant::Provisioners::Base

Instance Method Details

#chown_provisioning_folderObject



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

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:



7
8
9
# File 'lib/vagrant/provisioners/chef.rb', line 7

def prepare
  raise ChefError, :invalid_provisioner
end

#setup_config(template, filename, template_vars) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/vagrant/provisioners/chef.rb', line 26

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



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

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.json)

  json = data.to_json

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

#verify_binary(binary) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/vagrant/provisioners/chef.rb', line 11

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