├── README.md ├── Vagrant-Error-Example.md ├── example1-basic └── Vagrantfile ├── example2-ipconfig └── Vagrantfile ├── example3-synced-folders └── Vagrantfile ├── example4-vb-memory └── Vagrantfile ├── example5-ansible └── Vagrantfile └── example6-shell └── Vagrantfile /README.md: -------------------------------------------------------------------------------- 1 | # Vagrant 2 | Vagrant is an excellent open source tool for managing virtual machines. Vagrant provides easy to configure, reproducible, and portable work environments built on top of industry-standard technology and controlled by a single consistent workflow to help maximize the productivity and flexibility of you and your team. 3 | 4 | ##Getting Started 5 | For the quick-start, we'll bring up a development machine on 6 | [VirtualBox](https://www.virtualbox.org/) because it is free and works 7 | on all major platforms. Vagrant can work with almost any 8 | system such as [OpenStack] (https://www.openstack.org/), [VMware] (https://www.vmware.com/), [Docker] (https://docs.docker.com/), etc. 9 | 10 | First, make sure your development machine has 11 | [VirtualBox](https://www.virtualbox.org/) 12 | installed. After this, 13 | [download and install the appropriate Vagrant package for your OS](https://www.vagrantup.com/downloads.html). 14 | 15 | To build your first virtual environment: 16 | 17 | vagrant init ubuntu/trusty64; 18 | vagrant up 19 | 20 | ## Vagrant boxes 21 | 22 | Boxes are the package format for Vagrant environments. A box can be used by anyone on any platform that Vagrant supports to bring up an identical working environment. Following for finding boxes. 23 | 24 | [Hashicorp](https://atlas.hashicorp.com/boxes/search) 25 | 26 | [Vagrantbox](http://www.vagrantbox.es/) 27 | 28 | 29 | ##Vagrant Commands List 30 | 31 |
vagrant init [box-name] [box-url]32 | Initializes the current directory to be a Vagrant environment with.vagrant directory if does not already exist. 33 | 34 |
vagrant up35 | For the starting the machine to create an enviroment. 36 | 37 |
vagrant status38 | For the showing machine status that is open or not. 39 | 40 |
vagrant halt41 | For the closeing the machine. 42 | 43 |
vagrant suspend44 | For the suspends a machine (remembers state). 45 | 46 |
vagrant provision47 | For the forceing reprovisioning of the machine 48 | 49 |
vagrant reload50 | For the restarting the machine with loads the new Vagrantfile configuration. 51 | 52 |
vagrant ssh53 | For the connecting to machine via SSH 54 | 55 |
vagrant share56 | For the sharing your VM and provides you with the public URL 57 | 58 |
vagrant login59 | Log in to HashiCorp's Atlas on your computer 60 | 61 |
vagrant destroy62 | For the deleteing the machine. 63 | 64 |
vagrant -v65 | For the knowing the version 66 | 67 |
vagrant global-status 68 | For the knowing state of all active environments on the system for the currently logged in user. 69 | 70 |
vagrant resume71 | For this resumeing a suspended machine (vagrant up works just fine for this as well) 72 | 73 |
vagrant reload --provision74 | For the restarting the machine and force provisioning. 75 | 76 |
vagrant push -- Yes77 | For the configuring to deploy code. 78 | -------------------------------------------------------------------------------- /Vagrant-Error-Example.md: -------------------------------------------------------------------------------- 1 | 2 | #Vagrant Error Example 3 | 4 | #### Error 01 : 5 | VirtualBox is complaining that the kernel module is not loaded. 6 |
7 | vagrant up 8 | The provider 'virtualbox' that was requested to back the machine 9 | 'default' is reporting that it isn't usable on this system. 10 | The reason is shown below: 11 | 12 | VirtualBox is complaining that the kernel module is not loaded. Please 13 | run `VBoxManage --version` or open the VirtualBox GUI to see the error 14 | message which should contain instructions on how to fix this error. 15 |16 | 17 | ####Solution 18 | Just run bellow command after that vagrant up again. 19 |
20 | sudo /etc/init.d/vboxdrv setup 21 |22 | 23 | OR 24 | 25 |
26 | sudo /usr/lib/virtualbox/vboxdrv.sh setup 27 |28 | -------------------------------------------------------------------------------- /example1-basic/Vagrantfile: -------------------------------------------------------------------------------- 1 | #basic Configuration 2 | Vagrant.configure(2) do |config| 3 | config.vm.box = "ubuntu/trusty64" 4 | config.vm.hostname = "raju.ghosh" 5 | end 6 | -------------------------------------------------------------------------------- /example2-ipconfig/Vagrantfile: -------------------------------------------------------------------------------- 1 | 2 | Vagrant.configure(2) do |config| 3 | 4 | #basic Configuration 5 | config.vm.box = "ubuntu/trusty64" 6 | config.vm.hostname = "raju.ghosh" 7 | 8 | # Private Network configr with port forwarded. 9 | config.vm.network "private_network", ip: "192.168.99.100" 10 | config.vm.network "forwarded_port", guest: 80, host: 8080 11 | 12 | end 13 | 14 | 15 | -------------------------------------------------------------------------------- /example3-synced-folders/Vagrantfile: -------------------------------------------------------------------------------- 1 | 2 | Vagrant.configure(2) do |config| 3 | 4 | # basic Configuration 5 | config.vm.box = "ubuntu/trusty64" 6 | config.vm.hostname = "raju.ghosh" 7 | 8 | # Folder sync 9 | config.vm.synced_folder "/home/raju/www/projects", "/projects" 10 | 11 | end 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /example4-vb-memory/Vagrantfile: -------------------------------------------------------------------------------- 1 | 2 | Vagrant.configure(2) do |config| 3 | 4 | # basic Configuration 5 | config.vm.box = "ubuntu/trusty64" 6 | config.vm.hostname = "raju.ghosh" 7 | 8 | #VirtualBox machines configuration 9 | config.vm.provider "virtualbox" do |vb| 10 | # Display the VirtualBox GUI when booting the machine 11 | vb.gui = true 12 | # VM is modified to have a host CPU execution cap of 50%, meaning that no matter how much CPU is used in the VM, no more than 50% would be used on your own host machine. 13 | v.customize ["modifyvm", :id, "--cpuexecutioncap", "50"] 14 | #VIRTUAL MACHINE NAME 15 | v.name = "my_vm" 16 | # Customize the amount of memory on the VM: 17 | vb.memory = "1024" 18 | end 19 | 20 | end 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /example5-ansible/Vagrantfile: -------------------------------------------------------------------------------- 1 | 2 | Vagrant.configure(2) do |config| 3 | 4 | # basic Configuration 5 | config.vm.box = "ubuntu/trusty64" 6 | config.vm.hostname = "raju.ghosh" 7 | 8 | # Run Ansible from the Vagrant Host 9 | config.vm.provision "ansible" do |ansible| 10 | ansible.playbook = "playbook.yml" 11 | end 12 | 13 | end -------------------------------------------------------------------------------- /example6-shell/Vagrantfile: -------------------------------------------------------------------------------- 1 | #basic Configuration 2 | Vagrant.configure(2) do |config| 3 | config.vm.box = "ubuntu/trusty64" 4 | config.vm.hostname = "raju.ghosh" 5 | 6 | # SHELL PROVISIONER Example 1 7 | config.vm.provision "shell", inline: <<-SHELL 8 | sudo apt-get update 9 | sudo apt-get install -y nginx 10 | SHELL 11 | 12 | # SHELL PROVISIONER Example 2 by bash file 13 | config.vm.provision "shell", path: "script.sh" 14 | 15 | # SHELL PROVISIONER Example 2 by remote bash 16 | config.vm.provision "shell", path: "https://example.com/provisioner.sh" 17 | 18 | end 19 | --------------------------------------------------------------------------------