Creating the Vagrantfile
Optional Commands to Add Into Vagrantfile
Provisioning within a VM
Provisioning
Option #1 Multiple Machines Utilizing a LoopVagrant.configure("2") do |config| (2..4).each do |i| config.vm.define "vm-#{i}" do |web| web.vm.box = "ubuntu/trusty64" web.vm.network "private_network", ip: "192.168.33.#{i}", auto_config: false web.vm.provision "shell", inline: "echo hello #{i}" web.vm.synced_folder "code/", "/app/code" end end end Option #2.0 Multi-Machine w/ Private Network# -- mode: ruby -- # vi: set ft=ruby : # Every Vagrant development environment requires a box. You can search for # boxes at https://atlas.hashicorp.com/search. BOX_IMAGE = "bento/ubuntu-16.04" NODE_COUNT = 3 Vagrant.configure("2") do |config| ----config.vm.define "Ansible" do |subconfig| -------subconfig.vm.box = "ansible/tower" -------subconfig.vm.hostname="ansible" -------subconfig.vm.network :private_network, ip:"10.10.2.5" ----end Option 2.1 -- Continued From Above ----config.vm.define "node-01" do |subconfig| ------subconfig.vm.box = "generic/debian10" ------subconfig.vm.hostname="node-01" ------subconfig.vm.network :private_network, ip:"10.10.2.11" --end --config.vm.define "node2" do |subconfig| -----subconfig.vm.box = "generic/debian10" -----subconfig.vm.hostname="node-02" -----subconfig.vm.network :private_network, ip:"10.10.2.12" --end end Option #2.2 -- Continued From Above --# Install avahi on all machines --config.vm.provision "shell", inline: <<-SHELL apt-get install -y avahi-daemon libnss-mdns SHELL end |
Networking
Bridged Network
1 VM w/ Multiple Network Options
One VM | CentOs | 512 RAM | 1 CPU | Private IPVagrant.configure("2") do |config| config.vm.box = "bento/centos-7.2" config.vm.provider :virtualbox do |vb| vb.memory = 512 vb.cpus = 1 end config.vm.define "srv-1" do |config| config.vm.provision :shell, :inline => "ip addr | grep \"inet\" | awk '{print $2}'" config.vm.network "private_network", ip: "192.168.50.11", virtualbox__intnet: "true" end end Provisioning with Ansible
--Continuation from Above--config.vm.define "db" do |db| db.vm.box = "ubuntu/trusty64" db.vm.network "private_network", ip: "192.168.33.30" db.vm.synced_folder "data/", "/db/data" db.vm.provider "virtualbox" do |vb| vb.memory = 2048 vb.cpus = 1 end end end Multiple VMs within One VagrantfileVagrant.configure("2") do |config| config.vm.provision "shell", inline: "echo Hello" config.vm.define "web" do |web| web.vm.box = "ubuntu/trusty64" web.vm.network "private_network", ip: "192.168.33.20" web.vm.synced_folder "code/", "/app/code" web.vm.provider "virtualbox" do |vb| vb.memory = 1048 vb.cpus = 1 end end Thank You -
|
Cheatography
https://cheatography.com
Create a Vagrantfile Cheat Sheet (DRAFT) by boogie
Breakdown and explanation of some vagrantfile sections.
This is a draft cheat sheet. It is a work in progress and is not finished yet.