-
Notifications
You must be signed in to change notification settings - Fork 1
/
vagrantfile_ansible_roles-virtualbox_drives
135 lines (123 loc) · 5.41 KB
/
vagrantfile_ansible_roles-virtualbox_drives
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# Get current role name, and append branch name and build number if set
# Give the virtualbox name a timestamp plus random to prevent naming collision
current_role = File.basename(File.expand_path("..", Dir.pwd))
# Strip special characters
current_role = current_role.gsub(/[^A-Za-z0-9 ]/, '')
# Add timestamp and random
current_role << "-#{Time.now.to_i}-#{rand(999)}"
# Make vagrantfile directory to put our disks in if it doesn't exist
if not FileTest::directory?("./.vagrant")
Dir::mkdir("./.vagrant")
end
# Add some test hard drives
sdb = './.vagrant/sdb.vdi'
sdc = './.vagrant/sdc.vdi'
sdd = './.vagrant/sdd.vdi'
Vagrant.configure("2") do |config|
# install plugins
config.vagrant.plugins = ['vagrant-vbguest']
puts "Configuring proxy settings..."
if Vagrant.has_plugin?("vagrant-proxyconf")
puts "Found vagrant-proxyconf plugin - Now checking environment variables..."
if ENV["http_proxy"]
puts "http_proxy is set to: " + ENV["http_proxy"]
config.proxy.http = ENV["http_proxy"]
elsif ENV["HTTP_PROXY"]
puts "HTTP_PROXY is set to: " + ENV["HTTP_PROXY"]
config.proxy.http = ENV["HTTP_PROXY"]
end
if ENV["https_proxy"]
puts "https_proxy is set to: " + ENV["https_proxy"]
config.proxy.https = ENV["https_proxy"]
elsif ENV["HTTPS_PROXY"]
puts "HTTPS_PROXY is set to: " + ENV["HTTPS_PROXY"]
config.proxy.https = ENV["HTTPS_PROXY"]
end
if ENV["no_proxy"]
puts "no_proxy paths set to: " + ENV["no_proxy"]
config.proxy.no_proxy = ENV["no_proxy"] + ",172.28.0.1/16"
elsif ENV["NO_PROXY"]
puts "NO_PROXY paths set to: " + ENV["NO_PROXY"]
config.proxy.no_proxy = ENV["NO_PROXY"] + ",172.28.0.1/16"
end
end
config.vm.define "noble", autostart: false do |noble|
# Virtualbox provider
noble.vm.provider "virtualbox" do |v, override|
# Ubuntu Noble 24.04
v.name = current_role
override.vm.box = "bento/ubuntu-24.04"
# Add extra drives
unless File.exist?(sdb)
v.customize ['createhd', '--filename', sdb, '--size', 1 * 1024]
end
unless File.exist?(sdc)
v.customize ['createhd', '--filename', sdc, '--size', 1 * 1024]
end
unless File.exist?(sdd)
v.customize ['createhd', '--filename', sdd, '--size', 1 * 1024]
end
v.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', sdb]
v.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', sdc]
v.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', sdd]
end
end
config.vm.define "jammy", primary: true do |jammy|
# Virtualbox provider
jammy.vm.provider "virtualbox" do |v, override|
# Ubuntu Jammy 22.04
v.name = current_role
override.vm.box = "bento/ubuntu-22.04"
# Add extra drives
unless File.exist?(sdb)
v.customize ['createhd', '--filename', sdb, '--size', 1 * 1024]
end
unless File.exist?(sdc)
v.customize ['createhd', '--filename', sdc, '--size', 1 * 1024]
end
unless File.exist?(sdd)
v.customize ['createhd', '--filename', sdd, '--size', 1 * 1024]
end
v.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', sdb]
v.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', sdc]
v.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', sdd]
end
end
config.vm.define "focal", autostart: false do |focal|
# Virtualbox provider
focal.vm.provider "virtualbox" do |v, override|
# Ubuntu Focal 20.04
v.name = current_role
override.vm.box = "bento/ubuntu-20.04"
# Add extra drives
unless File.exist?(sdb)
v.customize ['createhd', '--filename', sdb, '--size', 1 * 1024]
end
unless File.exist?(sdc)
v.customize ['createhd', '--filename', sdc, '--size', 1 * 1024]
end
unless File.exist?(sdd)
v.customize ['createhd', '--filename', sdd, '--size', 1 * 1024]
end
v.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', sdb]
v.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', sdc]
v.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', sdd]
end
end
config.vm.provision "ansible" do |ansible|
# Pull requirements
ansible.galaxy_roles_path = ".vagrant/roles"
# Include requirements if its present
if File.exist?('requirements.yml')
ansible.galaxy_role_file = "requirements.yml"
end
# Run playbook
ansible.playbook = "test.yml"
# Load in extra variables if passed in
ansible.raw_arguments = Shellwords.shellsplit(ENV['ANSIBLE_ARGS']) if ENV['ANSIBLE_ARGS']
# Set verbosity
ansible.verbose = true
# Increase default threads and allow pipelining for speed, load in extra variables
ansible.raw_arguments = ['-T 25', '-e pipelining=True'] + Shellwords.shellsplit(ENV['ANSIBLE_ARGS']) if ENV['ANSIBLE_ARGS']
end
end