Skip to content

Instantly share code, notes, and snippets.

@PoplarYang
Last active August 11, 2019 06:21
Show Gist options
  • Select an option

  • Save PoplarYang/f829e9f4a2f17916f288a0dab905dbaf to your computer and use it in GitHub Desktop.

Select an option

Save PoplarYang/f829e9f4a2f17916f288a0dab905dbaf to your computer and use it in GitHub Desktop.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |node|
(1..3).each do |index|
node.vm.define "node#{index}" do |config|
# box config
config.vm.box = "centos/7"
config.vm.box_check_update = false
config.vm.post_up_message = "Hello, welcome to server power by vagrant."
# network config
config.vm.network "forwarded_port", guest: 80, host: "707#{index}", host_ip: "0.0.0.0"
config.vm.network "private_network", ip: "10.10.10.2#{index}"
# file sync
config.vm.synced_folder "/data", "/root/deploy"
config.vm.hostname = "node#{index}"
config.vm.provider "virtualbox" do |vb|
# Display the VirtualBox GUI when booting the machine
vb.gui = false
# cpu
vb.cpus = 2
# Customize the amount of memory on the VM:
vb.memory = "8192"
file_to_disk = "/disk2/node1/vd#{index}.vdi"
vb.customize ["storagectl", :id, "--name", "SATA Controller", "--add", "sata", "--controller", "IntelAHCI"]
unless File.exist?(file_to_disk)
vb.customize ["createhd", "--filename", file_to_disk, "--size", 100 * 1024, "--format", "VDI"]
end
vb.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", 0, "--device", 0, "--type", "hdd", "--medium", file_to_disk]
end
config.vm.provision "shell", inline: <<-SHELL
echo "hello vagrent."
echo "$(id)"
SHELL
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment