Home Cloud & Networking Hands-On DevOps with Vagrant

Hands-On DevOps with Vagrant

By Alex Braunton
books-svg-icon Book
eBook $29.99 $20.98
Print $38.99
Subscription $15.99 $10 p/m for three months
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
eBook $29.99 $20.98
Print $38.99
Subscription $15.99 $10 p/m for three months
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
  1. Free Chapter
    Introduction
About 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.
Publication date:
October 2018
Publisher
Packt
Pages
232
ISBN
9781789138054

 

Chapter 1. Introduction

You are about to embark on an exciting journey focused on Vagrant and its role within DevOps. Throughout these chapters, you will learn interesting and useful facts, as well as tips and tricks, about Vagrant. Initially, we will focus on the basics of Vagrant and getting it installed and running on your machine. We will then venture through its ins and outs, by focusing on the important parts of Vagrant, such as its commands, networking, multi-machine, Vagrantfiles, and using configuration management tools, such as Chef, Docker, and Ansible. By the end of this book, you will have solid foundational knowledge about Vagrant and the necessary skill set to start using it on a day-to-day basis as part of your DevOps workflow. 

In this chapter, we will create a solid foundation that will help you understand what Vagrant is, what VirtualBox is, and how Vagrant ties into the DevOps landscape. We will learn about the current state of development tools in DevOps and focus on how Vagrant can be used by many different teams in an organisation—not just developers! By the end of this chapter, you will have a good understanding of the basics of Vagrant, VirtualBox, and DevOps.

 

Getting started with Vagrant and DevOps


In this section, you will be introduced to Vagrant and learn about its features, benefits, and its role in the development tools used in the DevOps world. 

Understanding Vagrant

Vagrant is very simple on the surface, but is actually incredibly complex under the hood. It allows you to quickly and effortlessly create virtual environments (known as Vagrant boxes) and customize them. Vagrant easily integrates with multiple providers, such as VirtualBox, VMware, and Docker. These providers actually power the virtual environments, but Vagrant provides a customizable API to that virtual machine.

Vagrant has a large selection of commands, which can be used from the command line/Terminal to manage virtual environments. These commands can quickly download and set up an environment from the Vagrant cloud, which hosts many popular environments, such as Ubuntu or PHP's Laravel.

Vagrant is an important piece of software that can be found in many programmers' toolboxes. It is commonly used to tackle the well-known phrase, It works on my machine, by allowing everyone to have a copy of the same environment.

Vagrant was created by Mitchell Hashimoto and released in March 2010. Vagrant is now part of the HashiCorp company, which Mitchell Hashimoto cofounded in 2012 with Armon Dadgar. Vagrant is an open source piece of software that has been built in the Ruby language. It is currently being licensed under the MIT license. Vagrant can be run on macOS, Windows, FreeBSD, and Linux.

Vagrant is essentially another layer in the virtualization stack. It acts as an easily programmable interface to control virtual environments. Vagrant relies on a provider, such as VirtualBox, to power these environments, but it can also configure providers so they work in harmony – an example would be Vagrant controlling how much memory (RAM) an environment has.

Vagrant features

Vagrant offers many features to help you build and configure virtual environments. Vagrant features can be split into a few key areas—Vagrantfile, boxes, networking, provisioning, and plugins. Vagrant can be managed in two key ways – the command line and a Vagrantfile. The command-line approach is often used for admin tasks, such as downloading/importing a new Vagrant box or deleting an old one.

Vagrantfile

A Vagrantfile is a configuration file that uses the Ruby programming language syntax. It is easy to understand and can be quickly tested by making a change and then running the vagrant up command to see whether the expected results happen. A Vagrantfile can easily be shared and added into version control. It's lightweight and contains everything needed for another user to replicate your virtual environment/application.

Boxes

Vagrant boxes are packages that, similar to Vagrantfiles, can be shared and used to replicate virtual environments. Vagrant boxes can be easily downloaded by running the vagrant box add command. The Vagrant cloud offers an easily searchable catalogue of boxes. The Vagrant cloud provides lots of information about a box, such as the creator, the version, how many times its been downloaded, and a brief description.

Networking

Vagrant supports three main types of networking when creating virtual environments: public networks, private networks, and port-forwarding. The simplest networking option is port-forwarding, which allows you to access a specific port through the guest operating system into the Vagrant machine. Public and private networking are more complex and offer more configuration, but we will cover that in future chapters.

