Skip to content

Instantly share code, notes, and snippets.

@savishy
Last active May 25, 2022 23:05
Show Gist options
  • Save savishy/d771191108cb582e386276fae52a1038 to your computer and use it in GitHub Desktop.
Save savishy/d771191108cb582e386276fae52a1038 to your computer and use it in GitHub Desktop.
Vagrant Tips and Tricks

Vagrant Tips and Tricks

Vagrant shell provisioner allows reading from Gists!

reference

Assuming

  1. You are using Vagrant and Shell provisioner often (e.g when doing Windows provisioning you will end up using Powershell a lot)
  2. You have started running into the problem of reusing your scripts

In this case you want to be able to download and run Powershell scripts.

Thankfully Vagrant has this ability built in.

From the reference:

If you use a remote script as part of your provisioning process, you can pass in its URL as the path argument as well. If you are running a Batch or PowerShell script for Windows, make sure that the external path has the proper extension (".bat" or ".ps1"), because Windows uses this to determine what kind of file it is to execute. If you exclude this extension, it likely will not work.


Vagrant.configure("2") do |config|
  config.vm.provision "shell", path: "https://example.com/provisioner.sh"
end

If you have duplicate provisioners of a given type, name them!

reference

If you have many provisioners of the same type (e.g shell) and want to call just one then name the provisioners as shown:

config.vm.provision "name1", type: "shell", do |s|
end

config.vm.provision "name2", type: "shell", do |s|
end

config.vm.provision "name3", type: "shell", do |s|
end

You can then use vagrant provision --provision-with name1 to provision with just the name1 provisioner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment