DEV Community

Cover image for Automate VM Creation Using Vagrant
Yusuf Khadijat
Yusuf Khadijat

Posted on

Automate VM Creation Using Vagrant

Creating and Managing VMs manually on platforms such as Virtual box and Vmware workstation can be time consuming, especially when handling multiple VMs at the same time where speed and consistency is required. Automating VM creations using tools like Vagrant makes this process easier and seamless.
In this tutorial, I will be showing you how to set up and create a CentOS7 operating system in your Windows machine with Virtual box and vagrant in minutes!

First, the Prerequisites:

  • Ensure you have chocolatey installed on your windows machine. You can install here
  • Also, install Virtual Box software on your windows system.
  • Install git bash. This will allow us to run Linux commands on our windows system.

Step 1: With Chocolatey installed, we can easily download Vagrant into our system. Open up powershell with administrative privilege, and run the following command:

Vagrant download command

Step 2: Once Vagrant is installed, Create a directory where your VM will be setup in git bash. Vagrant cloud provides a list of different vagrant boxes. Each box includes an operating system at its base to set up a working environment, while other specialised boxes will have configurations like Laravel, Lamp stacks, Ruby etc already provided. Search for “CentOS7” and select a box with that name. Ensure that the box supports the provider (Virtual box, vmware, hyperv, etc) you are using.

Step 3: In git bash, we will initialise the box

Vagrant Box Initialisation

Step 4: Once the box has been initialised, a Vagrantfile that contains the configuration of the centos 7 operating system will be added to our directory. You can also modify the configurations as needed.

Vagrantfile configuration

Step 5: Once the configurations are good to go, bring up the operating system with vagrant using “vagrant up” command

Vagrant creation command
Here, your Vm is up and running as can be seen on Virtual box:

Virtual Box
Step 6: Using “Vagrant ssh”, we will be able to access and interact with the centos 7 machine

Vagrant SSH

You can also use “Vagrant halt” to pause the CentOS VM when not in use and “vagrant destroy” to delete the VM completely.

So there you have it, Techies😎. You can create VMs automatically in minutes with Vagrant🎊.
Thanks for reading! Please leave a comment.

Top comments (2)

Collapse
 
henriettatkr profile image
Henrietta Takor

Amazing!

Collapse
 
kjart profile image
Yusuf Khadijat

Thank you for reading