Vagrant making VMs setup easy
Vagrant enables users to create and configure lightweight, reproducible, and portable development environments.
$ sudo dnf install vagrant -y
Last metadata expiration check: 2:10:16 ago on Sunday 25 March 2018 06:58:56 PM IST.
Package vagrant-1.9.1-3.fc26.noarch is already installed, skipping.
Dependencies resolved.
Nothing to do.
Complete!
$ vagrant init centos/7
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment!
$ vagrant plugin install vagrant-rekey-ssh ; vagrant plugin install vagrant-mutate ; vagrant plugin install vagrant-libvirt
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.define :one do |one|
one.vm.box = "centos/7"
one.vm.box_check_update = false
one.vm.network "forwarded_port", guest: 80, host: 8080
one.vm.network "private_network", ip: "192.168.122.100"
one.vm.hostname = "one.vagrant.box"
config.vm.provider "libvirt" do |libvirt|
libvirt.connect_via_ssh = false
libvirt.username = "cipher"
libvirt.storage_pool_name = "default"
libvirt.memory = "420"
libvirt.driver = "kvm"
end
end
config.vm.define :two do |two|
two.vm.box = "centos/7"
two.vm.box_check_update = false
two.vm.network "forwarded_port", guest: 80, host: 8081
two.vm.network "private_network", ip: "192.168.122.101"
two.vm.hostname = "two.vagrant.box"
config.vm.provider "libvirt" do |libvirt|
libvirt.connect_via_ssh = false
libvirt.username = "cipher"
libvirt.storage_pool_name = "default"
libvirt.memory = "420"
libvirt.driver = "kvm"
end
end
end$ vagrant up
Bringing machine 'one' up with 'libvirt' provider...
Bringing machine 'two' up with 'libvirt' provider...
==> one: Creating image (snapshot of base box volume).
==> two: Creating image (snapshot of base box volume).
==> one: Creating domain with the following settings...
==> one: -- Name: cipher_one
==> one: -- Domain type: kvm
==> one: -- Memory: 420M
==> two: -- Name: cipher_two
==> two: -- Domain type: kvm
$ vagrant status
Current machine states:
one running (libvirt)
two running (libvirt)
$ vagrant ssh one
[vagrant@one ~]$ hostname
one.vagrant.box
$ vagrant ssh two
[vagrant@two ~]$ hostname
two.vagrant.box
Related Articles
Vagrant making VMs setup easy
Vagrant enables users to create and configure lightweight, reproducible, and portable development environments.
How We Set Up Our KVM Hypervisor: From Bare Metal to Production-Ready VM Host
Detailed walkthrough of building a dedicated KVM/libvirt hypervisor with XFS tuning, hugepages, 10GbE tuning, and automation.
Building a Predictable KVM Infrastructure: From Chaos to Control
How to engineer a predictable KVM-based infrastructure focusing on repeatability, observability, and operational safety.