• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

Create single node Virtual Machine with Vagrant

May 30, 2020 by Sharad Chhetri Leave a Comment

In this post we will show how to create a single node Virtual Machine with Vagrant. As we know in our previous post we written about How to install Vagrant on Ubuntu and create first VM.
We use Vagrant in our environment for doing lots of testing, POC(Proof Of Concept) and do some pre-work check before it goes to real Dev Environment. When we started there were less Vagrant Providers(including VirtualBox) , now currently it supports various providers like Cloud,containers,HyperV etc.

In Vagrant the main hero is Vagrantfile, from this you manage your Vagrant ecosystem in your machine. You can create Single VM or Multi VM setup with Vagrant. In this post, we are covering Single node VM creation with Vagrant.

Steps to create Single Virtual Machine with Vagrant

In this example, we will show basic config which we often use and will give basic insight so that you can play with some more Vagrantfile config by yourself.

Step 1::Open the terminal in your system because we will use command line here.

Step 2: Create directory where you will keep the Vagrantfile.

mkdir -p ~/vagrant_boxes/Single_VM/poc_box

Step 3: Change to newly created directory

cd ~/vagrant_boxes/Single_VM/poc_box

Step 4: Create a file called ‘Vagrantfile’ and paste the given below contents in it. Important to note, Vagrant is written in Ruby language.

We use the ‘vi’ editor because we love it. You can use other file editor of your choice like ‘nano’,’gedit’,’atom’,’sublime’.’vscode’ etc. there is N numbers of options available.

vi Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|

    # In 'config' block, set variable 'vb' where defining desired Vagrant Provider and VM specs.
    config.vm.provider "virtualbox" do |vb|
      vb.name = "webserver01"
      vb.memory = 1024
      vb.cpus = 2
    end
 
    #now using main 'config' block, defining OS,Hostname and Virtual Box network type.
    config.vm.box = "centos/8"
    config.vm.hostname = "webserver01"
    config.vm.network "private_network", ip: "192.168.33.10"

end

Step 5: Run the command to create single node Virtual Machine in VirtualBox. You can see the execution in your terminal.

vagrant up

Once it is completed, open Virtual Box in your system.You will find your Single VM created with Vagrant.

In given below screenshot, you can see the highlighted changes.
single vm vagrant

Explanation

Note: You can give any other name to Variable but you have to use that particular Variable name for calling in code.

Vagrant.configure("2") do |config| :
The “2” represents the configuration for 1.1+ leading up to 2.0.x. And ‘config’ is the variable.

config.vm.provider "virtualbox" do |vb| :
Calling ‘config’ variable and defining VM provider ‘virtualbox’. For this block, the variable called ‘vb’ is set.
Inside the ‘vb’ block, rest are self explanatory. Here, we are setting Memory and CPU for the Virtual Machine. The memory default value is taken in MB hence 1024 means 1024 MB.

Now the ‘vb’ variable code block is END and then again we started using ‘config’ variable. To define vagrant box, hostname and VirtualBox network type we are ‘config’ variable again.

config.vm.box = "centos/8" this refers the Vagrant Box. Vagrant Cloud is the platform to find number of Vagrant boxes. Get the exact box name and use it in your Vagrantfile configuration.

Reference: Do you want to know more Vagrantfile configurations? Here is the Vagrant Official Documentation.

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. Create multiple virtual machine with one Vagrantfile
  2. Xen Virtual Machine Migration (In Hyper-VM)
  3. Virtual Machine inaccessible status on VirtualBox 4.3
  4. hash:/etc/postfix/virtual is unavailable. open database /etc/postfix/virtual.db: No such file or directory
  5. Install Vagrant on Ubuntu and create first VM
  6. Learn Vagrant provision with shell provisioner examples
  7. /usr/bin/env: node: No such file or directory
  8. How to create Jenkins user by command line and GUI
  9. Enable ethernet in RHEL 6.0 and CentOS 6.0 : Tested In Virtual Box and VMware
  10. How to configure ethernet in CentOS 6 after installing in Virtual Box

Filed Under: Devops, Linux Tagged With: devops, vagrant

Reader Interactions

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.

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Commands

How to install libxml2 and libxslt packages on CentOS 6.5

How to list users above or below particular user id

Temporarily change the shell after login

Unix / Linux : How to print duplicate lines from file

Install libjpegtran by using yum command in CentOS 6.x

vi : Edit file without opening it

How to find installation date and time of rpm package

Explore 70+ Articles On Linux Commands

Always Useful Tips And Tricks

WordPress host IP changed not able to open wp-admin and site page looks scattered

How to find when Operating system was installed in linux CentOS and Red Hat

Keep logs of user after sudo su – : Secondary Logging

Non interactive ,without typing password do ssh to Server : By sshpass

Change default editor of crontab in Ubuntu

Read the file inside compressed .gz files without extract

Password prompt in single user mode is not secure : CentOS/Red Hat

Explore 90+ Article On "Linux Tips And Tricks"

You Might Like These Articles!

Internal External Command

What is Linux/Unix Internal And External Command

Linux basic command

Linux Basic Commands With Examples For Every Beginner

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

Copyright © 2023 ยท
The material in this site cannot be republished either online or offline, without our permission but Schools and Colleges can do in their Private Network
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy