Learn Vagrant from Scratch : Provision environment for the virtual machine

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 cloud infrastructure engineer and a full stack web developer and blogger. Sportsperson by heart and loves football. Scale is something he loves to work for and always keen to learn new tech. Experienced with CI/CD, distributed cloud infrastructure, build systems and lot of SRE Stuff.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.