Quick introduction to vagrant

I really like using vagrant on my laptop to test things out as it is so simple to spin up test machines, a few things have changed recently.

If you are using this on a Mac, the default place for you files are ~/.vagrant.d/boxes, always good to store the machines in a separate directory depending on the project you are working on.  I use this along with virtual box, this does the spinning up you don't actually interface with it

The first thing before you can download the boxes etc you need to create an account, the website for all the information and to be able to create an account is - https://www.vagrantup.com/docs/vagrant-cloud/

Once you have your account login, from the command line type

vagrant login

From here you put in all your login details then you are good to go to download the boxes you want.

I use centos when testing somethings, so I type vagrant box add centos/7.  You may find this link helpful - https://www.vagrantup.com/intro/getting-started/boxes.html

Once you know you have the box downloaded, you are ready to start to fire up your first box.  You should create a directory, call it test_server1, change into that directory and initialise the machine.

mkdir test_server1
cd test_server1
vagrant init

This will then create you a basic Vagrantfile, this is like the main config file for the server, there are many things you can change in here when provisioning the machine, for now let's leave it as it is and start the machine, from the command line type vagrant up.

This will build and start the machine up.

Once the machine has been started you can connect to the machine by typing vagrant ssh.  Now you are at the prompt of the linux machine, now you can play until your heart is content.

Once you have several machines running from the one directory, there is a simple way to check the status of those, switch to the directory and type

MacBook-Air:appdb $ vagrant status
Current machine states:
app1                      poweroff (virtualbox)
app2                      poweroff (virtualbox)
db                        poweroff (virtualbox)
This environment represents multiple VMs. The VMs are all listed
above with their current state. For more information about a specific
VM, run `vagrant status NAME`.

To stop a machine, while you are in the directory you can type vagrant halt.  This will power the machine off.

If you want to check the status of all of the machines you have

If you wanted to check the status of all the vagrant machines on your box you can use vagrant global-status, this shows ALL machines and their statuses

MacBook-Air:appdb $ vagrant global-status
id       name    provider   state    directory                              
-----------------------------------------------------------------------------
900ab57  default virtualbox poweroff /Users/ansible-book            
5427642  default virtualbox running  /Users/.vagrant.d/boxes        
2f4e5dc  default virtualbox poweroff /Users/.vagrant.d/boxes/test1  
0a42ded  default virtualbox poweroff /Users/.vagrant.d/boxes/test2  
d2d82e0  default virtualbox poweroff /Users/.vagrant.d/boxes/centos
90ae4e5  app1    virtualbox poweroff /Users/.vagrant.d/boxes/appdb  
a1f117a  app2    virtualbox poweroff /Users/.vagrant.d/boxes/appdb  
481b13d  db      virtualbox poweroff /Users/.vagrant.d/boxes/appdb  

The above shows information about all known Vagrant environments on this machine. This data is cached and may not be completely up-to-date. To interact with any of the machines, you can go to that directory and run Vagrant, or you can use the ID directly with Vagrant commands from any directory. For example:

"vagrant destroy 1a2b3c4d”

We will continue this week with some ways you can change IP addresses of the machines of test ansible scripts, anything in particular you want to see?

I am always interested in your thoughts so if you have any comments or feedback then please feel free to add any comments, or you can mail me  here.

Related Posts Plugin for WordPress, Blogger... 

 

Mantis Malware

Trying to update setuptools 39.1.0