Book Image

Vagrant Virtual Development Environment Cookbook

Book Image

Vagrant Virtual Development Environment Cookbook

Overview of this book

Table of Contents (17 chapters)
Vagrant Virtual Development Environment Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 a directory in our working directory. The working directory that holds the Vagrantfile is shared, by default, with the guest operating system as the /vagrant folder.

Before we start our Vagrant environment, create a directory named html in the working...