Skip to content

Instantly share code, notes, and snippets.

@tcnksm
Created February 25, 2014 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tcnksm/39be2506b8a5e846cd59 to your computer and use it in GitHub Desktop.
Save tcnksm/39be2506b8a5e846cd59 to your computer and use it in GitHub Desktop.
Vagrant plugin on Vagrantfile
module MyPlugins
class Plugin < Vagrant.plugin("2")
name "install packages"
config(:apt_get, :provisioner) do
class Config < Vagrant.plugin("2", :config)
attr_accessor :packages
def initialize
super
@packages = UNSET_VALUE
end
def finalize!
@packages = [] if @packages == UNSET_VALUE
end
end
Config
end
provisioner :apt_get do
class Provisioner < Vagrant.plugin("2", :provisioner)
def provision
command = "apt-get install -y #{@config.packages.join(' ')}"
@machine.communicate.sudo(command) do |type, data|
@machine.env.ui.info(data.chomp, prefix: false)
end
end
end
end
end
Vagrant.configure("2") do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.provision :apt_get do |p|
p.packages = ["htop","wget", "hello"]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment