

Get Vagrant: Up and Running now with the O’Reilly learning platform. In the previous chapter, we did this by manually running Python’s. In this chapter, we’ll set up Apache to serve static files from the Vagrant shared folder. Additional provisioners can be added via plug-ins if your organization requires it. Out of the box, Vagrant supports provisioning with shell scripts, Chef, or Puppet.
#VAGRANT PROVISION SOFTWARE#
Vagrant supports automated provisioning, and will run configured provisioners on every vagrant up so that the necessary software and configurations needed to run the project being developed in the Vagrant environment are all properly prepared.
#VAGRANT PROVISION MANUAL#
The problem of installing software on a booted system is known as provisioning, and is often the job of shell scripts, configuration management systems, or manual command-line entry.

Only the minimal amount of software required to make it function with Vagrant (e.g., SSH) is installed. The base box this book has been using in examples so far is a bare-bones Ubuntu 12.04 LTS installation. In practice, the base boxes used by Vagrant are usually quite bare. This can be done one of two ways: baking the software into the box itself, or automatically installing the software as part of the development environment creation process. This means that all the necessary software for each project being developed should be installed on the guest. => default: Running provisioner: shell.ĭefault: Hello from provisioner 7.According to The Tao of Vagrant, a developer can simply run vagrant up and have a complete development environment ready to go. This prints the “ Hello from provisioner” message when the provisioning runs: $ vagrant up Let’s define a simple shell provisioner in our Vagrantfile: nfigure("2") do |config|
#VAGRANT PROVISION INSTALL#
Before automatic provisioning, you would SSH into your guest machine and install a webserver. For example, we can run shell scripts or copy files to the virtual machine. Vagrant allows you to automatically provision environments, including web servers. On top of that, there are different types of provisioners as well. We can have multiple provisioners per project. It happens when we first create the environment with the vagrant up command, but we can run it manually, too. Provisioning automates the process of customizing the development environment. We can do this every time by hand, but it would be time-consuming and error-prone. We need to install and configure the necessary components to have a useful development environment. Usually, simple boxes aren’t enough for our use cases. We can manage boxes directly with the vagrant box command. Boxes can have an optional metadata file that contains information about versioning, providers, or simply the name and description of the box. To do this, it had to look into the metadata of the box. => default: Successfully added box 'hashicorp/bionic64' (v1.0.282) for 'virtualbox'!Īs we can see, Vagrant didn’t find the box on our machine, so it downloaded it from Vagrant Cloud. => default: Adding box 'hashicorp/bionic64' (v1.0.282) for provider: virtualbox => default: Loading metadata for box 'hashicorp/bionic64' => default: Box 'hashicorp/bionic64' could not be found. This command downloads the specified box and starts the virtual machine: Bringing machine 'default' up with 'virtualbox' provider. The up command in Vagrant creates and configures our environment: $ vagrant up Let’s start a virtual machine using the previously defined Vagrantfile.

We’ve removed some comments from the file for clarity: Let’s take a look at the generated file and understand what each section does. You are now ready to `vagrant up` your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on `` for more information on using Vagrant. It produces the following output, and we can find the generated Vagrantfile in the directory: A `Vagrantfile` has been placed in this directory. We can create an initial Vagrantfile in this directory using the init command: $ vagrant init hashicorp/bionic64 Let’s create our Vagrant project in a directory called vagrant-start. On the other hand, if we know Ruby well, we can make use of it and create more complex Vagrantfiles easily. Most of the time, we use simple operations, for example, variable assignment. Vagrantfiles use the Ruby programming language, but we don’t necessarily need to know Ruby to create, understand or modify these files. For example, we can have a Vagrantfile in our Vagrant home directory with some default configuration and override the project-specific values in the project directory. However, when we run Vagrant commands, it looks for other Vagrantfiles on our filesystem and merges the relevant ones to build the final configuration.
