vagrant
Contents
Vagrant can be used for automatically provisioning VMs, and even whole development environments.
On ubuntu host:
1 | $ sudo apt install vagrant |
Components
- Providers:
- Backend of Vagrant
- VirtualBox
- VMware
- Hyper-V
- vCloud
- AWS
- Boxes:
- Predefined images
- Public Vagrant box catalog
- Vagrantfile:
- A Ruby file
- How many VMs
- Configure VMs
- Provision VMs
- Committed to version control
- Provisioners:
- Automatically install software, alter configurations
- Boxes may not be a complete use case for you
- Multiple options
- Shell Script
- Ansible
- Chef
- Docker
- Puppet
Operations
- Adding a vagrant box:
- Syntax: vagrant box add
- Example: vagrant box add ubuntu/trusty32
- Syntax: vagrant box add
- Listing and removing vagrant boxes:
- vagrant box list
- vagrant box remove
- Creating a VM environment:
- Syntax: vagrant init
- Example: vagrant init ubuntu/trusty32
- Syntax: vagrant init
- Starting a VM environment:
- vagrant up ubuntu/trusty32
- vagrant up
- Connecting:
- vagrant ssh ubuntu/trusty32
- vagrant ssh
- Stopping, restarting, and destroying
- vagrant halt
- vagrant reload
- vagrant destroy
Provisioning of vagrant
Creating a VM and provisioning it with Apache installed and prot forwarding
Add theses lines in Vagrantfile:
1
2config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.provision 'shell', path: 'provision.sh'Create provision.sh file with these entries:
- sudo apt-get update
- sudo apt-get install -y apache2
Destroy and start the virtual machine:
- vagrant destroy
- vagrant up