Skip to content

Instantly share code, notes, and snippets.

@LukeCAutomate
Last active September 21, 2024 00:17
Show Gist options
  • Save LukeCAutomate/f2789ba1ad8aa67e731a02c261ea61d4 to your computer and use it in GitHub Desktop.
Save LukeCAutomate/f2789ba1ad8aa67e731a02c261ea61d4 to your computer and use it in GitHub Desktop.
DBA Challenges - vagrantfile used for September 2024 challenges
=begin
Copyright © 2024 AutomateSQL, LLC
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the “Software”), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit persons to
whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
=end
DCIpAddress = '192.168.88.3' #This will be the internal DNS / Domain Controller's IP address that all other machines use.
Vagrant.configure("2") do |config|
machines = [
{ name: "DC1", memory: 4096, cpus: 4, vnet: "VMnet8", nat_device: "vmnet8" } ,
{ name: "SRV1", memory: 8192, cpus: 4, vnet: "VMnet8", nat_device: "vmnet8" },
{ name: "STORSRV1", memory: 4096, cpus: 4, vnet: "VMnet8", nat_device: "vmnet8", second_nic: { ip: "10.0.1.1", second_vnet: "VMnet9", nic_name: "iSCSI_NET"}},
{ name: "CLUSTER1SRV1", memory: 16384, cpus: 8, vnet: "VMnet8", nat_device: "vmnet8", second_nic: { ip: "10.0.1.2", second_vnet: "VMnet9", nic_name: "iSCSI_NET"}, third_nic: {ip: "172.16.0.1", third_vnet: "VMnet4", nic_name: "Heartbeat"} },
{ name: "CLUSTER1SRV2", memory: 16384, cpus: 8, vnet: "VMnet8", nat_device: "vmnet8", second_nic: { ip: "10.0.1.3", second_vnet: "VMnet9", nic_name: "iSCSI_NET"}, third_nic: {ip: "172.16.0.2", third_vnet: "VMnet4", nic_name: "Heartbeat"} }
]
config.vm.usable_port_range = 8500..8999
config.vm.communicator = "winrm"
config.vm.box = "automatesql/win2022"
config.winrm.username = "Administrator"
config.winrm.password = "Sign up for the DBA Challenges newsletter at http://www.dbachallenges.com!"
config.winrm.max_tries = 300
config.winrm.retry_delay = 5
config.winrm.ssl_peer_verification = false
#Loop through the machines and configure each one
machines.each do |machine|
config.vm.define machine[:name] do |node|
node.vm.provision "shell",
run: "once",
name: "set-dns",
inline: "get-netadapter -name Ethernet0 | set-DnsClientServerAddress -ServerAddresses #{DCIpAddress}",
privileged: true
node.vm.provision "shell",
run: "once",
name: "Set hostname",
inline: "powershell rename-computer -NewName '#{machine[:name]}' -Restart",
privileged: true
#here we'll configure the second nic
if machine[:second_nic]
node.vm.provision "shell",
run: "once",
name: "set ip",
inline: "get-netadapter -name Ethernet1 | new-NetIPAddress -IPAddress #{machine[:second_nic][:ip]} -PrefixLength 24",
privileged: true
node.vm.provision "shell",
run: "once",
name: "rename nic",
inline: "rename-netadapter -name Ethernet1 -newname #{machine[:second_nic][:nic_name]}",
privileged: true
end
#here we'll configure the third nic
if machine[:third_nic]
node.vm.provision "shell",
run: "once",
name: "set ip",
inline: "get-netadapter -name Ethernet2 | new-NetIPAddress -IPAddress #{machine[:third_nic][:ip]} -PrefixLength 29",
privileged: true
node.vm.provision "shell",
run: "once",
name: "rename nic",
inline: "rename-netadapter -name Ethernet2 -newname #{machine[:third_nic][:nic_name]}",
privileged: true
end
node.vm.provider "vmware_desktop" do |mybasebox|
mybasebox.gui = true
mybasebox.allowlist_verified = :disable_warning
#mybasebox.port_forward_network_pause = 20
mybasebox.nat_device = machine[:nat_device]
mybasebox.vmx["displayname"] = machine[:name]
mybasebox.vmx["memsize"] = machine[:memory]
mybasebox.vmx["numvcpus"] = machine[:cpus]
mybasebox.vmx["cpuid.coresPerSocket"] = machine[:cpus]
mybasebox.vmx["vvtd.enable"] = "TRUE"
mybasebox.vmx["vhv.enable"] = "TRUE"
mybasebox.vmx["vpmc.enable"] = "TRUE"
mybasebox.vmx["ethernet0.connectiontype"] = "custom"
mybasebox.vmx["ethernet0.vnet"] = machine[:vnet]
#add second nic if needed - Currently using this nic for iSCSI traffic.
if machine[:second_nic]
mybasebox.vmx["ethernet1.connectiontype"] = "custom"
mybasebox.vmx["ethernet1.vnet"] = machine[:second_nic][:second_vnet]
mybasebox.vmx["ethernet1.present"] = "TRUE"
mybasebox.vmx["ethernet1.virtualDev"] = "e1000e"
end
#add third nic if needed - Currently using this nic for cluster heartbeat traffic.
if machine[:third_nic]
mybasebox.vmx["ethernet2.connectiontype"] = "custom"
mybasebox.vmx["ethernet2.vnet"] = machine[:third_nic][:third_vnet]
mybasebox.vmx["ethernet2.present"] = "TRUE"
mybasebox.vmx["ethernet2.virtualDev"] = "e1000e"
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment