Vagrant - Provision (Code, Software Installation)

Card Puncher Data Processing

Script

Code Shipping - Provisioning in Vagrant.

config.vm.provision :shell, path: "mydir/myScript.sh"

where:

For complex provisioning scripts, it may be more efficient to package a custom Vagrant box with those packages pre-installed instead of building them each time. See the packaging custom boxes documentation.

Command

Run

Provisioning happens at certain points during the lifetime of your Vagrant environment:

  • On the first vagrant up that creates the environment, provisioning is run. If the environment was already created and the up is just resuming a machine or booting it up, they will not run unless the –provision flag is explicitly provided.
  • When vagrant provision is used on a running environment.
  • When vagrant reload –provision is called. The –provision flag must be present to force provisioning.
    • Reload quickly restart the virtual machine, skipping the initial import step.
    • –provision: instructs Vagrant to run the provisioners, since usually Vagrant will only do this on the first vagrant up.

Not run

You can also bring up your environment and explicitly not run provisioners by specifying –no-provision.

Example

Apache

Vagrant.configure("2") do |config|
  config.vm.box = "hashicorp/precise64"
  config.vm.provision :shell, path: "installApache.sh"
end
#!/usr/bin/env bash

apt-get update
apt-get install -y apache2
if ! [ -L /var/www ]; then
  rm -rf /var/www
  ln -fs /vagrant /var/www
fi





Discover More
Card Puncher Data Processing
Vagrant - (Lifetime|Lifecyle) - Command

The principal command of Vagrant are defining the lifetime of the virtual machine. Init a project directory to be used with vagrant. It will create a .vagrant directory into the directory project...



Share this page:
Follow us:
Task Runner