Command cheat sheet for vagrant

Few months back, I wrote article on vagrant usage which basically covers the very brief introduction to vagrant.

I started learning about ansible, again I need to visit the basic concept of vagrant to make my learning quick with ansible.  In this post, I am just going to list the commands and codes which I am going to use most of the time :

Commands :

1) We already know that we can create a file using “vagrant init” if we want to re-create file in the same directory and without any comments.

# vagrant init -f -m

2) Creating file specifying the name of box.

# vagrant init -f rhel-7.2

You need to replace the name with your box name.

3) To check the global status of all vagrant boxes.

# vagrant global-status

4) Checking the port mapping between host and vagrant guest.

# vagrant port <guest name>

This command doesn’t work for libvirtd provider, I have used this command with Virtualbox provider.

5) Commands to destroy, shutdown or suspend the vagrant environment.

# vagrant suspend
# vagrant halt
# vagrant destroy

Code tips :

1) Enabling the port forwarding and running a script while bringing up the vagrant box.

Vagrant.configure(“2”) do |config| = “rhel-7.2”
config.vm.provision :shell, path: “” :forwarded_port, guest: 80, host: 4567

Above stanza can be changed if we want to avoid any sort of port conflict while spawning multiple instances.

Vagrant.configure(“2”) do |config| = “rhel-7.2”
config.vm.provision :shell, path: “” :forwarded_port, guest: 80, host: 4567

auto_correct: true

2) script will run only once when you brought up the vagrant instance. To run that script again.

# vagrant up –provision
# vagrant provision
# vagrant reload –provision

3) If we want to bring the vagrant instance up without running mentioned script.

# vagrant up –no-provision

4) Running a particular box version.

Vagrant.configure(“2”) do |config| = “rhel-7.2”
config.vm.box_version = “1.1.0”

I will keep on adding more hacks into this article.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s