Provisioning

Provisioning in Vagrant offers you a way to configure the Vagrant machine even more. You can install software and dependencies as the machine is being created. To provision a Vagrant machine, you can use shell scripting, Docker, Chef, Ansible, and other configuration-management software, such as Puppet.

Plugins

Vagrant plugins offer another way to customize and extend the functionality of Vagrant. They allow you to interact with the low-level aspects of Vagrant and often provide new commands to be used as part of the Vagrant command line.

Advantages of Vagrant

Vagrant allows you to easily package up a virtual environment that can be shared among fellow developers. This packaged virtual environment is often referred to as a Vagrant box. A box can be configured to mirror the production environment where your web application or code will be running. This can help minimize any bugs or issues when your application/code is deployed to the production environment.

The beauty of Vagrant's configuration (known as a Vagrantfile) is often small and can be easily edited and tested. The syntax of a Vagrantfile is easy to understand and offers a simple way to build a complex environment.

Vagrant can be used by many different members of a team, including those on the development team, the operations team, and the design team. 

Development team

For a developer, Vagrant can allow them to package up their code/application into an easily-sharable fully-fledged development environment. This can then be used by developers using different operating systems, such as macOS, Linux, or Windows. 

Operations team

The operations team can easily and quickly test deployment tools and scripts using Vagrant. Vagrant supports many popular deployment tools in the operations/DevOps world, such as Puppet, Docker, and Chef. Vagrant can be a cheaper and faster way to test deployment scripts and infrastructure topologies. Everything can be done locally with Vagrant or it can be used with a service such as Amazon Web Services.

Design team

Vagrant allows the development team and operations team to create virtual environments running code, and applications ready for a designer to easily run this environment on their machine and start making edits to the application. There is no configuration required and feedback can be instant, from when a developer makes a change or a developer has to update the Vagrantfile.

What is VirtualBox?

VirtualBox is one of the many providers that Vagrant supports. VirtualBox is a powerful virtualization tool that allows you to create virtual environments on your existing operating system. It allows you to fully customize a virtual machine's hardware, such as the RAM, CPU, hard drive, audio, and graphics.

VirtualBox was initially released in January 2007 by the company Innotek GmbH, which was later acquired by Sun Microsystems, which, in turn, was acquired by the Oracle Corporation. Oracle is actively maintaining and releasing new versions of VirtualBox.

VirtualBox is built in x86 Assembly, C++, and C. It can run and supports many different operating systems, such as Windows, Linux, Solaris, and OS X.

What is DevOps?

DevOps is a popular term in the IT world at the moment. There are many different opinions as to what DevOps actually is. In simple terms, DevOps is the mix of development and operations. It is essentially creating a sort of "hybrid programmer" who knows about operations and infrastructure, or a system admin who understands programming and can develop applications.

DevOps is a mixture of methodologies, practices, philosophies, and software. DevOps streamlines the whole project life cycle by creating a workflow that works for all departments. There are no rules or laws in DevOps, but generally it's the process of connecting the developers and the infrastructure team by enabling an easy way to develop and ship code.

The beauty of DevOps is that any company can start following its ideas, methodologies, and best practices. Large companies may have a whole DevOps department/team, whereas smaller companies may just need one or two dedicated DevOps employees. In a start-up scenario, where money must be carefully budgeted, one employee may take on the role of developer and also DevOps.

 

Vagrant for DevOps


In this chapter, you will learn about the current state of development in DevOps, how Vagrant fits into DevOps, and how to use Vagrant as a day-to-day DevOps tool. By the end of this chapter, you will have a much better understanding of how Vagrant can be used for development as part of the DevOps process.

Current state of development within DevOps

As mentioned previously, DevOps is a mixture of software development, operations/system administration, and testing/quality assurance. DevOps is not a new movement, but one that doesn't necessarily have a leader or a set of rules and standards to follow. Every company has their own idea of what DevOps is and how it should be implemented. Many follow similar paths or rough guidelines. Due to the lack of governance with DevOps, the current state of development is varied.

Traditionally, development has always been separate to the operations and server team, but in the last few years, we have seen many DevOps tools bridge that gap and make life easier for both sides.

