Learn Vagrant from Scratch : Provision environment for the virtual machine

Learn Vagrant from Scratch : Provision environment for the virtual machine
4.5 (90%) 2 votes

Provisioning and Setting up environment for the virtual machine

We have a simple box running with synced folder and we are able to ssh into it. Now what we want to do next is to make our vagrant install some softwares for us like update ubuntu, install vim and then nginx.

For this we will make a simple shell script that will be executed when we provision our vagrant box.

Make a file named provision.sh with the following shell script

#!/usr/bin/env bash

apt-get update
apt-get install -y vim
apt-get install -y nginx

Now make these changes in Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.box = "hashicorp/precise64"
  config.vm.provision :shell, path: "provision.sh"
end

Now your vagrant will call the provision.sh and it will install these softwares for you.

Run

vagrant provision

if you are already running a vagrant box or just

vagrant up

the system. Now you can ssh into the system and trying checking if the server is there or not.

 

 


Gaurav Yadav

Gaurav is a Full Stack Web Developer and Blogger. Sportsperson by heart and loves football. He has experience with various frameworks in php, python and javascript. Loves to explore new frameworks and evolve with the trending technology.

Leave a Reply

Your email address will not be published. Required fields are marked *