-
Notifications
You must be signed in to change notification settings - Fork 39
/
Vagrantfile
98 lines (95 loc) · 3.68 KB
/
Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
ENV['VAGRANT_EXPERIMENTAL'] = 'typed_triggers'
require 'open3'
VM_CPU = 4
VM_MEMORY_GB = 4
VM_ROOT_DISK_SIZE_GB = 128
Vagrant.configure('2') do |config|
config.vm.box = 'proxmox-ve-amd64'
#config.vm.box = 'proxmox-ve-uefi-amd64'
config.vm.provider :libvirt do |lv, config|
lv.memory = VM_MEMORY_GB*1024
lv.cpus = VM_CPU
lv.cpu_mode = 'host-passthrough'
lv.nested = true
lv.keymap = 'pt'
lv.machine_virtual_size = VM_ROOT_DISK_SIZE_GB
config.vm.synced_folder '.', '/vagrant', type: 'nfs', nfs_version: '4.2', nfs_udp: false
end
config.vm.provider :hyperv do |hv, config|
hv.vmname = "#{File.basename(File.dirname(File.dirname(__FILE__)))}-example"
hv.linked_clone = true
hv.enable_virtualization_extensions = true # nested virtualization.
hv.memory = VM_MEMORY_GB*1024
hv.cpus = VM_CPU
hv.vlan_id = ENV['HYPERV_VLAN_ID']
# set the management network adapter.
# see https://github.com/hashicorp/vagrant/issues/7915
# see https://github.com/hashicorp/vagrant/blob/10faa599e7c10541f8b7acf2f8a23727d4d44b6e/plugins/providers/hyperv/action/configure.rb#L21-L35
config.vm.network :private_network, bridge: ENV['HYPERV_SWITCH_NAME'] if ENV['HYPERV_SWITCH_NAME']
config.vm.synced_folder '.', '/vagrant',
type: 'smb',
smb_username: ENV['VAGRANT_SMB_USERNAME'] || ENV['USER'],
smb_password: ENV['VAGRANT_SMB_PASSWORD']
# further configure the VM (e.g. add the secondary network adapter for
# the :private_network that is defined bellow).
config.trigger.before :'VagrantPlugins::HyperV::Action::StartInstance', type: :action do |trigger|
trigger.ruby do |env, machine|
system(
'PowerShell',
'-NoLogo',
'-NoProfile',
'-ExecutionPolicy',
'Bypass',
'-File',
'configure-hyperv.ps1',
machine.id
)
end
end
end
config.vm.provider :vsphere do |vsphere, config|
vsphere.name = ENV['VSPHERE_VM_NAME']
vsphere.notes = "Created from #{__FILE__}"
vsphere.cpu_count = VM_CPU
vsphere.memory_mb = VM_MEMORY_GB*1024
vsphere.user = ENV['GOVC_USERNAME']
vsphere.password = ENV['GOVC_PASSWORD']
vsphere.insecure = true
vsphere.host = ENV['GOVC_HOST']
vsphere.data_center_name = ENV['GOVC_DATACENTER']
vsphere.compute_resource_name = ENV['GOVC_CLUSTER']
vsphere.data_store_name = ENV['GOVC_DATASTORE']
vsphere.template_name = ENV['VSPHERE_TEMPLATE_NAME']
vsphere.vm_base_path = ENV['VSPHERE_VM_FOLDER']
vsphere.vlan = ENV['VSPHERE_VLAN']
if ENV['VAGRANT_SMB_PASSWORD']
config.vm.synced_folder '.', '/vagrant',
type: 'smb',
smb_username: ENV['VAGRANT_SMB_USERNAME'] || ENV['USER'],
smb_password: ENV['VAGRANT_SMB_PASSWORD']
end
config.trigger.after :'VagrantPlugins::VSphere::Action::Clone', type: :action do |trigger|
trigger.ruby do |env, machine|
stdout, stderr, status = Open3.capture3(
'bash',
'configure-vsphere.sh',
machine.id,
"#{VM_ROOT_DISK_SIZE_GB}",
"#{ENV['VSPHERE_VLAN']}")
if status.exitstatus != 0
raise "failed to configure vsphere. status=#{status.exitstatus} stdout=#{stdout} stderr=#{stderr}"
end
end
end
end
ip = '10.10.10.2'
config.vm.network :private_network,
ip: ip,
auto_config: false,
libvirt__dhcp_enabled: false,
libvirt__forward_mode: 'none'
config.vm.provision :shell, path: 'provision.sh', args: ip
config.vm.provision :shell, path: 'provision-pveproxy-certificate.sh', args: ip
config.vm.provision :shell, path: 'provision-containers.sh', args: ip
config.vm.provision :shell, path: 'summary.sh', args: ip
end