cmdref.net - Cheat Sheet and Example

cmdref.net is command references/cheat sheets/examples for system engineers.

User Tools

Site Tools


Sidebar








Cloud



Etc


Reference














.

software:vargant:vagrantfile



PC Software

Vagrantfile Examples

Vagrantfile Sample : Adoptor1:NAT, Adoptor2: Bridge

  • public_network = Bridge Network
Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"

  #Adaptor2 :Bridged network with DHCP
  config.vm.network "public_network"

  config.vm.provider "virtualbox" do |v|
     v.memory = 512
     v.cpus = 1
  end

end
config.vm.network "public_network", ip: "192.168.0.2"


Vagrantfile Sample : Adoptor1:NAT, Adoptor2: Host Only

  • Default Network is NAT
  • private_network is host only network
Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"

  #Adaptor2 :host only network
  config.vm.network "private_network", type: "dhcp"


  config.vm.provider "virtualbox" do |v|
    v.memory = 512
    v.customize ["modifyvm", :id, "--cpus", "2"]
  end

end


Vagrantfile Sample : Adoptor1:NAT with portfoward

Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"

  #Adaptor1 : NAT with portforward
  config.vm.network "forwarded_port", guest: 80, host: 8080
  config.vm.network "forwarded_port", guest: 22, host: 10022

  config.vm.provider "virtualbox" do |v|
    v.memory = 512
    v.customize ["modifyvm", :id, "--cpus", "2"]
  end

end


Vagrantfile Sample : Using Local box file

Vagrant.configure("2") do |config|

  config.vm.box = "centos/7"
  config.vm.box_url = "file://../../virtualbox/CentOS-7-x86_64-Vagrant-1905_01.VirtualBox.box"

  config.vm.network "public_network"

  config.vm.provider "virtualbox" do |vb|
     vb.memory = "512"
     vb.cpus = 1
  end

end
Download from Web server
config.vm.box_url = "http://x.x.x.x/downloads/vagrant-boxes/CentOS-7-x86_64-Vagrant-1905_01.VirtualBox.box"


Vagrantfile Sample : MULTI-MACHINE

Vagrant.configure("2") do |config|
  config.vm.provision "shell", inline: "echo Hello"

  config.vm.define "web" do |web|
    web.vm.box = "apache"
  end

  config.vm.define "db" do |db|
    db.vm.box = "mysql"
  end
end
Vagrant.configure(2) do |config|

  config.vm.box = "xxxxx"

  config.vm.define :test1 do |cfg|
    cfg.vm.hostname = "test1"
    cfg.vm.network "private_network", ip: "192.168.10.11", virtualbox__intnet: "intnet"
  end

  config.vm.define :test2 do |cfg|
    cfg.vm.hostname = "test2"
    cfg.vm.network "private_network", ip: "192.168.10.12", virtualbox__intnet: "intnet"
  end

end
Vagrant.configure(2) do |config|
  config.vm.define "controller" do |node|
        node.vm.box = "centos/7"
        node.vm.hostname = "controller"
        node.vm.network :private_network, ip: "192.168.0.200"
        node.vm.network :forwarded_port, id: "ssh", guest: 22, host: 2200
  end
  config.vm.define "target" do |node|
        node.vm.box = "centos/7"
        node.vm.hostname = "target"
        node.vm.network :private_network, ip: "192.168.0.201"
        node.vm.network :forwarded_port, id: "ssh", guest: 22, host: 2201
  end
end


Vagrantfile Sample : Shell

Vagrant.configure("2") do |config|
  config.vm.define "host" do |node|
    node.vm.box = "bento/centos-7"
    node.vm.hostname = "host"
    node.vm.synced_folder "host", "/vagrant"
    node.vm.network :private_network, ip: "192.168.33.11"

    node.vm.provision "shell", inline: <<-SHELL
      sudo yum -y install epel-release
      sudo yum install -y gcc python-pip python-devel openssl-devel libffi-devel
      sudo pip install --upgrade pip setuptools
      sudo pip install ansible
    SHELL

  end




Vagrantfile Note

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
   config.vm.synced_folder "./data", "/vagrant_data"



software/vargant/vagrantfile.txt ยท Last modified: 2020/06/22 by admin

Page Tools