Executing shell scripts in a Vagrantfile

Provisioning a Vagrant machine with single inline string arguments can make simple provisioning tasks easy, but more complicated requirements can require more complicated scripts. Scripts can be defined within Vagrantfiles using the multiline string feature of Ruby. A multiline string will allow a definition of a set of commands that can be executed with the Vagrant inline command.

This example will also demonstrate how we can make a script idempotent, which is capable of being executed multiple times without changing the end state of the machine after every run.

Getting ready

In this example, we will provision a new Vagrant environment, install the nginx web server, and replace the default web directory with ...

Get Vagrant Virtual Development Environment Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.