Book Image

Hands-On DevOps with Vagrant

By : Alex Braunton
Book Image

Hands-On DevOps with Vagrant

By: Alex Braunton

Overview of this book

Hands-On DevOps with Vagrant teaches you how to use Vagrant as a powerful DevOps tool and gives an overview of how it fits into the DevOps landscape. You will learn how to install VirtualBox and Vagrant in Windows, macOS, and Linux. You will then move on to understanding Vagrant commands, discovering its boxes and Vagrant Cloud. After getting to grips with the basics, the next set of chapters helps you to understand how to configure Vagrant, along with networking. You will explore multimachine, followed by studying how to create multiple environments and the communication between them. In addition to this, you will cover concepts such as Vagrant plugins and file syncing. The last set of chapters provides insights into provisioning shell scripts, also guiding you in how to use Vagrant with configuration management tools such as Chef, Ansible, Docker, Puppet, and Salt. By the end of this book, you will have grasped Vagrant’s features and how to use them for your benefit with the help of tips and tricks.
Table of Contents (21 chapters)
Title Page
Dedication
Packt Upsell
Contributors
Preface
Index

Basic usage of Vagrant provisioning


To get started with provisioning our Vagrant machine, let's create a new Vagrantfile. We can do this by running the vagrant init -m command.

Within our Vagrantfile, we can define a provisioning block by using the config.vm.provision code and pass in a value to declare what type of provisioner we will be using. In the following example, we will be using the shell type:

config.vm.provision "shell"

Using the shell provisioner, you can then define additional values inline:

config.vm.provision "shell", inline "sudo apt-get update -y"

 

 

Or use a configuration block, where we define our shell value within pipe characters:

config.vm.provision "shell" do |shell|
     shell.inline = "sudo apt-get update -y"
 end

Both options would, in this example, update the system packages. Using the configuration block method is much easier to read, as each value can have its own line.

Vagrant provisioning commands

Once you've created your provisioner values, it's time to apply those...