This repository has been archived by the owner on Jul 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
Trigger recipes
Emiliano Ticci edited this page Nov 1, 2015
·
8 revisions
Feel free to add your own recipes in this page!
Forward port 80 and 443 to your Vagrant box on your Mac (@sgarbesi)
http://salvatore.garbesi.com/vagrant-port-forwarding-on-mac/
Ask for confirmation before running an action (@emyl)
config.trigger.before :halt do
confirm = nil
until ["Y", "y", "N", "n"].include?(confirm)
confirm = ask "Would you really like to shut down the VM? (Y/N) "
end
exit unless confirm.upcase == "Y"
end
Create a baseline VM snapshot if no snapshots exist (@thelateperseus)
Uses the (vagrant-vbox-snapshot) plugin to create a baseline snapshot that we can restore to much quicker than vagrant destroy/up
.
config.trigger.after [:up, :resume] do
# Snapshot list will return 1 if no snapshots exist
`vagrant snapshot list`
unless $?.exitstatus == 0
`vagrant snapshot take Baseline`
@machine.ui.info("Took initial snapshot")
end
end
When a Packer vmware-vmx builder uses the vmdk's from a Vagrant box running CentOS 6.x, packer can never get SSH access to the cloned VM. This has also been seen with a virtualbox builder. This trigger removes the persistent network interface details whenever you do a vagrant halt; allowing the cloned packer VM to successfully get a DHCP lease with vmware and being able to actually SSH to the vagrant clone.
{
:halt => "rm -f /etc/udev/rules.d/70-persistent-net.rules",
}.each do |command, trigger|
config.trigger.before command, :stdout => true do
info "Executing #{command} action via SSH on Vagrant box..."
run "ssh -p 2222 vagrant@localhost 'sudo #{trigger}'"
end
end