Showing posts with label Z3_Vagrant. Show all posts
Showing posts with label Z3_Vagrant. Show all posts

Sunday, February 16, 2020

Vagrant Plugins

1: The disksize plugin
Ever created a VM with a specific size for the disk and after using it for a while, you find out you would have liked to have a larger size disk? You can resize the VDI in for example.
you can ask Vagrant to give you the disk size you want to have?
Enter the vagrant-disksize plugin.
Install it with
vagrant plugin install vagrant-disksize
And you can use it in your Vagrant file like:
config.disksize.size = '75GB'
It will figure out what to do and do it!

2: The vbguest plugin
Getting tired of installing guest additions after each and every new installation and keeping them updated after a new version of VirtualBox is released? Mounting an ISO, installing the required dependencies, running the installer… You don’t have to worry about those things anymore! The vagrant-vbguest plugin takes care of this for you.
Install it with:
vagrant plugin install vagrant-vbguest
And add to your Vagrantfile a line like:
config.vbguest.auto_update = true
This installs the correct version of the guest additions and also installs dependencies if required to for example build the module.

3: Install missing plugins
If I want to share a Vagrantfile, When my Vagrantfile depends on plugins such as above, it won’t work if they are missing. Luckily installing missing plugins is easy to automate within your Vagrantfile like below:
unless Vagrant.has_plugin?("vagrant-disksize")
puts 'Installing vagrant-disksize Plugin...'
system('vagrant plugin install vagrant-disksize')
end
unless Vagrant.has_plugin?("vagrant-vbguest")
puts 'Installing vagrant-vbguest Plugin...'
system('vagrant plugin install vagrant-vbguest')
end
unless Vagrant.has_plugin?("vagrant-reload")
puts 'Installing vagrant-reload Plugin...'
system('vagrant plugin install vagrant-reload')
end


This way you don’t have to first install the plugins before you can use the Vagrantfile. Inspiration from the Oracle provided Vagrantfiles here.

4: Execute a command once after a reboot
Suppose you want to have a specific command executed only once after a reboot. This can happen because a specific command could require certain files not to be in use or for example the vagrant user not to be logged in. You can do this with a pre-script (prepare), the reload plugin and a post script (cleanup). The below example should work for most Linux distributions:
Inside your Vagrantfile:
config.vm.provision :shell, path: "prescript.sh"
config.vm.provision :reload
config.vm.provision :shell, path: "postscript.sh"
Pre-script: prescript.sh
chmod +x /etc/rc.d/rc.local
echo ‘COMMAND_YOU_WANT_TO_HAVE_EXECUTED’ >> /etc/rc.d/rc.local
Post-script: postscript.sh
chmod -x /etc/rc.d/rc.local
sed -i ‘$ d’ /etc/rc.d/rc.local

The pre-script adds a line to rc.local and makes it executable. The postscript removes the line again.

5: Installing docker and docker-compose
For installing docker and docker-compose (and running containers) there are 3 main options.
Using Vagrant plugins
This is the easiest option and does not require specific provisioning file entries. The Docker provisioner is provided as part of Vagrant out of the box. Docker-compose requires the installation of a plugin.
vagrant plugin install vagrant-docker-compose
Inside your Vagrantfile
config.vm.provision :docker
config.vm.provision :docker_compose

Using these plugins, you might have to look into how you can force it to use a specific version should you require it.
Using a provisioning script and OS repositories

Saturday, December 26, 2015

Vagrant Commands



What is Vagrant ?
  • Vagrant is a tool that uses Oracle's VirtualBox to dynamically build configurable, lightweight, and portable virtual machines. 
  • Vagrant supports the use of either Puppet or Chef for managing the configuration.
vagrant -v 

vagrant up, halt 
- up is used to create & configure your guest environment/machines based on  your  vagrantfile.
- halt bring down the environment Vagrant is managing.

vagrant status
- status of the Vagrant managed machines.

vagrant reload
-  apply Vagrant configuration changes (like port forwarding) without rebuilding the VM.

vagrant suspend, resume
- saves the state of the current VM.- resume will load up the suspended VM.

vagrant init, destroy 
- init initializes a project to use Vagrant
- Beware. This command will bring down the environment if running and then destroys
all of the resources that were created along with the initial creation.

vagrant push
- Vagrant can be configured to deploy code !

vagrant ssh 

- SSH into your Vagrant running machines.

vagrant login 
- log into Vagrant cloud (Atlas).

vagrant share 
- Do form folder with vagrantfile

vagrant global-status
- List all VMs status anywhere on the system.

vagrant gem
- install Vagrant plugins via RubyGems

vagrant box (add, list, remove) 

- vagrant box add, allows you to install a box (or VM) to the local machine
-  vagrant box remove, a box from the local machine
-  vagrant box list, the locally installed Vagrant boxes

vagrant -help 
- That will provide man pages for a Vagrant command.

Configuration Management Tool : Puppet,  Chef, Ansible, Salt, Docker
vagrant provision, reload --provision 
- provisioning runs on up only

Create own boxes with vagrant or packer
vagrant package
- To create a distribution of the vm you have running.

Vagrant plugin list : click here
vagrant plugin install vagrant-berkshelf
vagrant plugin install vagrant-hostmanager
vagrant plugin install vagrant-omnibus

Vagrant Boxes List : click here

Vagrant Example :

vagrant box add precise32 http://files.vagrantup.com/precise32.box
vagrant init precise32
vagrant up
vagrant ssh
vagrant reload
vagrant provision