proxy-setup-spinner/vms/px-001-Office-DB/Vagrantfile
Eliezer Croitoru d7ec0d2317 1
2024-02-07 23:57:14 +02:00

100 lines
2.6 KiB
Ruby

$ENALBE_SYNC_FOLDER = false
$ENALBE_SYNC_FOLDER = true if File.exist?("sync_shared")
if File.exist?("net1")
$HOST_NET_1 = File.readlines('net1').first.chomp
end
if File.exist?("net2")
$HOST_NET_2 = File.readlines('net2').first.chomp
end
if File.exist?("net3")
$HOST_NET_3 = File.readlines('net3').first.chomp
end
if File.exist?("net4")
$HOST_NET_4 = File.readlines('net4').first.chomp
end
$VM_NAME = File.readlines('vmname').first.chomp
$VM_MEM = File.readlines('vmmem').first.chomp.to_i
$VM_VCPU = File.readlines('vmcpu').first.chomp.to_i
$BOX = File.readlines('box').first.chomp
$HOSTNAME = File.readlines('hostname').first.chomp if File.exist?("hostname")
# Will not work on Hyper-V
#$VM_DISK_SIZE = File.readlines('disksize').first.chomp
$PROVISION_SSH_KEY_SCRIPT=<<EOF
mkdir -p /root/.ssh
chmod 0700 /root/.ssh
cat /home/vagrant/.ssh/vagrant.pub >> /root/.ssh/authorized_keys
chmod 0600 /root/.ssh/authorized_keys
chown root:root -R /root/.ssh
mkdir -p /home/vagrant/.ssh
chmod 0700 /home/vagrant/.ssh
echo /home/vagrant/.ssh/vagrant.pub >> /home/vagrant/.ssh/authorized_keys
chmod 0600 /home/vagrant/.ssh/authorized_keys
chown vagrant:vagrant -R /home/vagrant/.ssh
EOF
Vagrant.configure("2") do |config|
config.vm.box = $BOX
## Remember to generate the vagrant private key.
## ssh-keygen -f C:\Users\eliezer\.ssh\vagrant
config.ssh.insert_key = false
config.ssh.private_key_path = ['~/.ssh/vagrant', '~/.vagrant.d/insecure_private_key' ]
config.vm.provider "hyperv" do |hv, override|
hv.vmname = $VM_NAME
hv.maxmemory = $VM_MEM
hv.memory = $VM_MEM
hv.cpus = $VM_VCPU
override.vm.allowed_synced_folder_types = [:rsync]
end
if $HOST_NET_1 and !$HOST_NET_1.empty?
config.vm.network "public_network", bridge: $HOST_NET_1
end
if $HOST_NET_2 and !$HOST_NET_2.empty?
config.vm.network "private_network", bridge: $HOST_NET_2
end
if $HOST_NET_3 and !$HOST_NET_4.empty?
config.vm.network "private_network", bridge: $HOST_NET_3
end
if $HOST_NET_4 and !$HOST_NET_4.empty?
config.vm.network "private_network", bridge: $HOST_NET_4
end
config.vm.synced_folder ".", "/vagrant", disabled: true
if $ENALBE_SYNC_FOLDER == true
config.vm.synced_folder "shared/", "/vagrant", type: "rsync"
end
if !$HOSTNAME.empty?
config.vm.provision 'shell', inline: "hostnamectl set-hostname #{$HOSTNAME}"
end
config.vm.provision "file", source: "~/.ssh/vagrant.pub", destination: "/home/vagrant/.ssh/vagrant.pub"
config.vm.provision 'shell', inline: $PROVISION_SSH_KEY_SCRIPT
if $ENALBE_SYNC_FOLDER == true
config.vm.provision 'shell', inline: "stat /vagrant/init.sh && cd /vagrant && bash init.sh;true"
end
end