Learn Steps

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.