Convert chef provisioners to new format

This commit is contained in:
Mitchell Hashimoto 2011-12-14 23:19:46 -08:00
parent e5303a82e0
commit e602af8c3a
3 changed files with 26 additions and 24 deletions

View File

@ -17,10 +17,11 @@ module Vagrant
end
def verify_binary(binary)
vm.ssh.execute do |ssh|
env[: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)
ssh.sudo!("which #{binary}", :error_class => ChefError,
:_key => :chef_not_detected, :binary => binary)
end
end
@ -32,7 +33,7 @@ module Vagrant
end
def chown_provisioning_folder
vm.ssh.execute do |ssh|
env[:vm].ssh.execute do |ssh|
ssh.sudo!("mkdir -p #{config.provisioning_path}")
ssh.sudo!("chown #{env.config.ssh.username} #{config.provisioning_path}")
end
@ -50,17 +51,18 @@ module Vagrant
:no_proxy => config.no_proxy
}.merge(template_vars))
vm.ssh.upload!(StringIO.new(config_file), File.join(config.provisioning_path, filename))
env[:vm].ssh.upload!(StringIO.new(config_file),
File.join(config.provisioning_path, filename))
end
def setup_json
env.ui.info I18n.t("vagrant.provisioners.chef.json")
env[:ui].info I18n.t("vagrant.provisioners.chef.json")
# Set up our configuration that is passed to the attributes by default
data = { :config => env.config.to_hash }
data = { :config => env[:global_config].to_hash }
# Add our default share directory if it exists
default_share = env.config.vm.shared_folders["v-root"]
default_share = env[:vm].config.vm.shared_folders["v-root"]
data[:directory] = default_share[:guestpath] if default_share
# And wrap it under the "vagrant" namespace
@ -72,7 +74,7 @@ module Vagrant
json = data.to_json
vm.ssh.upload!(StringIO.new(json), File.join(config.provisioning_path, "dna.json"))
env[:vm].ssh.upload!(StringIO.new(json), File.join(config.provisioning_path, "dna.json"))
end
end

View File

@ -60,22 +60,22 @@ module Vagrant
end
def create_client_key_folder
env.ui.info I18n.t("vagrant.provisioners.chef.client_key_folder")
env[:ui].info I18n.t("vagrant.provisioners.chef.client_key_folder")
path = Pathname.new(config.client_key_path)
vm.ssh.execute do |ssh|
env[:vm].ssh.execute do |ssh|
ssh.sudo!("mkdir -p #{path.dirname}")
end
end
def upload_validation_key
env.ui.info I18n.t("vagrant.provisioners.chef.upload_validation_key")
vm.ssh.upload!(validation_key_path, guest_validation_key_path)
env[:ui].info I18n.t("vagrant.provisioners.chef.upload_validation_key")
env[:vm].ssh.upload!(validation_key_path, guest_validation_key_path)
end
def upload_encrypted_data_bag_secret
env.ui.info I18n.t("vagrant.provisioners.chef.upload_encrypted_data_bag_secret_key")
vm.ssh.upload!(encrypted_data_bag_secret_key_path, config.encrypted_data_bag_secret)
env[:ui].info I18n.t("vagrant.provisioners.chef.upload_encrypted_data_bag_secret_key")
env[:vm].ssh.upload!(encrypted_data_bag_secret_key_path, config.encrypted_data_bag_secret)
end
def setup_server_config
@ -96,24 +96,24 @@ module Vagrant
command_env = config.binary_env ? "#{config.binary_env} " : ""
command = "#{command_env}#{chef_binary_path("chef-client")} -c #{config.provisioning_path}/client.rb -j #{config.provisioning_path}/dna.json"
env.ui.info I18n.t("vagrant.provisioners.chef.running_client")
vm.ssh.execute do |ssh|
env[:ui].info I18n.t("vagrant.provisioners.chef.running_client")
env[:vm].ssh.execute do |ssh|
ssh.sudo!(command) do |channel, type, data|
if type == :exit_status
ssh.check_exit_status(data, command)
else
env.ui.info("#{data}: #{type}")
env[:ui].info("#{data}: #{type}")
end
end
end
end
def validation_key_path
File.expand_path(config.validation_key_path, env.root_path)
File.expand_path(config.validation_key_path, env[:root_path])
end
def encrypted_data_bag_secret_key_path
File.expand_path(config.encrypted_data_bag_secret_key_path, env.root_path)
File.expand_path(config.encrypted_data_bag_secret_key_path, env[:root_path])
end
def guest_validation_key_path

View File

@ -72,7 +72,7 @@ module Vagrant
# Create the local/remote path based on whether this is a host
# or VM path.
local_path = nil
local_path = File.expand_path(path, env.root_path) if type == :host
local_path = File.expand_path(path, env[:root_path]) if type == :host
remote_path = nil
if type == :host
# Path exists on the host, setup the remote path
@ -102,7 +102,7 @@ module Vagrant
def share_folders(prefix, folders)
folders.each do |type, local_path, remote_path|
if type == :host
env.config.vm.share_folder("v-#{prefix}-#{self.class.get_and_update_counter(:shared_folder)}",
env[:vm].config.vm.share_folder("v-#{prefix}-#{self.class.get_and_update_counter(:shared_folder)}",
remote_path, local_path, :nfs => config.nfs)
end
end
@ -127,13 +127,13 @@ module Vagrant
command_env = config.binary_env ? "#{config.binary_env} " : ""
command = "#{command_env}#{chef_binary_path("chef-solo")} -c #{config.provisioning_path}/solo.rb -j #{config.provisioning_path}/dna.json"
env.ui.info I18n.t("vagrant.provisioners.chef.running_solo")
vm.ssh.execute do |ssh|
env[:ui].info I18n.t("vagrant.provisioners.chef.running_solo")
env[:vm].ssh.execute do |ssh|
ssh.sudo!(command) do |channel, type, data|
if type == :exit_status
ssh.check_exit_status(data, command)
else
env.ui.info("#{data}: #{type}")
env[:ui].info("#{data}: #{type}")
end
end
end