Vagrant.
Vagrant is a tool for building and managing virtual machine environments in a single workflow. Visit https://www.vagrantup.com/ to download and learn more about Vagarnt In a nutshell Vagrant allows for quick and easy deployment of virtual machines and alleviates the hussle of manually setting up virtual machines. A single vagrant box allows you to deploy several instance of the virtual machine with ease.Getting JunOS on Vagrant
Pre-requisites
- Virtualbox is installed on host machine
- Vagrant is installed on host machine
- Git is installed on host machine https://git-scm.com/downloads
- Existing github account https://github.com/
Initial setup
1. Setting up Git
- Create a directory for your project from terminal (linux) or cmd (windows)
$ mkdir vagranttest $ cd vagranttest
Link your github account
$ git config --global user.name "github_username" $ git config --global user.email "email_address"
Clone below git this will create new directory
vagrant-junos/
$ git clone https://github.com/JNPRAutomate/vagrant-junos.git
Go to this directory
$ cd vagrant-junos/
2. Install Vagrant plugin for junos
$ vagrant plugin install vagrant-junos
$ vagrant plugin install vagrant-host-shell
3. Check the Vagrant machine status
$ vagrant status
This completes the initial setup. See below image for reference of the above procedures
Downloading the box
Run the below command to download and start the vagrant box
$ vagrant up
Once the box is downloaded it will boot. Verify the status by running the command
$ vagrant status
Test login to the machine
$ vagrant ssh
Creating topology
The above process has created the base box which runs JunOS 12.1X47-D15.4. In a lab environment you may want to add more and create a topology to work with.
To add more machines edit the vagrantfile
created in the vagrant-junos/ directory
Contents of vagrantfile
Sample topology
Below is an example of vagrantfile
that creates the shown topology
Testing the topology
Checking the vagrant status you will have now have two devices r1 and r2
Use command vagrant up
to boot both VMs, to boot one of them for example booting r2 only use command vagrant up r2
After the VMs boot up you can confirm their status by command vagrant status
and you can login and do your work on them.
To shutdown the VMs use command vagrant halt
Creating Vagrant Box From Existing VM
Pre-requisites
- Vagrant is installed on the host machine; download https://www.vagrantup.com/downloads.html
- Virtual box is installed on the host machine; download https://www.virtualbox.org/wiki/Downloads
- Existing VM is installed in virtual box
- Windows Host machine
Procedures
Assign the first interface of the virtual machine to NAT interface This is done via virtual box network adapter settings
Power on the virtual machine
After booting, create a user and enable ssh access in the vitual machine then shutdown the VM
create a working directory on the host machine
Go to the directory and open command line, issue commands
$ vagrant package --base=<name of virtual machine within virtual box> --output=<custom name of box>
Wait for response and run below command
$ vagrant box add <custom name of box>.box --name=<custom name>
Wait for response
$ vagrant init
- This will create a file
vagrantfile
in the directory
Use text editor to edit the vagrantfile created by above command in step number (5) to specify username and password
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # All Vagrant configuration is done here. The most common configuration # options are documented and commented below. For a complete reference, # please see the online documentation at vagrantup.com. # Every Vagrant virtual environment requires a box to build off of. config.vm.box = "centos64" config.ssh.username="uaccount" config.ssh.password="passw0rd"
The vagrant box is created successfully and to start the machine run the command
$ vagrant up