Vagrant: Building stronger workflows in DevOps
In my previous post, I spoke about DevOps in 2019, and the surge that is expected in DevOps practices across the Software Development LifeCycle (SDLC). From here on, we will be taking different DevOps tools and environments which are expected to contribute the most towards the DevOps tool market in 2019.
Servers are moving faster to the cloud, and physical machines have been translated to Virtual Machines. Infrastructure as Code helps to manage and provision data centers through code rather than configuration tools. It helps to automate the environment setup while deploying an application, lowering development environment setup time and increasing production parity.
Vagrant provides easy to configure, reproducible, and portable work environments via a single consistent workflow to reduce time of development and operations team.
The machines are provisioned on top of Virtual Box, VMware and other providers, where tools such as Chef, Puppet etc. can automatically install and configure software applications on the virtual machine.
Who Uses Vagrant?
- Dev Ops Engineer
Advantage for Developers:
Developers do not need to specify environment details each time a new environment is to be created for development purposes. A single Vagrant configuration file with all tools that are needed for the development, can be provided to the developer, for faster environment creations in the future.
Advantage for Operators:
If you are a devops engineer, it gives you an environment and consistent workflow for developing and testing infrastructure management scripts. You can quickly test things related to infrastructure, and then, with the same configuration and workflow, you can test these scripts on cloud services such as AWS, Rackspace etc.
Advantage for Designers:
If you are a designer, you just have to run “vagrant up” command, vagrant will configure and setup everything that is required for your web app to run. Now you don’t need to bother other developers to fix your environment so you can easily test your designs further reducing design iterations.
What are Vagrant Boxes?
Boxes are nothing but images of virtual machines. Building virtual machines from scratch is a time intensive process and using boxes simplifies the process immensely. Apart from the Operating System, a box can have various software applications that are required for a development process.
How can you create and use a Vagrant environment from scratch? (Windows)
Prerequisite: Oracle virtual box should be installed.
1. Open command prompt.
2. Set the directory to vagrant file directory.
3. Now run the below commands to start the process
D:\POC> vagrant init hashicorp/precise64
(hashicorp/precise64 – It is a default box provided by vagrant.)
4. Once you have run that command you can see some similar message as per the below screen shot.
5. D:\POC> vagrant up
If everything is successful without errors, you can see the below screen shot with running virtual machine.
6. D:\POC> vagrant ssh
This command is used to access your virtual operating system files. Once you run this command you can see the similar screen shot as below.
7. Now your Ubuntu operating system is ready to use.
How to install and run a PHP web site in an environment created by Vagrant?
PHP boxes are already available, instead of using them, we will install and configure it manually.
- D:\POC> sudo apt-get update
- D:\POC> sudo apt-get install apache2 –y
- D:\POC> sudo apt-get install php5-mysql
Once you have installed it successfully, next up configure the IP address and port so that it will be easy to run and test your application on the original operating system.
- Find the below line in your vagrant file and uncomment it, so that you can run your PHP application on the below IP address, in your original operating system.
config.vm.network “public_network”, ip: “192.168.0.17”
So, that covers how Vagrant can ease environment set up issues and ensure consistent environments are used across the team for better productivity.
Surya Narayana Murthy
Surya Narayana Murthy
Being a web developer, I love to learn new technologies and stay up-to date with current trends. Apart from my work I like to take apart and assemble electronic devices, travelling and exploring new places at my own pace.All stories by: Surya Narayana Murthy