Created
January 22, 2011 07:48
-
-
Save peritus/790962 to your computer and use it in GitHub Desktop.
I want to 'vagrant destroy' and 'vagrant up' vms when on the train, plane and bus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Vagrant Rsync Provisioner | |
# | |
# TODO: Make the download commands available via 'vagrant rsync_download' | |
# | |
# == Motivation == | |
# | |
# I want to 'vagrant destroy' and 'vagrant up' vms when on the train, plane and | |
# bus. Not fetching debian packages also tends to make provisioning with chef | |
# faster. | |
# | |
# == Installation == | |
# | |
# Put this in a file named 'rsync_provisioner.rb' in the directory where your | |
# Vagrantfile is. | |
# | |
# == Configuration == | |
# | |
# Add this to your Vagrantfile (in this case it's smart to place this before | |
# the chef_solo section): | |
# | |
# config.vm.provision RsyncProvisioner do |rsync| | |
# rsync.paths = { | |
# "apt_cache/" => "/var/cache/apt/", | |
# } | |
# end | |
# | |
class RsyncProvisioner < Vagrant::Provisioners::Base | |
class Config < Vagrant::Config::Base | |
attr_accessor :paths | |
end | |
def rsync_opts | |
ssh_user = vm.env.config.ssh.username | |
ssh_port = vm.ssh.port | |
private_key_path = vm.env.config.ssh.private_key_path | |
"rsync -avzP --rsync-path='sudo rsync' -e 'ssh -i #{private_key_path} -p #{ssh_port} -l #{ssh_user}'" | |
end | |
def provision! | |
puts | |
puts "# To download rsync.paths from the vm, use these commands:" | |
config.paths.each do |local_path, vm_path| | |
download_cmd = "# #{rsync_opts} :#{vm_path} #{local_path}" | |
puts download_cmd | |
end | |
puts | |
puts "# Provisioning with rsync:" | |
puts | |
config.paths.each do |local_path, vm_path| | |
upload_cmd = "#{rsync_opts} #{local_path} :#{vm_path}" | |
puts upload_cmd | |
system upload_cmd | |
end | |
puts | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment