Skip to content

Commit

Permalink
template
Browse files Browse the repository at this point in the history
  • Loading branch information
bbaassssiiee committed Dec 11, 2024
1 parent 20970b0 commit fa84e14
Showing 1 changed file with 36 additions and 59 deletions.
95 changes: 36 additions & 59 deletions Vagrantfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,6 @@
# vagrant up

Vagrant.require_version ">= 2.0.0"

# Define environment variables DB_PASS and SSH_PASSPHRASE for your security
$DbPass = ENV['DB_PASS'] || "your_database_password"
$SshPassphrase = ENV['SSH_PASSPHRASE'] || "KeyWillBeGeneratedWithAPassphrase"

# Select the config file from the STAGE environment variable (dev or local)
# VM Configs are loaded from json files.
$Stage = ENV['STAGE'] || "dev"

# Require JSON module
require 'json'
# Read JSON file with config details
guests = JSON.parse(File.read(File.join(File.dirname(__FILE__), "inventory", $Stage, $Stage + ".json")))
# Local PATH_SRC for mounting
$PathSrc = ENV['PATH_SRC'] || "."
Vagrant.configure(2) do |config|

# check for updates of the base image
Expand All @@ -38,50 +23,42 @@ Vagrant.configure(2) do |config|
config.ssh.insert_key = false

# Iterate through entries in JSON file
guests.each do |guest|
config.vm.define guest['name'], autostart: guest['autostart'] do |srv|
srv.vm.box = guest['box']
srv.vm.hostname = guest['name']
# Hyper-V needs an _external_ network adapter, bound to a connected interface.
# srv.vm.network "public_network", type: "dhcp", bridge: "Wi-Fi"
# Better Hypervisors allow setting the IP
srv.vm.network 'private_network', ip: guest['ip_addr']
srv.vm.network :forwarded_port, host: guest['forwarded_port'], guest: guest['app_port']

# set no_share to false to enable file sharing
srv.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: guest['no_share']
srv.vm.provider "hyperv" do |hyperv|
hyperv.cpus = guest['cpu']
hyperv.memory = guest['memory']
hyperv.vmname = guest['name']
hyperv.enable_virtualization_extensions = true
hyperv.vm_integration_services = {
guest_service_interface: true,
heartbeat: true,
shutdown: true,
time_synchronization: true,
}
hyperv.linked_clone = true
end
srv.vm.provider :vmware_desktop do |vmware|
vmware.gui = guest['gui']
vmware.vmx['memsize'] = guest['memory']
vmware.vmx['numvcpus'] = guest['cpus']
end
srv.vm.provider :virtualbox do |virtualbox|
virtualbox.customize ["modifyvm", :id,
"--audio-driver", "none",
"--cpus", guest['cpus'],
"--memory", guest['memory'],
"--natnet1", "192.168.33.0/24",
"--graphicscontroller", "VMSVGA",
"--vram", "64"
]
virtualbox.gui = guest['gui']
virtualbox.name = guest['name']
end
end
config.vm.box = "ansiblebook/controller"
config.vm.hostname = "controller"
config.vm.network "public_network", type: "dhcp", bridge: "Wi-Fi"
config.vm.network :forwarded_port, host: 8443, guest: 443

# set no_share to false to enable file sharing
config.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
config.vm.provider "hyperv" do |hyperv|
hyperv.cpus = 2
hyperv.memory = 4096
hyperv.vmname = "controller"
hyperv.enable_virtualization_extensions = true
hyperv.vm_integration_services = {
guest_service_interface: true,
heartbeat: true,
shutdown: true,
time_synchronization: true,
}
hyperv.linked_clone = true
end
config.vm.provider :vmware_desktop do |vmware|
vmware.gui = false
vmware.vmx['memsize'] = 4096
vmware.vmx['numvcpus'] = 2
end
config.vm.provider :virtualbox do |virtualbox|
virtualbox.customize ["modifyvm", :id,
"--audio-driver", "none",
"--cpus", 2,
"--memory", 4096,
"--natnet1", "192.168.33.0/24",
"--graphicscontroller", "VMSVGA",
"--vram", "64"
]
virtualbox.gui = false
virtualbox.name = "controller"
end
# install ansible+controller in the VM
config.vm.provision "shell", privileged: false, path: "controller.sh", env: {"DB_PASS"=>$DbPass, "SSH_PASS"=>$SshPassphrase}
end

0 comments on commit fa84e14

Please sign in to comment.