lib/vagrant/provisioners/chef.rb in vagrantup-0.2.0 vs lib/vagrant/provisioners/chef.rb in vagrantup-0.3.0

- old
+ new

@@ -9,24 +9,30 @@ # Chef server specific config attr_accessor :chef_server_url attr_accessor :validation_key_path attr_accessor :validation_client_name attr_accessor :client_key_path + attr_accessor :node_name # Chef solo specific config attr_accessor :cookbooks_path + attr_accessor :roles_path # Shared config attr_accessor :provisioning_path + attr_accessor :log_level attr_accessor :json def initialize @validation_client_name = "chef-validator" @client_key_path = "/etc/chef/client.pem" + @node_name = "client" @cookbooks_path = "cookbooks" + @roles_path = [] @provisioning_path = "/tmp/vagrant-chef" + @log_level = :info @json = { :instance_role => "vagrant", :run_list => ["recipe[vagrant_main]"] } end @@ -64,39 +70,48 @@ # Tell the Vagrant configure class about our custom configuration Config.configures :chef, ChefConfig def prepare - raise Actions::ActionException.new("Vagrant::Provisioners::Chef is not a valid provisioner! Use ChefSolo or ChefServer instead.") + raise Actions::ActionException.new(:chef_base_invalid_provisioner) end def chown_provisioning_folder logger.info "Setting permissions on chef provisioning folder..." - SSH.execute do |ssh| - ssh.exec!("sudo mkdir -p #{Vagrant.config.chef.provisioning_path}") - ssh.exec!("sudo chown #{Vagrant.config.ssh.username} #{Vagrant.config.chef.provisioning_path}") + env.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..." + env.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 => Vagrant.config, - :directory => Vagrant.config.vm.project_directory, + :config => env.config, + :directory => env.config.vm.project_directory, } # 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!(Vagrant.config.chef.json) + data.merge!(env.config.chef.json) json = data.to_json - SSH.upload!(StringIO.new(json), File.join(Vagrant.config.chef.provisioning_path, "dna.json")) + env.ssh.upload!(StringIO.new(json), File.join(env.config.chef.provisioning_path, "dna.json")) end end end -end \ No newline at end of file +end