lib/vagrant/provisioners/chef.rb in vagrantup-0.5.4 vs lib/vagrant/provisioners/chef.rb in vagrantup-0.6.0
- old
+ new
@@ -2,12 +2,70 @@
module Provisioners
# This class is a base class where the common functinality shared between
# chef-solo and chef-client provisioning are stored. This is **not an actual
# provisioner**. Instead, {ChefSolo} or {ChefServer} should be used.
class Chef < Base
+ def prepare
+ raise ChefError.new(:invalid_provisioner)
+ end
+
+ def verify_binary(binary)
+ vm.ssh.execute do |ssh|
+ # Checks for the existence of chef binary and error if it
+ # doesn't exist.
+ ssh.exec!("which #{binary}", :error_class => ChefError, :_key => :chef_not_detected, :binary => binary)
+ end
+ end
+
+ def chown_provisioning_folder
+ vm.ssh.execute do |ssh|
+ ssh.exec!("sudo mkdir -p #{env.config.chef.provisioning_path}")
+ ssh.exec!("sudo chown #{env.config.ssh.username} #{env.config.chef.provisioning_path}")
+ end
+ end
+
+ def setup_config(template, filename, template_vars)
+ config_file = TemplateRenderer.render(template, {
+ :log_level => env.config.chef.log_level.to_sym
+ }.merge(template_vars))
+
+ vm.ssh.upload!(StringIO.new(config_file), File.join(env.config.chef.provisioning_path, filename))
+ end
+
+ 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!(env.config.chef.json)
+
+ json = data.to_json
+
+ vm.ssh.upload!(StringIO.new(json), File.join(env.config.chef.provisioning_path, "dna.json"))
+ end
+ end
+
+ class Chef < Base
+ class ChefError < Errors::VagrantError
+ error_namespace("vagrant.provisioners.chef")
+ end
+ end
+
+ class Chef < Base
# This is the configuration which is available through `config.chef`
class ChefConfig < Vagrant::Config::Base
+ configures :chef
+
# Chef server specific config
attr_accessor :chef_server_url
attr_accessor :validation_key_path
attr_accessor :validation_client_name
attr_accessor :client_key_path
@@ -32,11 +90,11 @@
@roles_path = []
@provisioning_path = "/tmp/vagrant-chef"
@log_level = :info
@json = {
:instance_role => "vagrant",
- :run_list => ["recipe[vagrant_main]"]
+ :run_list => []
}
end
# Returns the run list for the provisioning
def run_list
@@ -58,69 +116,16 @@
def add_role(name)
name = "role[#{name}]" unless name =~ /^role\[(.+?)\]$/
run_list << name
end
- def to_json(*a)
+ def instance_variables_hash
# Overridden so that the 'json' key could be removed, since its just
# merged into the config anyways
- data = instance_variables_hash
- data.delete(:json)
- data.to_json(*a)
+ result = super
+ result.delete("json")
+ result
end
- end
-
- # Tell the Vagrant configure class about our custom configuration
- Config.configures :chef, ChefConfig
-
- def prepare
- action_env.error!(:chef_base_invalid_provisioner)
- end
-
- def verify_binary(binary)
- vm.ssh.execute do |ssh|
- # Checks for the existence of chef binary and error if it
- # doesn't exist.
- ssh.exec!("which #{binary}", :error_key => :chef_not_detected, :error_data => {:binary => binary})
- end
- end
-
- def chown_provisioning_folder
- logger.info "Setting permissions on chef provisioning folder..."
- vm.ssh.execute do |ssh|
- ssh.exec!("sudo mkdir -p #{env.config.chef.provisioning_path}")
- ssh.exec!("sudo chown #{env.config.ssh.username} #{env.config.chef.provisioning_path}")
- end
- end
-
- def setup_config(template, filename, template_vars)
- config_file = TemplateRenderer.render(template, {
- :log_level => env.config.chef.log_level.to_sym
- }.merge(template_vars))
-
- logger.info "Uploading chef configuration script..."
- vm.ssh.upload!(StringIO.new(config_file), File.join(env.config.chef.provisioning_path, filename))
- end
-
- def setup_json
- logger.info "Generating chef JSON and uploading..."
-
- # Set up initial configuration
- data = {
- :config => env.config,
- :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!(env.config.chef.json)
-
- json = data.to_json
-
- vm.ssh.upload!(StringIO.new(json), File.join(env.config.chef.provisioning_path, "dna.json"))
end
end
end
end