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

Preface

Vagrant is an open source tool that allows you to programatically create and manage virtual environments. Vagrant's main focus is on creating development environments that can be shared between teams all over the world. It removes the "works fine on my machine" problem and allows anyone with the Vagrantfile configuration to create an exact copy of the original machine.

Vagrant was created and is maintained by Mitchell Hashimoto and HashiCorp with a continuous stream of support and updates. It's a piece of software that has been going from strength to strength since its creation in 2010.

Who this book is for

In this book, we'll cover many aspects of Vagrant. The book can be used by beginners who have very little or no experience with Vagrant. We'll cover how to install Vagrant and all of the basic knowledge needed to get up and running.

This book can also be used by more advanced users who wish to better understand and utilize Vagrant. We'll cover the available commands, networking, multi-machine, and provisioning with configuration management tools such as Chef and Ansible.

Whatever level you are at, this book will teach you something new or help reinforce your knowledge and offer tips and tricks.

What this book covers

Chapter 1, Introduction, acts as a great introduction to the world of Vagrant. It will help create a foundation of knowledge to guide you through the book. You will learn what Vagrant is, the benefits of Vagrant, what VirtualBox is, and what DevOps is. You'll also learn how Vagrant fits into the DevOps landscape, how it can be used as a DevOps tool, and take a look at other pieces of software.

Chapter 2, Installing VirtualBox and Vagrant, Windows, macOS, and Linux, gets your hands dirty by teaching you how to install VirtualBox and Vagrant. We'll cover the three main operating systems: Windows, macOS, and Linux. You'll learn how to navigate both websites (https://www.virtualbox.org and https://www.vagrantup.com) to download, install, and verify the software, once it has been installed.

 

 

Chapter 3Command Line-Interface - Vagrant Commands, teaches you about the range of useful commands that Vagrant provides. You'll learn about all of the available commands and sub-commands. You'll also learn about the structure of Vagrant commands, how to use the help command to get more information, and a brief description of what each one does. You will feel confident in managing Vagrant via the command line by the end of this chapter.

Chapter 4Discovering Vagrant Boxes - Vagrant Cloud, covers all aspects of Vagrant boxes. We will look at how to manage them: installation, deletion, and versioning. We will also create a base box that has the minimum requirements for building a Vagrant environment. In this chapter, we will also cover Vagrant Cloud and what it offers you. Vagrant Cloud is a searchable index of Vagrant boxes that are ready to download. We'll cover a range of things, such as how to use the the Vagrant Cloud website, how to search for a specific box, and how to install that box.

Chapter 5, Configuring Vagrant Using a Vagrantfile, explores the Vagrantfile, which allows you to easily customize your Vagrant machine. The Vagrantfile offers many different configuration options, such as networking, folder syncing, the multi-machine option, provisioning, and provider-specific settings. You'll also learn the syntax and formatting of a Vagrantfile and how to validate it, once created.

Chapter 6, Networking in Vagrant, explains how networking in Vagrant is easily configurable and can be used to create some powerful setups. There are three key networking configuration options that you will learn about in this chapter: port forwarding, public networking, and private networking. You'll learn how to use each one through examples and view the benefits of each.

Chapter 7, Multi-Machine, looks at the multi-machine option, which allows you to create multiple Vagrant machines and manage/configure them using a single Vagrantfile. You will create a multi-machine environment that mimics a real-world scenario. You will create one machine that runs a web server and another that runs a database. These machines will communicate using a networking configuration. This will give you a solid foundation and help you to start creating powerful environments using the multi-machine option.

Chapter 8, Exploring Vagrant Plugins and Syncing Files, gets into how, although Vagrant offers many features, there may be a specific use case where you require some additional functionality. In this chapter, you will learn all about Vagrant plugins. You will see how easy it is to install and use Vagrant plugins. There are a range of commands and sub-commands to learn about, too. In this chapter, you will also learn about syncing files with Vagrant and the different configuration options available.

 

Chapter 9Shell Scripts - Provisioning, deals with provisioning in Vagrant, which is another powerful Vagrant feature, giving you the ability to easily provision your Vagrant machines. This chapter acts as an introduction to provisioning and will teach you more about configuration management tools, shell provisioning, and file provisioning. There are multiple configuration options available when using these types of provisioning to learn about, too.

Chapter 10, Ansible - Using Ansible to Provision a Vagrant Box, teaches you how to provision a Vagrant environment using Ansible and Ansible playbooks. You will also briefly learn how to install Ansible on your Vagrant machine, before learning how to use Ansible on the host machine to provision the Vagrant box.

Chapter 11, Chef - Using Chef to Provision a Vagrant Box, teaches you how to provision a Vagrant environment using Chef and Chef cookbooks. You will look at provisioning the machine using the basic option, Chef Solo, and the advanced option, Chef Client.

Chapter 12, Docker - Using Docker with Vagrant, delves into how to provision a Vagrant environment using Docker. We'll look at searching and pulling images from the Docker Hub and then running them as containers. We'll also look at the different options Docker accepts when we're using it as a Vagrant provisioner.

Chapter 13, Puppet - Using Puppet to Provision a Vagrant Box, explores how to provision a Vagrant environment using Puppet. You will learn about the two main options available with Vagrant: Puppet Apply and Puppet Agent. Using Puppet Agent, you will see how to connect to a Puppet master and retrieve instructions from that.

Chapter 14, Salt - Using Salt to Provision a Vagrant Box, tackles how to provision a Vagrant environment using Salt. You will also learn about Salt states, which allow us to dictate which packages and services should be added into the provisioning.

To get the most out of this book

This book is aimed at both beginners and advanced users. It will teach you how to install the required software. If you already have this software, please check the versions that you have as there may be differences between the version that you have and the version that we use in the book. You may need to upgrade your software. You will need:

  • VirtualBox version: 5.2.10
  • Vagrant version: 2.0.4
  • Ubuntu box (from Vagrant cloud) version: ubuntu/xenial64 20180510.0.0

It's worth reading through each chapter a few times so you don't miss anything. If you need more information or clarification, the official Vagrant website documentation is fantastic.

Download the example code files

You can download the example code files for this book from your account at www.packtpub.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packtpub.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Hands-On-DevOps-with-Vagrant. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it https://www.packtpub.com/sites/default/files/downloads/9781789138054_ColorImages.pdf.

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "This metadata is usually stored as a JSON document. The filename would be metadata.json."

A block of code is set as follows:

Vagrant.configure("2") do |config|
     config.vm.box = "base"
 end

Any command-line input or output is written as follows:

config.vm.network "public_network", ip: "192.168.1.123"

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "There is a list of supported operating systems, but we need to click on the Latest Releases on macOS section."

Note

Warnings or important notes appear like this.

Note

Tips and tricks appear like this.

 

 

Get in touch

Feedback from our readers is always welcome.

General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packtpub.com.