In the past, when a web developer would build a web application, they would code it, built it locally on their machine, and then FTP (file transfer) the files onto a live (production) server to then run the code—if there were any issues or bugs, the developer would have to make changes to the server environment and debug the code. There are many developers who still use this workflow and it may be because of their environment or because they have no choice in the matter.

Today, a modern web developer's workflow may look like this:

  1. The developer writes their code locally but through a virtual environment/machine with a tool such as Vagrant. This allows the developer to set up an environment such as the production one.
  2. The developer edits to their code and uses version-control (such as Git or Subversion) to manage changes. The version-control is set up in a way that allows the developer to keep test/new code separate from the production code.
  3. A continuous integration (CI) tool (such as Jenkins or Travis CI) is used to create a pipeline that often has three separate stages—development, staging, and production. The CI tool can be used to run tests against the software, and run scripts such as performing assets by combining and minifying them. The version-control software can be linked into the CI tool, which often triggers these builds and tests. When the developer pushes some new code to the staging environment, tests can be run before it reaches the production environment.
  4. Often, if the tests run and there are no issues, the code may be pushed directly into the production branch in the version control. At this point, the CI tool may trigger a new build, which would essentially restart the service that the code applies to. This could be simple or complex, depending on the production environment and software architecture.
  5. At some stages during this process, there may be manual intervention by the QA (quality assurance/testing) team or more senior developers who wish to check the code before it goes to production.

Of course, this is just an example workflow and will differ between companies and development teams. The modern workflow may seem much more complicated and tedious, but this is for good measure. At each stage, you'll notice there are checks and tests run before the code can reach a live production environment where real users may be interacting with that code. This can be incredibly important when working with financial software and other business-critical software. This modern workflow greatly reduces the margin of error.

Modern development in the DevOps world is focused on speed and automation. The focus on speed is the ability to quickly build a feature or fix a bug and "push the code to production" (a phrase you might have heard!). This means that single developers or a team of developers have less of a barrier when working on the code. A developer shouldn't worry about configuring servers or environments.

Automation is a big part of DevOps, and that effects the development part too. You can imagine how slow a process it would be if a developer made changes to their code and then had to wait for a member of the operations team to manually run tests and scripts against their changes before letting them know the result. 

Vagrant and DevOps

I believe that Vagrant is a key tool in a developer's toolbox in today's DevOps-focused world. Vagrant is essentially a suite of tools that allows the developer to create code but also connect with configuration management tools, such as Puppet, Chef, and Ansible, that are used to automate workflows and environments on servers.

Vagrant's primary focus is on development and enables an easy way for every developer on the team to use the same environment. Within a Vagrant environment, you can run version-control that could link into the CI workflow, which allows you to run tests and move code into different stages.

Using Vagrant as a day-to-day DevOps tool

Vagrant is a flexible tool that enhances day-to-day development by allowing you to easily test out DevOps workflow ideas. It allows you to separate your software code and infrastructure without having to know much about DevOps, infrastructure, servers, and configuration-management tools. 

As a day-to-day DevOps tool, Vagrant can be used for many things, including the following:

  • Testing software code in different environments and operating systems
  • Testing different workflows using configuration-management tools, such as Chef and Puppet
  • Working in the same environment as other developers in your team/company
  • Easily make changes to Vagrant and see the results instantly
  • Running multiple environments/virtual environments to test out networking, file-sharing, and other multi-server use cases
 

Summary


In this chapter, we learned that Vagrant is a very powerful and flexible tool for helping create virtual environments that can mimic staging and development environments used by your business or application. We looked at the current development state of DevOps, how Vagrant fits into that, and how to use Vagrant as a day-to-day development tool.

In Chapter 2Installing VirtualBox and Vagrant, we will install Vagrant and its provider, VirtualBox. We will look at how to install these pieces of software on a Windows, Mac, and Linux machine. You will also learn how to find out your system's version and its CPU architecture.

About the Author
  • Alex Braunton

    Alex Braunton is a web developer focusing on the LAMP stack by day and a technical tinkerer by night. He is passionate about all technological things and enjoys trying to build robots and home automation systems with his Raspberry Pi collection. Currently, he is focusing on sharpening his DevOps knowledge and experimenting with a range of technologies, such as serverless, virtual reality, and GraphQL. He also has a growing bonsai collection and constantly bores his wife and family about the art and history of bonsai.

    Browse publications by this author
Hands-On DevOps with Vagrant
Unlock this book and the full library FREE for 7 days
Start now