vagrant-uplift 0.2.1902.19 → 0.2.1902.32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/lib/scripts/vagrant/uplift.vagrant.dc12/dc.dsc.ps1 +2 -2
  3. data/lib/scripts/vagrant/uplift.vagrant.dc12/dc.replica.dsc.ps1 +2 -2
  4. data/lib/scripts/vagrant/uplift.vagrant.dc12/dc.users.dsc.ps1 +2 -2
  5. data/lib/scripts/vagrant/uplift.vagrant.sharepoint/_sp2013_image_packages.dsc.ps1 +40 -0
  6. data/lib/scripts/vagrant/uplift.vagrant.sharepoint/sp2013.dsc.ps1 +2 -2
  7. data/lib/scripts/vagrant/uplift.vagrant.sharepoint/sp2013.post_setup.dsc.ps1 +3 -3
  8. data/lib/scripts/vagrant/uplift.vagrant.sharepoint/sp2016.dsc.ps1 +1 -1
  9. data/lib/scripts/vagrant/uplift.vagrant.sharepoint/sp2016.farm-minimal-services.dsc.ps1 +279 -0
  10. data/lib/scripts/vagrant/uplift.vagrant.sharepoint/sp2016.farm-only.dsc.ps1 +34 -128
  11. data/lib/scripts/vagrant/uplift.vagrant.sharepoint/sp2016.post_setup.dsc.ps1 +2 -2
  12. data/lib/scripts/vagrant/uplift.vagrant.sharepoint/sp2016.pre_setup2.dsc.ps1 +2 -2
  13. data/lib/scripts/vagrant/uplift.vagrant.sharepoint/sp2016.sp-accounts.dsc.ps1 +98 -0
  14. data/lib/scripts/vagrant/uplift.vagrant.sharepoint/sp2016.sp-image-setup.dsc.ps1 +56 -0
  15. data/lib/scripts/vagrant/uplift.vagrant.sharepoint/sp2016.sql-accounts.dsc.ps1 +106 -0
  16. data/lib/scripts/vagrant/uplift.vagrant.sharepoint/sp2016.web-application.dsc.ps1 +117 -0
  17. data/lib/scripts/vagrant/uplift.vagrant.sharepoint/tests/sp2016.minimal-services.Tests.ps1 +47 -0
  18. data/lib/scripts/vagrant/uplift.vagrant.sql12/sql.dsc.ps1 +1 -1
  19. data/lib/scripts/vagrant/uplift.vagrant.sql12/sql.optimize.dsc.ps1 +3 -2
  20. data/lib/scripts/vagrant/uplift.vagrant.sql12/sql.prepare.dsc.ps1 +1 -1
  21. data/lib/scripts/vagrant/uplift.vagrant.win12soe/soe.shortcuts.dsc.ps1 +58 -4
  22. data/lib/vagrant-uplift/appinsights.rb +173 -0
  23. data/lib/vagrant-uplift/config_builder.rb +1231 -819
  24. data/lib/vagrant-uplift/log.rb +15 -4
  25. data/lib/vagrant-uplift/version.rb +1 -1
  26. metadata +13 -5
@@ -13,7 +13,7 @@ $sqlSysAdminAccounts = (Get-UpliftEnvVariable "UPLF_SQL_SYS_ADMIN_ACCOUNTS").Spl
13
13
 
14
14
  Configuration Install_SQL
15
15
  {
16
- Import-DscResource -ModuleName 'xSQLServer'
16
+ Import-DscResource -ModuleName 'xSQLServer' -ModuleVersion "9.1.0.0"
17
17
  Import-DscResource -ModuleName 'PSDesiredStateConfiguration'
18
18
 
19
19
  Node localhost {
@@ -8,9 +8,10 @@ Write-UpliftEnv
8
8
 
9
9
  Configuration Optimize_SQL
10
10
  {
11
- Import-DscResource -ModuleName 'xSQLServer'
12
11
  Import-DscResource -ModuleName 'PSDesiredStateConfiguration'
13
12
 
13
+ Import-DscResource -ModuleName 'SqlServerDsc' -ModuleVersion "12.2.0.0"
14
+
14
15
  Node localhost {
15
16
 
16
17
  SqlServerMemory SQLServerMaxMemory
@@ -36,7 +37,7 @@ $config = @{
36
37
  RetryIntervalSec = 30
37
38
 
38
39
  ServerName = Get-UpliftEnvVariable "UPLF_SQL_SERVER_NAME" "" (hostname)
39
- InstanceName = Get-UpliftEnvVariable "UPLF_SQL_INSTNCE_NAME" "" "MSSQL"
40
+ InstanceName = Get-UpliftEnvVariable "UPLF_SQL_INSTANCE_NAME" "" "MSSQLSERVER"
40
41
 
41
42
  MinMemory = Get-UpliftEnvVariable "UPLF_SQL_MIN_MEMORY" "" 1024
42
43
  MaxMemory = Get-UpliftEnvVariable "UPLF_SQL_MAX_MEMORY" "" 4096
@@ -21,7 +21,7 @@ $instanceFeatures = Get-UpliftEnvVariable "UPLF_SQL_INSTANCE_FEATURES"
21
21
  Write-UpliftMessage "Executing prepare DSC..."
22
22
  Configuration Prepare_SQL
23
23
  {
24
- Import-DscResource -ModuleName xSQLServer
24
+ Import-DscResource -ModuleName xSQLServer -ModuleVersion "9.1.0.0"
25
25
 
26
26
  Node localhost {
27
27
 
@@ -9,20 +9,21 @@ Configuration SOE_Shortcuts
9
9
  {
10
10
  Import-DscResource -ModuleName DSCR_Shortcut -ModuleVersion '1.3.7'
11
11
 
12
- $desktopPath = [Environment]::GetFolderPath("Desktop")
12
+ $desktopPath = [Environment]::GetFolderPath("CommonDesktopDirectory")
13
13
 
14
+ # common setup - IE, PowerShell ISE, PS6
14
15
  cShortcut IE_Desktop
15
16
  {
16
17
  Path = "$desktopPath\IE.lnk"
17
18
  Target = "C:\Program Files\Internet Explorer\iexplore.exe"
18
-
19
19
  }
20
20
 
21
21
  cShortcut PowerShell_ISE_Desktop
22
22
  {
23
- Path = "$desktopPath\PowerShellISE.lnk"
23
+ Path = "$desktopPath\PowerShell ISE.lnk"
24
24
  Target = "%windir%\system32\WindowsPowerShell\v1.0\PowerShell_ISE.exe"
25
25
  WorkingDirectory = '%HOMEDRIVE%%HOMEPATH%'
26
+ Description = "IE IE"
26
27
 
27
28
  }
28
29
 
@@ -31,7 +32,60 @@ Configuration SOE_Shortcuts
31
32
  Path = "$desktopPath\PowerShell6.lnk"
32
33
  Target = "C:\Program Files\PowerShell\6\pwsh.exe"
33
34
  Arguments = "-WorkingDirectory ~"
34
-
35
+ }
36
+
37
+ # system utils
38
+ cShortcut ADUsers
39
+ {
40
+ Path = "$desktopPath\AD Users and Computers.lnk"
41
+ Target = "%SystemRoot%\system32\dsa.msc"
42
+ WorkingDirectory = '%HOMEDRIVE%%HOMEPATH%'
43
+ }
44
+
45
+ cShortcut ServerManager
46
+ {
47
+ Path = "$desktopPath\Server Manager.lnk"
48
+ Target = "%windir%\system32\ServerManager.exe"
49
+ WorkingDirectory = '%windir%\system32'
50
+ }
51
+
52
+ cShortcut Services
53
+ {
54
+ Path = "$desktopPath\Services.lnk"
55
+ Target = "%windir%\system32\services.msc"
56
+ WorkingDirectory = '%HOMEDRIVE%%HOMEPATH%'
57
+ }
58
+
59
+ # VS2017 exists?
60
+ $vs17Path = "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\devenv.exe"
61
+ if( (Test-Path $vs17Path) -eq $True) {
62
+ cShortcut VS2017
63
+ {
64
+ Path = "$desktopPath\VS 2017.lnk"
65
+ Target = "$vs17Path"
66
+ WorkingDirectory = "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\"
67
+ }
68
+ }
69
+
70
+ # sql management
71
+ $sql16ssms = "C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\Ssms.exe"
72
+ if( (Test-Path $sql16ssms) -eq $True) {
73
+ cShortcut SQL16SSMS
74
+ {
75
+ Path = "$desktopPath\SQL Server Manager.lnk"
76
+ Target = "$sql16ssms"
77
+ }
78
+ }
79
+
80
+ # sharepoint ca
81
+ $sp16centralAdministration = "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\BIN\psconfigui.exe"
82
+ if( (Test-Path $sp16centralAdministration) -eq $True) {
83
+ cShortcut SP2016CA
84
+ {
85
+ Path = "$desktopPath\SharePoint Central Administration.lnk"
86
+ Target = $sp16centralAdministration
87
+ Arguments = "-cmd showcentraladmin"
88
+ }
35
89
  }
36
90
  }
37
91
 
@@ -0,0 +1,173 @@
1
+ module VagrantPlugins::Uplift
2
+ module AppInsights
3
+
4
+ extend self
5
+
6
+ class AppInsightsHelper
7
+
8
+ require 'date'
9
+ require 'uri'
10
+ require 'net\http'
11
+ require 'openssl'
12
+ require 'json'
13
+
14
+ @key = nil
15
+
16
+ @endpoint = nil
17
+ @endpoint_api = nil
18
+
19
+ @client_id = nil
20
+
21
+ def initialize(key)
22
+ @key = key
23
+
24
+ @endpoint = 'https://dc.services.visualstudio.com'
25
+ @endpoint_api = '/v2/track'
26
+
27
+ @client_id = 'uplift-vagrant:ruby:1.0.0'
28
+ end
29
+
30
+ def track_event(event_name, event_properties)
31
+
32
+ _log_debug("tracking event: #{event_name}")
33
+
34
+ result = {
35
+ :success => false
36
+ }
37
+
38
+ begin
39
+ time = DateTime.now.to_time.utc.strftime('%Y-%m-%dT%H:%M:%S.%7N%z')
40
+
41
+ data = {
42
+ "name" => "Microsoft.ApplicationInsights.Event",
43
+
44
+ "time" => time,
45
+ "iKey" => @key,
46
+
47
+ "tags" => {
48
+ "ai.internal.sdkVersion": @client_id
49
+ },
50
+
51
+ "data" => {
52
+ "baseType" => "EventData",
53
+ "baseData" => {
54
+ "ver": 2,
55
+ "name": event_name ,
56
+ "properties": event_properties
57
+ }
58
+ }
59
+ }
60
+
61
+ _log_debug("sending data: #{data}")
62
+ _send_data_async(data)
63
+ rescue => e
64
+ result[:exception] = e;
65
+ result[:success] = false
66
+ ensure
67
+
68
+ end
69
+
70
+ return result
71
+ end
72
+
73
+ private
74
+
75
+ def _log_debug(message)
76
+ if ENV['UPLF_LOG_LEVEL'] == 'DEBUG'
77
+ puts " AppInsights DEBUG: #{message}"
78
+ end
79
+ end
80
+
81
+ def _send_data(data_hash)
82
+ thread = _send_data_async
83
+ thread.join
84
+ end
85
+
86
+ def _write_appinsight_usage_warning(message = nil, error = nil)
87
+ _log_debug "[!] Cannot use AppInsight, please report this error or use UPLF_NO_APPINSIGHT env variable to disable it."
88
+
89
+ if !message.to_s.empty?
90
+ _log_debug message
91
+ end
92
+
93
+ if !error.nil?
94
+ _log_debug e
95
+ end
96
+ end
97
+
98
+ def _send_data_async(data_hash)
99
+
100
+ thr = Thread.new {
101
+
102
+ begin
103
+
104
+ _log_debug(" - creating http client")
105
+ http = _get_http_client
106
+
107
+ _log_debug(" - crafting request")
108
+ request = Net::HTTP::Post.new(@endpoint_api)
109
+ request.body = data_hash.to_json
110
+
111
+ _log_debug(" - http.request(request)")
112
+ response = http.request(request)
113
+
114
+ result = {}
115
+
116
+ _log_debug(" - response: #{response.inspect}")
117
+
118
+ result[:success] = response != nil && response.code.to_s == '200'
119
+ result[:response] = response
120
+
121
+ result[:response_code] = response.code
122
+ result[:response_message] = response.message
123
+ result[:response_body] = response.body()
124
+
125
+ if response != nil && response.code.to_s != '200'
126
+ _log_debug(" [!] FAIL!")
127
+ _write_appinsight_usage_warning("response code: #{response.code}", nil)
128
+ else
129
+ _log_debug(" [+] OK!")
130
+ end
131
+
132
+ rescue => e
133
+ _log_debug(" [!] FAIL!")
134
+ _write_appinsight_usage_warning(nil, e)
135
+ end
136
+
137
+ return result
138
+ }
139
+
140
+ return thr
141
+ end
142
+
143
+ def _get_http_client()
144
+
145
+ uri = URI.parse(@endpoint)
146
+ http = Net::HTTP.new(uri.host, uri.port)
147
+
148
+ http.use_ssl = true
149
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
150
+
151
+ return http
152
+ end
153
+
154
+ end
155
+
156
+ def get_client(key)
157
+
158
+ client = AppInsightsHelper.new(key)
159
+
160
+ _configure_client(client)
161
+
162
+ return client
163
+ end
164
+
165
+ private
166
+
167
+ def _configure_client(client)
168
+
169
+ end
170
+
171
+ end
172
+
173
+ end
@@ -1,819 +1,1231 @@
1
- require_relative "log"
2
- require 'fileutils'
3
-
4
- module VagrantPlugins
5
- module Uplift
6
-
7
- class UpliftConfigBuilder
8
-
9
- @@logger = nil
10
-
11
- @@network_range = '192.168.4'
12
- @@config_file_path = './.vagrant/uplift-vagrant'
13
-
14
- # initialize
15
- def initialize()
16
- supported_version = '2.2.3'
17
-
18
- if(Vagrant::VERSION != supported_version)
19
- log_warn "WARN! - detected vagrant v#{Vagrant::VERSION}, uplift is tested on vagrant v#{supported_version}"
20
- end
21
-
22
- # disabple this warning
23
- # WARNING: Vagrant has detected the `vagrant-winrm` plugin.
24
- ENV['VAGRANT_IGNORE_WINRM_PLUGIN'] = '1'
25
-
26
- log_info_light "vagrant-uplift v0.1.0"
27
- end
28
-
29
- def vagrant_script_path
30
- current_dir = File.dirname(__FILE__)
31
- File.expand_path(File.join(current_dir, "/../scripts"))
32
- end
33
-
34
- def get_config_path
35
- return @@config_file_path
36
- end
37
-
38
- def set_config_path(value)
39
- @@config_file_path = value
40
- end
41
-
42
- # state configs
43
- def get_uplift_config_folder
44
- path = File.expand_path(@@config_file_path)
45
- FileUtils.mkdir_p path
46
-
47
- return path
48
- end
49
-
50
- def get_uplift_config_file
51
- config_dir_path = get_uplift_config_folder
52
- file_name = ".vagrant-network.yaml"
53
-
54
- return File.join(config_dir_path, file_name)
55
- end
56
-
57
- # uplift_vbmanage_machinefolder helper
58
- def uplift_set_vbmanage_machinefolder(vm_name, vm_config, value = nil)
59
- value = value || ENV['UPLF_VBMANAGE_MACHINEFOLDER']
60
-
61
- if !value.to_s.empty?
62
- log_info("#{vm_name}: vboxmanage machinefolder: #{value}")
63
- system("vboxmanage setproperty machinefolder #{value}")
64
- end
65
- end
66
-
67
- def uplift_set_default_vbmanage_machinefolder()
68
- system("vboxmanage setproperty machinefolder default")
69
- end
70
-
71
- # network helpers
72
- def get_network_range
73
- @@network_range
74
- end
75
-
76
- def set_network_range(value)
77
- @@network_range = value
78
- end
79
-
80
- def get_ip_for_host(host_name)
81
- start_index = 6
82
-
83
- file_path = get_uplift_config_file
84
-
85
- if(!File.exist? file_path)
86
- File.open(file_path,"w") do |f|
87
- f.write({}.to_yaml)
88
- end
89
- end
90
-
91
- map = YAML.load_file(file_path)
92
-
93
- if map.nil?
94
- map = {}
95
- end
96
-
97
- network_range = get_network_range
98
-
99
- ip_ranges_key = network_range
100
- machine_key = host_name.downcase
101
-
102
- ips = map.fetch(ip_ranges_key, { })
103
- machine_ip = ips.fetch(machine_key, nil)
104
-
105
- if machine_ip.nil?
106
- machine_ip = network_range + "." + (start_index + ips.count).to_s
107
- end
108
-
109
- ips[machine_key] = machine_ip
110
- map[ip_ranges_key] = ips
111
-
112
- File.open(file_path,"w") do |f|
113
- f.write(map.to_yaml)
114
- end
115
-
116
- machine_ip
117
- end
118
-
119
- # log helpers
120
- def log_warn(message)
121
- _logger.warn(message)
122
- end
123
-
124
- def log_warning(message)
125
- _logger.warn(message)
126
- end
127
-
128
- def log_info(message)
129
- _logger.info(message)
130
- end
131
-
132
- def log_info_light(message)
133
- _logger.info_light(message)
134
- end
135
-
136
- def log_debug(message)
137
- _logger.debug(message)
138
- end
139
-
140
- def log_error(message)
141
- _logger.error(message)
142
- end
143
-
144
- def log_error_and_raise(message)
145
- log_error(message)
146
- raise(message)
147
- end
148
-
149
- def get_env_variable(name, default_value)
150
- var_name = name.upcase
151
- var_value = ENV[var_name]
152
-
153
- if var_value.to_s.empty?
154
- return default_value
155
- end
156
-
157
- return var_value
158
- end
159
-
160
- def get_vm_cpus(vm_name, default_value)
161
- require_string(vm_name)
162
- require_integer(default_value)
163
-
164
- return get_env_variable("UPLF_#{vm_name}_CPUS", default_value)
165
- end
166
-
167
- def get_vm_memory(vm_name, default_value)
168
- require_string(vm_name)
169
- require_integer(default_value)
170
-
171
- return get_env_variable("UPLF_#{vm_name}_MEMORY", default_value)
172
- end
173
-
174
- # checkpoint helper
175
- def has_checkpoint?(vm_name, checkpoint_name)
176
-
177
- if !ENV['UPLF_NO_VAGRANT_CHECKPOINTS'].nil?
178
- _log.info("#{vm_name}: [-] provision checkpoint: #{checkpoint_name} (UPLF_NO_VAGRANT_CHECKPOINTS is set)")
179
-
180
- return false
181
- end
182
-
183
- file_name = ".vagrant/machines/#{vm_name}/virtualbox/.uplift/.checkpoint-#{checkpoint_name}"
184
- exists = File.exist?(file_name)
185
-
186
- if exists == true
187
- _log.info_light("#{vm_name}: [+] provision checkpoint: #{checkpoint_name}")
188
- else
189
- _log.info("#{vm_name}: [-] provision checkpoint: #{checkpoint_name}")
190
- end
191
-
192
- return exists
193
- end
194
-
195
- # RAM configs for VM
196
- def uplift_05Gb(vm_name, vm_config)
197
- require_string(vm_name)
198
- require_vagrant_config(vm_config)
199
-
200
- uplift_make_cpu_and_ram(vm_config, 2, 512)
201
- end
202
-
203
- def uplift_1Gb(vm_name, vm_config)
204
- require_string(vm_name)
205
- require_vagrant_config(vm_config)
206
-
207
- uplift_make_cpu_and_ram(vm_name, vm_config, 2, 1024)
208
- end
209
-
210
- def uplift_2Gb(vm_name, vm_config)
211
- require_string(vm_name)
212
- require_vagrant_config(vm_config)
213
-
214
- uplift_make_cpu_and_ram(vm_name, vm_config, 2, 1024 * 2)
215
- end
216
-
217
- def uplift_4Gb(vm_name, vm_config)
218
- require_string(vm_name)
219
- require_vagrant_config(vm_config)
220
-
221
- uplift_make_cpu_and_ram(vm_name, vm_config, 4, 1024 * 4)
222
- end
223
-
224
- def uplift_6Gb(vm_name, vm_config)
225
- require_string(vm_name)
226
- require_vagrant_config(vm_config)
227
-
228
- uplift_make_cpu_and_ram(vm_name, vm_config, 4, 1024 * 6)
229
- end
230
-
231
- def uplift_8Gb(vm_name, vm_config)
232
- require_string(vm_name)
233
- require_vagrant_config(vm_config)
234
-
235
- uplift_make_cpu_and_ram(vm_name, vm_config, 4, 1024 * 8)
236
- end
237
-
238
- def uplift_12Gb(vm_name, vm_config)
239
- require_string(vm_name)
240
- require_vagrant_config(vm_config)
241
-
242
- uplift_make_cpu_and_ram(vm_name, vm_config, 4, 1024 * 12)
243
- end
244
-
245
- def uplift_16Gb(vm_name, vm_config)
246
- require_string(vm_name)
247
- require_vagrant_config(vm_config)
248
-
249
- uplift_make_cpu_and_ram(vm_name, vm_config, 4, 1024 * 16)
250
- end
251
-
252
- def uplift_make_cpu_and_ram(vm_name, vm_config, cpu, ram)
253
-
254
- ram_in_gb = (ram / 1024.0)
255
-
256
- # round evertything that bigger that 1
257
- if ram_in_gb >= 1
258
- ram_in_gb = ram_in_gb.round
259
- end
260
-
261
- log_info_light("#{vm_name}: #{ram_in_gb}Gb RAM, #{cpu} CPU")
262
-
263
- vm_config.vm.provider "virtualbox" do |v|
264
-
265
- v.linked_clone = false
266
-
267
- v.memory = ram
268
- v.cpus = cpu
269
-
270
- v.gui = false
271
-
272
- v.customize ['modifyvm', :id, '--clipboard', 'bidirectional']
273
- v.customize ["modifyvm", :id, "--vram", 32]
274
-
275
- v.customize ["modifyvm", :id, "--audio", "none"]
276
- v.customize ["modifyvm", :id, "--usb", "off"]
277
-
278
- # if Vagrant::VERSION >= '2.2.3'
279
- # # Vagrant has detected a configuration issue which exposes a vulnerability with the installed version of VirtualBox
280
- # # Ensure the guest is trusted to use this configuration or update the NIC type using one of the methods below:
281
- # # https://www.vagrantup.com/docs/virtualbox/configuration.html#default-nic-type
282
-
283
- # v.default_nic_type = "82543GC"
284
- # end
285
-
286
- # https://github.com/hashicorp/vagrant/issues/6812#issuecomment-171981576
287
- # Vagrant is reconnecting from scratch, sometimes literally before each command in negotiating loop
288
- v.customize ['modifyvm', :id, "--natdnshostresolver1", "off"]
289
- end
290
- end
291
-
292
- def require_integer(value)
293
- if value.is_a?(Integer) != true
294
- log_error_and_raise("expected integer value, got #{value.class}, #{value.inspect}")
295
- end
296
- end
297
-
298
- def require_string(value)
299
- if value.nil? == true || value.to_s.empty?
300
- log_error_and_raise("expected string value, got nil or empty string")
301
- end
302
-
303
- if value.is_a?(String) != true
304
- log_error_and_raise("expected string value, got #{value.class}, #{value.inspect}")
305
- end
306
-
307
- end
308
-
309
- def require_vagrant_config(value)
310
- if value.nil? == true
311
- log_error_and_raise("expected string value, got nil or empty string")
312
- end
313
-
314
- if value.is_a?(Vagrant::Config::V2::Root) != true
315
- log_error_and_raise("expected Vagrant::Config::V2::Root value, got #{value.class}, #{value.inspect}")
316
- end
317
-
318
- end
319
-
320
- # winrm
321
- def uplift_winrm(vm_name, vm_config)
322
- require_string(vm_name)
323
- require_vagrant_config(vm_config)
324
-
325
- log_info_light("#{vm_name}: winrm config")
326
-
327
- # https://www.vagrantup.com/docs/vagrantfile/winrm_settings.html
328
-
329
- vm_config.vm.guest = :windows
330
-
331
- vm_config.vm.boot_timeout = 300
332
-
333
- vm_config.vm.communicator = "winrm"
334
- vm_config.winrm.transport = :plaintext
335
- vm_config.winrm.basic_auth_only = true
336
-
337
- vm_config.winrm.ssl_peer_verification = false
338
-
339
- vm_config.winrm.username = "vagrant"
340
- vm_config.winrm.password = "vagrant"
341
- end
342
-
343
- # synch folders
344
- def uplift_synced_folder(vm_name, vm_config)
345
- require_string(vm_name)
346
- require_vagrant_config(vm_config)
347
-
348
- log_info_light("#{vm_name}: synced folders config")
349
-
350
- vm_config.vm.synced_folder ".", "/vagrant", disabled: true
351
- end
352
-
353
- # test helpers
354
- def execute_tests?(vm_config:)
355
- return true
356
- end
357
-
358
- def execute_tests(vm_config:, paths:, env: {}, privileged: false)
359
-
360
- if !execute_tests?(vm_config: vm_config)
361
- _log.info " - pester: skipping test execition due to false flag in properties"
362
- return
363
- end
364
-
365
- if !paths.is_a?(Array)
366
- paths = [paths]
367
- end
368
-
369
- paths.each do | path |
370
- test_path_value = File.basename(path)
371
-
372
- _log.debug " - pester test path: #{test_path_value}"
373
- end
374
-
375
- paths.each do |src_test_path|
376
-
377
- test_files = Dir[src_test_path]
378
- test_files_string = "\n - " + test_files.join("\n - ")
379
- _log.debug " - scanned: #{src_test_path}, found: #{test_files_string}"
380
-
381
- if test_files.empty?
382
- _log.warn "[!] cannot find any test files under path: #{src_test_path} - mostlikely, wrong location/pattern"
383
- end
384
-
385
- test_files.each do |fname|
386
-
387
- test_path_value = File.basename(fname)
388
-
389
- _log.info " - pester test: #{test_path_value}"
390
- _log.debug "adding test file: #{fname}"
391
-
392
- src_path = fname
393
- dst_path = "c:/windows/temp/tests/" + File.basename(fname)
394
-
395
- vm_config.vm.provision :file do |file|
396
- file.source = fname
397
- file.destination = dst_path
398
- end
399
-
400
- vm_config.vm.provision "shell",
401
- inline: "Invoke-Pester -EnableExit -Script #{dst_path}",
402
- name: dst_path,
403
- env: env
404
- end
405
- end
406
-
407
- end
408
-
409
- # hostname and network
410
- def uplift_hostname(vm_name, vm_config, hostname)
411
- require_string(vm_name)
412
- require_vagrant_config(vm_config)
413
-
414
- require_string(hostname)
415
-
416
- log_info_light("#{vm_name}: setitng hostname: #{hostname}")
417
- vm_config.vm.hostname = hostname
418
- end
419
-
420
- def uplift_private_network(vm_name, vm_config, ip: '', gateway: '')
421
-
422
- require_string(vm_name)
423
- require_vagrant_config(vm_config)
424
-
425
- log_info(" - ip: #{ip}, gateway: #{gateway}")
426
-
427
- vm_config.vm.network :private_network, ip: ip, gateway: gateway
428
- end
429
-
430
- def uplift_client_network(vm_name, vm_config, hostname)
431
-
432
- require_string(vm_name)
433
- require_vagrant_config(vm_config)
434
-
435
- require_string(hostname)
436
-
437
- network_range = get_network_range
438
-
439
- dc_ip = "#{network_range}.5"
440
- machine_ip = get_ip_for_host(hostname)
441
-
442
- log_info(" - private network: ip: #{machine_ip} gateway: #{network_range}.1")
443
- vm_config.vm.network :private_network,
444
- ip: machine_ip, gateway: "#{network_range}.1"
445
-
446
- log_info(" - fixing secondary network interface: ip: #{machine_ip} dns: #{dc_ip}")
447
- vm_config.vm.provision "shell",
448
- path: "#{vagrant_script_path}/vagrant/uplift.vagrant.core/uplift.fix-second-network.ps1",
449
- args: "-ip #{machine_ip} -dns #{dc_ip}"
450
- end
451
-
452
- def uplift_private_dc_network(vm_name, vm_config)
453
- require_string(vm_name)
454
- require_vagrant_config(vm_config)
455
-
456
- log_info_light("#{vm_name}: private dc network")
457
-
458
- network_range = get_network_range
459
-
460
- uplift_private_network(
461
- vm_name,
462
- vm_config,
463
- :ip => "#{network_range}.5",
464
- :gateway => "#{network_range}.1"
465
- )
466
-
467
- end
468
-
469
- # DSC - base configs
470
- def uplift_win16_dsc_base(vm_name, vm_config)
471
-
472
- require_string(vm_name)
473
- require_vagrant_config(vm_config)
474
-
475
- log_info_light("#{vm_name}: dsc soe config")
476
-
477
- vm_config.vm.provision "shell",
478
- name: "soe.dsc.ps1",
479
- path: "#{vagrant_script_path}/vagrant/uplift.vagrant.win12soe/soe.dsc.ps1",
480
- env: {
481
- "UPLF_DSC_CHECK" => 1
482
- }
483
-
484
- execute_tests(
485
- vm_config: vm_config,
486
- paths: "#{vagrant_script_path}/vagrant/uplift.vagrant.win12soe/tests/soe.dsc.*"
487
- )
488
- end
489
-
490
- def uplift_win16_dsc_shortcuts(vm_name, vm_config)
491
-
492
- require_string(vm_name)
493
- require_vagrant_config(vm_config)
494
-
495
- log_info_light("#{vm_name}: dsc soe shortcuts")
496
-
497
- vm_config.vm.provision "shell",
498
- name: "soe.shortcuts.dsc.ps1",
499
- path: "#{vagrant_script_path}/vagrant/uplift.vagrant.win12soe/soe.shortcuts.dsc.ps1",
500
- env: {
501
- "UPLF_DSC_CHECK" => 1
502
- }
503
- end
504
-
505
- # DSC - domain controller
506
- def uplift_win16_dsc_dc(vm_name, vm_config)
507
-
508
- require_string(vm_name)
509
- require_vagrant_config(vm_config)
510
-
511
- log_info(" - dc provision")
512
-
513
- # just in case there are outstanding tasks
514
- vm_config.vm.provision "reload"
515
-
516
- vm_config.vm.provision "shell",
517
- path: "#{vagrant_script_path}/vagrant/uplift.vagrant.dc12/dc.dsc.ps1",
518
- name: "dc.dsc.ps1",
519
- env: {
520
- "UPLF_DC_DOMAIN_NAME" => "uplift.local",
521
- "UPLF_DC_DOMAIN_ADMIN_NAME" => "admin",
522
- "UPLF_DC_DOMAIN_ADMIN_PASSWORD" => "uplift!QAZ",
523
-
524
- "UPLF_DSC_CHECK_SKIP" => 1
525
- }
526
-
527
- vm_config.vm.provision "reload"
528
-
529
- execute_tests(
530
- vm_config: vm_config,
531
- paths: "#{vagrant_script_path}/vagrant/uplift.vagrant.dc12/tests/dc.dsc.*"
532
- )
533
- end
534
-
535
- def uplift_win16_dsc_dc_users(vm_name, vm_config)
536
-
537
- require_string(vm_name)
538
- require_vagrant_config(vm_config)
539
-
540
- log_info(" - domain users")
541
-
542
- vm_config.vm.provision "shell",
543
- path: "#{vagrant_script_path}/vagrant/uplift.vagrant.dc12/dc.users.dsc.ps1",
544
- name: 'dc.users.dsc.ps1',
545
- env: {
546
- "UPLF_DC_DOMAIN_NAME" => "uplift",
547
- "UPLF_DC_DOMAIN_ADMIN_NAME" => "admin",
548
- "UPLF_DC_DOMAIN_ADMIN_PASSWORD" => "uplift!QAZ",
549
-
550
- "UPLF_VAGRANT_USER_NAME" => "vagrant",
551
- "UPLF_VAGRANT_USER_PASSWORD" => "vagrant"
552
- }
553
-
554
- end
555
-
556
- def uplift_dc16(vm_name, vm_config)
557
-
558
- require_string(vm_name)
559
- require_vagrant_config(vm_config)
560
-
561
- log_info_light("#{vm_name}: domain controller setup")
562
-
563
- uplift_win16_dsc_dc(vm_name, vm_config)
564
- uplift_win16_dsc_dc_users(vm_name, vm_config)
565
- end
566
-
567
- def uplift_dc_join(vm_name, vm_config)
568
-
569
- require_string(vm_name)
570
- require_vagrant_config(vm_config)
571
-
572
- log_info_light("#{vm_name}: domain join")
573
-
574
- network_range = get_network_range
575
- dc_ip = "#{network_range}.5"
576
-
577
- log_info(" - dc_ip: #{dc_ip}")
578
-
579
- vm_config.vm.provision "shell",
580
- path: "#{vagrant_script_path}/vagrant/uplift.vagrant.dcjoin/dc.join.dsc.ps1",
581
- env: {
582
- "UPLF_DC_DOMAIN_NAME" => "uplift",
583
-
584
- "UPLF_DC_JOIN_USER_NAME" => "admin",
585
- "UPLF_DC_JOIN_USER_PASSWORD" => "uplift!QAZ",
586
-
587
- "UPLF_DC_DOMAIN_HOST_IP" => "#{dc_ip}"
588
- }
589
-
590
- vm_config.vm.provision "reload"
591
-
592
- vm_config.vm.provision "shell",
593
- name: "dc.join.hostname.ps1",
594
- path: "#{vagrant_script_path}/vagrant/uplift.vagrant.dcjoin/dc.join.hostname.ps1"
595
- end
596
-
597
- # DSC - SharePoint configs
598
- def uplift_sp16_pre_setup(vm_name, vm_config)
599
-
600
- require_string(vm_name)
601
- require_vagrant_config(vm_config)
602
-
603
- log_info_light("#{vm_name}: SharePoint 2016: farm pre-setup")
604
-
605
- # shared scripts
606
- vm_config.vm.provision "file",
607
- source: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/shared/sp.helpers.ps1",
608
- destination: "c:/windows/temp/uplift.vagrant.sharepoint/shared/sp.helpers.ps1"
609
-
610
- # presetup sharepoint farm
611
- # - fix iss
612
- # - reboot
613
- # - restore all services
614
- vm_config.vm.provision "shell",
615
- path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/sp2016.pre_setup1.dsc.ps1"
616
-
617
- vm_config.vm.provision "reload"
618
-
619
- vm_config.vm.provision "shell",
620
- path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/sp2016.pre_setup2.dsc.ps1"
621
- end
622
-
623
- def uplift_sp16_farm_post_setup(vm_name, vm_config)
624
-
625
- require_string(vm_name)
626
- require_vagrant_config(vm_config)
627
-
628
- log_info_light("#{vm_name}: SharePoint 2016: farm post-setup")
629
-
630
- vm_config.vm.provision "shell",
631
- path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/sp2016.post_setup.dsc.ps1"
632
- end
633
-
634
- def uplift_sp16_print_info(vm_name, vm_config)
635
-
636
- require_string(vm_name)
637
- require_vagrant_config(vm_config)
638
-
639
- log_info_light("#{vm_name}: SharePoint 2016: print info")
640
-
641
- vm_config.vm.provision "shell",
642
- path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/sp2016.info.ps1"
643
- end
644
-
645
- def uplift_sp16_farm_only(vm_name, vm_config, sql_server, farm_prefix = nil, dsc_verbose: '1')
646
-
647
- if farm_prefix.nil?
648
- farm_prefix = "#{vm_name}_"
649
- end
650
-
651
- require_string(vm_name)
652
- require_vagrant_config(vm_config)
653
-
654
- require_string(sql_server)
655
- require_string(farm_prefix)
656
-
657
- log_info_light("#{vm_name}: SharePoint 2016: farm creation only")
658
-
659
- # shared scripts
660
- vm_config.vm.provision "file",
661
- source: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/shared/sp.helpers.ps1",
662
- destination: "c:/windows/temp/uplift.vagrant.sharepoint/shared/sp.helpers.ps1"
663
-
664
- env = {
665
- "UPLF_sp_farm_sql_server_host_name" => sql_server,
666
- "UPLF_sp_farm_sql_db_prefix" => "#{farm_prefix}_",
667
- "UPLF_sp_farm_passphrase" => "uplift!QAZ",
668
-
669
- "UPLF_sp_setup_user_name" => "uplift\\vagrant",
670
- "UPLF_sp_setup_user_password" => "vagrant",
671
- "UPLF_DSC_VERBOSE" => dsc_verbose
672
- }
673
-
674
- vm_config.vm.provision "shell",
675
- path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/sp2016.farm-only.dsc.ps1",
676
- env: env
677
- end
678
-
679
- # DSC - sql configs
680
- def uplift_sql(vm_name, vm_config)
681
-
682
- require_string(vm_name)
683
- require_vagrant_config(vm_config)
684
-
685
- log_info_light("#{vm_name}: SQL 2016: image completion")
686
-
687
- vm_config.vm.provision "shell",
688
- path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sql12/sql.complete.dsc.ps1"
689
-
690
- execute_tests(
691
- vm_config: vm_config,
692
- paths: "#{vagrant_script_path}/vagrant/uplift.vagrant.sql12/tests/sql16.dsc.*"
693
- )
694
-
695
- end
696
-
697
- def uplift_sql_optimize(vm_name, vm_config)
698
-
699
- require_string(vm_name)
700
- require_vagrant_config(vm_config)
701
-
702
- log_info_light("#{vm_name}: SQL 2016: optimization")
703
-
704
- vm_config.vm.provision "shell",
705
- path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sql12/sql.optimize.dsc.ps1",
706
- env: {
707
- # UPLF_SQL_SERVER_NAME
708
- # UPLF_SQL_INSTNCE_NAME
709
- # UPLF_SQL_MIN_MEMORY
710
- # UPLF_SQL_MAX_MEMORY
711
- }
712
-
713
- end
714
-
715
- def uplift_sql_config(vm_name:, vm_config:, resource_name: 'sql2016_rtm')
716
- log_info("SQL16")
717
-
718
- uplift_sql(
719
- vm_config,
720
- resource_name: 'sql2016_rtm'
721
- )
722
-
723
- log_info("SQL16 completed!")
724
- end
725
-
726
- def uplift_sql16(vm_name:, vm_config:)
727
- uplift_sql_config(
728
- vm_config,
729
- resource_name: 'sql2016_rtm'
730
- )
731
- end
732
-
733
- def uplift_sql14(vm_name:, vm_config:)
734
- uplift_sql_config(
735
- vm_config,
736
- resource_name: 'sql2016_rtm'
737
- )
738
- end
739
-
740
- def uplift_sql12(vm_name:, vm_config:)
741
- uplift_sql_config(
742
- vm_config,
743
- resource_name: 'sql2016_rtm'
744
- )
745
- end
746
-
747
- # DSC - Visual Studio 17 configs
748
- def uplift_visual_studio_17(vm_name:, vm_config:,
749
- resource_name: 'ms-visualstudio-2017.ent-dist-office-dev',
750
- bin: true,
751
- install: true)
752
-
753
- log_info(" - vs17 config for resource: #{resource_name}")
754
-
755
- vm_config.vm.provision "shell",
756
- path: "#{vagrant_script_path}/vagrant/uplift.vagrant.visual_studio17/vs17.dsc.ps1",
757
- env: {
758
- "UPLF_VS_EXECUTABLE_PATH" => "c:/_uplift_resources/ms-visualstudio-2017.ent-dist-office-dev/latest/vs_enterprise.exe",
759
- "UPLF_RESOURCE_NAME" => [
760
- 'Microsoft.VisualStudio.Workload.Office',
761
- 'Microsoft.VisualStudio.Workload.ManagedDesktop',
762
- 'Microsoft.VisualStudio.Workload.NetCoreTools',
763
- 'Microsoft.VisualStudio.Workload.NetWeb',
764
- 'Microsoft.VisualStudio.Workload.Node',
765
- 'Microsoft.VisualStudio.Workload.VisualStudioExtension'
766
- ].join(";")
767
- }
768
-
769
- end
770
-
771
- private
772
-
773
- def _logger
774
- @@logger = @@logger || VagrantPlugins::Uplift::Log.get_logger
775
- @@logger
776
- end
777
-
778
- def _log
779
- _logger
780
- end
781
-
782
- def _is_privileged_shell?
783
- # https://github.com/hashicorp/vagrant/issues/9138#issuecomment-444408251
784
- # https://github.com/clong/DetectionLab/issues/172
785
-
786
- result = Vagrant::VERSION < '2.2.1'
787
-
788
- log_debug "_is_privileged_shell: #{result}"
789
-
790
- result
791
- end
792
-
793
- def _is_powershell_elevated_interactive?
794
- # https://github.com/hashicorp/vagrant/issues/9138#issuecomment-444408251
795
- # https://github.com/clong/DetectionLab/issues/172
796
-
797
- result = Vagrant::VERSION < '2.2.1'
798
-
799
- # join to dc issue
800
- # workgroup 'WORKGROUP' with following error message: Unable to update the password. The value
801
- # Computer 'WIN-SN2UMLHU29M' failed to join domain 'uplift' from its current workgroup 'WORKGROUP' with following error message: Unable to update the password.
802
- # The value provided as the current password is incorrect.
803
-
804
- # http://www.gi-architects.co.uk/2017/01/powershell-add-computer-error-when-executed-remotely/
805
-
806
- log_debug "is_powershell_elevated_interactive: #{result}"
807
-
808
- result
809
- end
810
-
811
- end
812
-
813
- def self.Config
814
- return UpliftConfigBuilder.new
815
- end
816
-
817
- end
818
-
819
- end
1
+ require_relative "log"
2
+ require_relative "appinsights"
3
+
4
+ require 'fileutils'
5
+ require 'securerandom'
6
+
7
+ module VagrantPlugins
8
+ module Uplift
9
+
10
+ class UpliftConfigBuilder
11
+
12
+ @@logger = nil
13
+
14
+ @@network_range = '192.168.4'
15
+ @@config_file_path = './.vagrant/uplift-vagrant'
16
+
17
+ @@ai_client = nil
18
+ @@ai_config_id = nil
19
+
20
+ @@plugin_version = 'v0.1.20190207.235938'
21
+
22
+ @@supported_version = nil
23
+
24
+ # initialize
25
+ def initialize()
26
+
27
+ @@supported_version = '2.2.3'
28
+ @@ai_config_id = SecureRandom.uuid.to_s
29
+
30
+ if(Vagrant::VERSION != @@supported_version)
31
+ log_warn "WARN! - detected vagrant v#{Vagrant::VERSION}, uplift is tested on vagrant v#{@@supported_version}"
32
+ end
33
+
34
+ # disable warning:
35
+ # WARNING: Vagrant has detected the `vagrant-winrm` plugin.
36
+ ENV['VAGRANT_IGNORE_WINRM_PLUGIN'] = '1'
37
+
38
+ log_info_light "vagrant-uplift #{@@plugin_version}"
39
+
40
+ _track_ai_event('initialize')
41
+
42
+ # track only first time initialization for the vagrantfile
43
+ # further initializations won't be tracked
44
+ # _track_first_initialize
45
+ end
46
+
47
+ def vagrant_script_path
48
+ current_dir = File.dirname(__FILE__)
49
+ File.expand_path(File.join(current_dir, "/../scripts"))
50
+ end
51
+
52
+ def get_config_path
53
+ return @@config_file_path
54
+ end
55
+
56
+ def set_config_path(value)
57
+ @@config_file_path = value
58
+ end
59
+
60
+ # Returns path to uplift config folder
61
+ #
62
+ # @return [String] path to uplift config folder
63
+ def get_uplift_config_folder
64
+ path = File.expand_path(@@config_file_path)
65
+ FileUtils.mkdir_p path
66
+
67
+ return path
68
+ end
69
+
70
+ # Returns path to uplift config file
71
+ #
72
+ # @return [String] path to uplift config file
73
+ def get_uplift_config_file
74
+ config_dir_path = get_uplift_config_folder
75
+ file_name = ".vagrant-network.yaml"
76
+
77
+ return File.join(config_dir_path, file_name)
78
+ end
79
+
80
+ # Sets 'machinefolder' property using 'vboxmanage' util
81
+ #
82
+ # @param vm_name [String] vagrant vm name
83
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
84
+ # @param value [String] path to use for virtualbx vms
85
+ def set_vbmanage_machinefolder(vm_name, vm_config, value = nil)
86
+ value = value || ENV['UPLF_VBMANAGE_MACHINEFOLDER']
87
+
88
+ if !value.to_s.empty?
89
+ log_info("#{vm_name}: vboxmanage machinefolder: #{value}")
90
+ system("vboxmanage setproperty machinefolder #{value}")
91
+
92
+ _track_ai_event(__method__, {
93
+ 'vm_name': vm_name
94
+ })
95
+ end
96
+ end
97
+
98
+ # Resets 'machinefolder' property to default using 'vboxmanage' util
99
+ def set_vbmanage_machinefolder_default()
100
+ system("vboxmanage setproperty machinefolder default")
101
+ _track_ai_event(__method__, {
102
+ 'vm_name': vm_name
103
+ })
104
+ end
105
+
106
+ # network helpers
107
+ def get_network_range
108
+ @@network_range
109
+ end
110
+
111
+ # Sets network range to be used in the multi-vm setup
112
+ #
113
+ # @param value [String] network range such as '192.168.10'
114
+ def set_network_range(value)
115
+ @@network_range = value
116
+ end
117
+
118
+ def get_ip_for_host(host_name)
119
+ start_index = 6
120
+
121
+ file_path = get_uplift_config_file
122
+
123
+ if(!File.exist? file_path)
124
+ File.open(file_path,"w") do |f|
125
+ f.write({}.to_yaml)
126
+ end
127
+ end
128
+
129
+ map = YAML.load_file(file_path)
130
+
131
+ if map.nil?
132
+ map = {}
133
+ end
134
+
135
+ network_range = get_network_range
136
+
137
+ ip_ranges_key = network_range
138
+ machine_key = host_name.downcase
139
+
140
+ ips = map.fetch(ip_ranges_key, { })
141
+ machine_ip = ips.fetch(machine_key, nil)
142
+
143
+ if machine_ip.nil?
144
+ machine_ip = network_range + "." + (start_index + ips.count).to_s
145
+ end
146
+
147
+ ips[machine_key] = machine_ip
148
+ map[ip_ranges_key] = ips
149
+
150
+ File.open(file_path,"w") do |f|
151
+ f.write(map.to_yaml)
152
+ end
153
+
154
+ machine_ip
155
+ end
156
+
157
+ # log helpers
158
+ def log_warn(message)
159
+ _logger.warn(message)
160
+ end
161
+
162
+ def log_warning(message)
163
+ _logger.warn(message)
164
+ end
165
+
166
+ def log_info(message)
167
+ _logger.info(message)
168
+ end
169
+
170
+ def log_info_light(message)
171
+ _logger.info_light(message)
172
+ end
173
+
174
+ def log_debug(message)
175
+ _logger.debug(message)
176
+ end
177
+
178
+ def log_error(message)
179
+ _logger.error(message)
180
+ end
181
+
182
+ def log_error_and_raise(message)
183
+ log_error(message)
184
+ raise(message)
185
+ end
186
+
187
+ # Returns env variable value by name or default value
188
+ #
189
+ # @param name [String] env value name
190
+ # @param default_value [object] default value
191
+ # @return [object] env value
192
+ def get_env_variable(name, default_value)
193
+ var_name = name.upcase
194
+ var_value = ENV[var_name]
195
+
196
+ if var_value.to_s.empty?
197
+ return default_value
198
+ end
199
+
200
+ return var_value
201
+ end
202
+
203
+ # Returns cpus count for the giving vm name
204
+ #
205
+ # @param vm_name [String] vm name
206
+ # @param default_value [object] default value
207
+ # @return [String] cpus count
208
+ def get_vm_cpus(vm_name, default_value)
209
+ require_string(vm_name)
210
+ require_integer(default_value)
211
+
212
+ return get_env_variable("UPLF_#{vm_name}_CPUS", default_value)
213
+ end
214
+
215
+ # Returns memory value for the giving vm name
216
+ #
217
+ # @param vm_name [String] vm name
218
+ # @param default_value [object] default value
219
+ # @return [String] memory value
220
+ def get_vm_memory(vm_name, default_value)
221
+ require_string(vm_name)
222
+ require_integer(default_value)
223
+
224
+ return get_env_variable("UPLF_#{vm_name}_MEMORY", default_value)
225
+ end
226
+
227
+ # Returns checkpoint flag for the giving vm
228
+ #
229
+ # @param vm_name [String] vm name
230
+ # @param checkpoint_name [String] checkpoint name
231
+ # @return [Boolean] memory value
232
+ def has_checkpoint?(vm_name, checkpoint_name)
233
+
234
+ if !ENV['UPLF_NO_VAGRANT_CHECKPOINTS'].nil?
235
+ _log.info("#{vm_name}: [-] provision checkpoint: #{checkpoint_name} (UPLF_NO_VAGRANT_CHECKPOINTS is set)")
236
+
237
+ return false
238
+ end
239
+
240
+ file_name = ".vagrant/machines/#{vm_name}/virtualbox/.uplift/.checkpoint-#{checkpoint_name}"
241
+ exists = File.exist?(file_name)
242
+
243
+ if exists == true
244
+ _log.info_light("#{vm_name}: [+] provision checkpoint: #{checkpoint_name}")
245
+ else
246
+ _log.info("#{vm_name}: [-] provision checkpoint: #{checkpoint_name}")
247
+ end
248
+
249
+ return exists
250
+ end
251
+
252
+ # Configures vagrant vm with 0.5G and 2 CPUs
253
+ #
254
+ # @param vm_name [String] vm name
255
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
256
+ def set_05Gb(vm_name, vm_config)
257
+ require_string(vm_name)
258
+ require_vagrant_config(vm_config)
259
+
260
+ set_cpu_and_ram(vm_name, vm_config, 2, 512)
261
+ end
262
+
263
+ # Configures vagrant vm with 1G and 2 CPUs
264
+ #
265
+ # @param vm_name [String] vm name
266
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
267
+ def set_1Gb(vm_name, vm_config)
268
+ require_string(vm_name)
269
+ require_vagrant_config(vm_config)
270
+
271
+ set_cpu_and_ram(vm_name, vm_config, 2, 1024)
272
+ end
273
+
274
+ # Configures vagrant vm with 2G and 2 CPUs
275
+ #
276
+ # @param vm_name [String] vm name
277
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
278
+ def set_2Gb(vm_name, vm_config)
279
+ require_string(vm_name)
280
+ require_vagrant_config(vm_config)
281
+
282
+ set_cpu_and_ram(vm_name, vm_config, 2, 1024 * 2)
283
+ end
284
+
285
+ # Configures vagrant vm with 4G and 4 CPUs
286
+ #
287
+ # @param vm_name [String] vm name
288
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
289
+ def set_4Gb(vm_name, vm_config)
290
+ require_string(vm_name)
291
+ require_vagrant_config(vm_config)
292
+
293
+ set_cpu_and_ram(vm_name, vm_config, 4, 1024 * 4)
294
+ end
295
+
296
+ # Configures vagrant vm with 6G and 4 CPUs
297
+ #
298
+ # @param vm_name [String] vm name
299
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
300
+ def set_6Gb(vm_name, vm_config)
301
+ require_string(vm_name)
302
+ require_vagrant_config(vm_config)
303
+
304
+ set_cpu_and_ram(vm_name, vm_config, 4, 1024 * 6)
305
+ end
306
+
307
+ # Configures vagrant vm with 8G and 4 CPUs
308
+ #
309
+ # @param vm_name [String] vm name
310
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
311
+ def set_8Gb(vm_name, vm_config)
312
+ require_string(vm_name)
313
+ require_vagrant_config(vm_config)
314
+
315
+ set_cpu_and_ram(vm_name, vm_config, 4, 1024 * 8)
316
+ end
317
+
318
+ # Configures vagrant vm with 12G and 4 CPUs
319
+ #
320
+ # @param vm_name [String] vm name
321
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
322
+ def set_12Gb(vm_name, vm_config)
323
+ require_string(vm_name)
324
+ require_vagrant_config(vm_config)
325
+
326
+ set_cpu_and_ram(vm_name, vm_config, 4, 1024 * 12)
327
+ end
328
+
329
+ # Configures vagrant vm with 16G and 4 CPUs
330
+ #
331
+ # @param vm_name [String] vm name
332
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
333
+ def set_16Gb(vm_name, vm_config)
334
+ require_string(vm_name)
335
+ require_vagrant_config(vm_config)
336
+
337
+ set_cpu_and_ram(vm_name, vm_config, 4, 1024 * 16)
338
+ end
339
+
340
+ # Configures vagrant vm with giving RAM and CPUs
341
+ #
342
+ # @param vm_name [String] vm name
343
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
344
+ # @param cpu [String] amount of cpu
345
+ # @param ram [String] amount of ram
346
+ def set_cpu_and_ram(vm_name, vm_config, cpu, ram)
347
+
348
+ ram_in_gb = (ram / 1024.0)
349
+
350
+ # round evertything that bigger that 1
351
+ if ram_in_gb >= 1
352
+ ram_in_gb = ram_in_gb.round
353
+ end
354
+
355
+ log_info_light("#{vm_name}: #{ram_in_gb}Gb RAM, #{cpu} CPU")
356
+
357
+ vm_config.vm.provider "virtualbox" do |v|
358
+
359
+ v.linked_clone = false
360
+
361
+ v.memory = ram
362
+ v.cpus = cpu
363
+
364
+ v.gui = false
365
+
366
+ v.customize ['modifyvm', :id, '--clipboard', 'bidirectional']
367
+ v.customize ["modifyvm", :id, "--vram", 32]
368
+
369
+ v.customize ["modifyvm", :id, "--audio", "none"]
370
+ v.customize ["modifyvm", :id, "--usb", "off"]
371
+
372
+ # if Vagrant::VERSION >= '2.2.3'
373
+ # # Vagrant has detected a configuration issue which exposes a vulnerability with the installed version of VirtualBox
374
+ # # Ensure the guest is trusted to use this configuration or update the NIC type using one of the methods below:
375
+ # # https://www.vagrantup.com/docs/virtualbox/configuration.html#default-nic-type
376
+
377
+ # v.default_nic_type = "82543GC"
378
+ # end
379
+
380
+ # https://github.com/hashicorp/vagrant/issues/6812#issuecomment-171981576
381
+ # Vagrant is reconnecting from scratch, sometimes literally before each command in negotiating loop
382
+ v.customize ['modifyvm', :id, "--natdnshostresolver1", "off"]
383
+ end
384
+
385
+ # tracking only our own boxes
386
+ # subpoint | uplift
387
+ box_name = 'other'
388
+ box_version = 'other'
389
+
390
+ begin
391
+ box_name = vm_config.vm.box()
392
+ rescue => e
393
+ box_name = 'not_set'
394
+ end
395
+
396
+ if( box_name.to_s.downcase.start_with?('subpoint') || box_name.to_s.downcase.start_with?('uplift') )
397
+ begin
398
+ box_version = vm_config.vm.box_version()
399
+ rescue => e
400
+ box_version = 'not_set'
401
+ end
402
+ else
403
+ box_name = 'other'
404
+ box_version = 'other'
405
+ end
406
+
407
+ data = {
408
+ 'vm_name': vm_name,
409
+ 'cpus': cpu,
410
+ 'memory': ram,
411
+ 'box_name': box_name,
412
+ 'box_version': box_version
413
+ }
414
+
415
+ _track_ai_event(__method__, data)
416
+ end
417
+
418
+ # Requires value to be integer
419
+ #
420
+ # @param value [object] value
421
+ def require_integer(value)
422
+ if value.is_a?(Integer) != true
423
+ log_error_and_raise("expected integer value, got #{value.class}, #{value.inspect}")
424
+ end
425
+ end
426
+
427
+ # Requires value to be string
428
+ #
429
+ # @param value [String] value
430
+ def require_string(value)
431
+ if value.nil? == true || value.to_s.empty?
432
+ log_error_and_raise("expected string value, got nil or empty string")
433
+ end
434
+
435
+ if value.is_a?(String) != true
436
+ log_error_and_raise("expected string value, got #{value.class}, #{value.inspect}")
437
+ end
438
+
439
+ end
440
+
441
+ # Requires value to be [Vagrant::Config::V2::Root]
442
+ #
443
+ # @param value [object] value
444
+ def require_vagrant_config(value)
445
+ if value.nil? == true
446
+ log_error_and_raise("expected string value, got nil or empty string")
447
+ end
448
+
449
+ if value.is_a?(Vagrant::Config::V2::Root) != true
450
+ log_error_and_raise("expected Vagrant::Config::V2::Root value, got #{value.class}, #{value.inspect}")
451
+ end
452
+
453
+ end
454
+
455
+ # Configures vagrant vm with the default winrm settings
456
+ #
457
+ # @param vm_name [String] vagrant vm name
458
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
459
+ def set_winrm(vm_name, vm_config)
460
+ require_string(vm_name)
461
+ require_vagrant_config(vm_config)
462
+
463
+ log_info_light("#{vm_name}: winrm config")
464
+
465
+ # https://www.vagrantup.com/docs/vagrantfile/winrm_settings.html
466
+
467
+ vm_config.vm.guest = :windows
468
+
469
+ vm_config.vm.boot_timeout = 300
470
+
471
+ vm_config.vm.communicator = "winrm"
472
+ vm_config.winrm.transport = :plaintext
473
+ vm_config.winrm.basic_auth_only = true
474
+
475
+ vm_config.winrm.ssl_peer_verification = false
476
+
477
+ vm_config.winrm.username = "vagrant"
478
+ vm_config.winrm.password = "vagrant"
479
+ end
480
+
481
+ # Disables default synced_folder for vagrant box
482
+ #
483
+ # @param vm_name [String] vagrant vm name
484
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
485
+ def set_default_synced_folder(vm_name, vm_config)
486
+
487
+ require_string(vm_name)
488
+ require_vagrant_config(vm_config)
489
+
490
+ log_info_light("#{vm_name}: synced folders config")
491
+
492
+ vm_config.vm.synced_folder ".", "/vagrant", disabled: true
493
+ end
494
+
495
+ def execute_tests?(vm_config:)
496
+ return true
497
+ end
498
+
499
+ def execute_tests(vm_config:, paths:, env: {}, privileged: false)
500
+
501
+ if !execute_tests?(vm_config: vm_config)
502
+ _log.info " - pester: skipping test execition due to false flag in properties"
503
+ return
504
+ end
505
+
506
+ if !paths.is_a?(Array)
507
+ paths = [paths]
508
+ end
509
+
510
+ paths.each do | path |
511
+ test_path_value = File.basename(path)
512
+
513
+ _log.debug " - pester test path: #{test_path_value}"
514
+ end
515
+
516
+ paths.each do |src_test_path|
517
+
518
+ test_files = Dir[src_test_path]
519
+ test_files_string = "\n - " + test_files.join("\n - ")
520
+ _log.debug " - scanned: #{src_test_path}, found: #{test_files_string}"
521
+
522
+ if test_files.empty?
523
+ _log.warn "[!] cannot find any test files under path: #{src_test_path} - mostlikely, wrong location/pattern"
524
+ end
525
+
526
+ test_files.each do |fname|
527
+
528
+ test_path_value = File.basename(fname)
529
+
530
+ _log.info " - pester test: #{test_path_value}"
531
+ _log.debug "adding test file: #{fname}"
532
+
533
+ src_path = fname
534
+ dst_path = "c:/windows/temp/tests/" + File.basename(fname)
535
+
536
+ vm_config.vm.provision :file do |file|
537
+ file.source = fname
538
+ file.destination = dst_path
539
+ end
540
+
541
+ vm_config.vm.provision "shell",
542
+ inline: "Invoke-Pester -EnableExit -Script #{dst_path}",
543
+ name: dst_path,
544
+ env: env
545
+ end
546
+ end
547
+
548
+ end
549
+
550
+ # Configures hostname for the vagrant box
551
+ #
552
+ # @param vm_name [String] vagrant vm name
553
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
554
+ # @param hostname [String] hostname
555
+ def set_hostname(vm_name, vm_config, hostname)
556
+ require_string(vm_name)
557
+ require_vagrant_config(vm_config)
558
+
559
+ require_string(hostname)
560
+
561
+ log_info_light("#{vm_name}: setitng hostname: #{hostname}")
562
+ vm_config.vm.hostname = hostname
563
+ end
564
+
565
+ # Configures private network for the vagrant box. Use for VMs to be promoted to domain controller.
566
+ #
567
+ # @param vm_name [String] vagrant vm name
568
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
569
+ # @param ip [String] ip value
570
+ # @param gateway [String] gateway value
571
+ def set_private_network(vm_name, vm_config, ip: '', gateway: '')
572
+
573
+ require_string(vm_name)
574
+ require_vagrant_config(vm_config)
575
+
576
+ log_info(" - ip: #{ip}, gateway: #{gateway}")
577
+
578
+ vm_config.vm.network :private_network, ip: ip, gateway: gateway
579
+ end
580
+
581
+ # Configures client network for the vagrant box. Use for VMs to be joined to domain controller.
582
+ #
583
+ # @param vm_name [String] vagrant vm name
584
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
585
+ # @param ip [String] ip value
586
+ # @param gateway [String] gateway value
587
+ def set_client_network(vm_name, vm_config, hostname)
588
+
589
+ require_string(vm_name)
590
+ require_vagrant_config(vm_config)
591
+
592
+ require_string(hostname)
593
+
594
+ network_range = get_network_range
595
+
596
+ dc_ip = "#{network_range}.5"
597
+ machine_ip = get_ip_for_host(hostname)
598
+
599
+ log_info(" - private network: ip: #{machine_ip} gateway: #{network_range}.1")
600
+ vm_config.vm.network :private_network,
601
+ ip: machine_ip, gateway: "#{network_range}.1"
602
+
603
+ log_info(" - fixing secondary network interface: ip: #{machine_ip} dns: #{dc_ip}")
604
+ vm_config.vm.provision "shell",
605
+ path: "#{vagrant_script_path}/vagrant/uplift.vagrant.core/uplift.fix-second-network.ps1",
606
+ args: "-ip #{machine_ip} -dns #{dc_ip}"
607
+ end
608
+
609
+ # Configures private network for the vagrant box to be promoted to domain controller.
610
+ #
611
+ # @param vm_name [String] vagrant vm name
612
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
613
+ def set_private_dc_network(vm_name, vm_config)
614
+ require_string(vm_name)
615
+ require_vagrant_config(vm_config)
616
+
617
+ log_info_light("#{vm_name}: private dc network")
618
+
619
+ network_range = get_network_range
620
+
621
+ set_private_network(
622
+ vm_name,
623
+ vm_config,
624
+ :ip => "#{network_range}.5",
625
+ :gateway => "#{network_range}.1"
626
+ )
627
+
628
+ end
629
+
630
+ # Provisions box with standard config
631
+ #
632
+ # @param vm_name [String] vagrant vm name
633
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
634
+ def provision_win16_dsc_soe(vm_name, vm_config)
635
+
636
+ require_string(vm_name)
637
+ require_vagrant_config(vm_config)
638
+
639
+ log_info_light("#{vm_name}: dsc soe config")
640
+
641
+ vm_config.vm.provision "shell",
642
+ name: "soe.dsc.ps1",
643
+ path: "#{vagrant_script_path}/vagrant/uplift.vagrant.win12soe/soe.dsc.ps1",
644
+ env: {
645
+ "UPLF_DSC_CHECK" => 1
646
+ }
647
+
648
+ execute_tests(
649
+ vm_config: vm_config,
650
+ paths: "#{vagrant_script_path}/vagrant/uplift.vagrant.win12soe/tests/soe.dsc.*"
651
+ )
652
+ end
653
+
654
+ # Provisions box with standard shortcuts
655
+ #
656
+ # @param vm_name [String] vagrant vm name
657
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
658
+ def provision_win16_dsc_shortcuts(vm_name, vm_config)
659
+
660
+ require_string(vm_name)
661
+ require_vagrant_config(vm_config)
662
+
663
+ log_info_light("#{vm_name}: dsc soe shortcuts")
664
+
665
+ vm_config.vm.provision "shell",
666
+ name: "soe.shortcuts.dsc.ps1",
667
+ path: "#{vagrant_script_path}/vagrant/uplift.vagrant.win12soe/soe.shortcuts.dsc.ps1",
668
+ env: {
669
+ "UPLF_DSC_CHECK" => 1
670
+ }
671
+ end
672
+
673
+ # Provisions domain controller, minimal config
674
+ #
675
+ # @param vm_name [String] vagrant vm name
676
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
677
+ def provision_win16_dsc_dc(vm_name, vm_config)
678
+
679
+ require_string(vm_name)
680
+ require_vagrant_config(vm_config)
681
+
682
+ log_info(" - dc provision")
683
+
684
+ # just in case there are outstanding tasks
685
+ vm_config.vm.provision "reload"
686
+
687
+ vm_config.vm.provision "shell",
688
+ path: "#{vagrant_script_path}/vagrant/uplift.vagrant.dc12/dc.dsc.ps1",
689
+ name: "dc.dsc.ps1",
690
+ env: {
691
+ "UPLF_DC_DOMAIN_NAME" => "uplift.local",
692
+ "UPLF_DC_DOMAIN_ADMIN_NAME" => "admin",
693
+ "UPLF_DC_DOMAIN_ADMIN_PASSWORD" => "uplift!QAZ",
694
+
695
+ "UPLF_DSC_CHECK_SKIP" => 1
696
+ }
697
+
698
+ vm_config.vm.provision "reload"
699
+
700
+ execute_tests(
701
+ vm_config: vm_config,
702
+ paths: "#{vagrant_script_path}/vagrant/uplift.vagrant.dc12/tests/dc.dsc.*"
703
+ )
704
+
705
+ _track_ai_event(__method__, {
706
+ 'vm_name': vm_name
707
+ })
708
+ end
709
+
710
+ # Provisions domain controller users, minimal config
711
+ #
712
+ # @param vm_name [String] vagrant vm name
713
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
714
+ def provision_win16_dsc_dc_users(vm_name, vm_config)
715
+
716
+ require_string(vm_name)
717
+ require_vagrant_config(vm_config)
718
+
719
+ log_info(" - domain users")
720
+
721
+ vm_config.vm.provision "shell",
722
+ path: "#{vagrant_script_path}/vagrant/uplift.vagrant.dc12/dc.users.dsc.ps1",
723
+ name: 'dc.users.dsc.ps1',
724
+ env: {
725
+ "UPLF_DC_DOMAIN_NAME" => "uplift",
726
+ "UPLF_DC_DOMAIN_ADMIN_NAME" => "admin",
727
+ "UPLF_DC_DOMAIN_ADMIN_PASSWORD" => "uplift!QAZ",
728
+
729
+ "UPLF_VAGRANT_USER_NAME" => "vagrant",
730
+ "UPLF_VAGRANT_USER_PASSWORD" => "vagrant"
731
+ }
732
+
733
+ _track_ai_event(__method__, {
734
+ 'vm_name': vm_name
735
+ })
736
+ end
737
+
738
+ # Provisions domain controller and users, minimal config
739
+ #
740
+ # @param vm_name [String] vagrant vm name
741
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
742
+ def provision_dc16(vm_name, vm_config)
743
+
744
+ require_string(vm_name)
745
+ require_vagrant_config(vm_config)
746
+
747
+ log_info_light("#{vm_name}: domain controller setup")
748
+
749
+ provision_win16_dsc_dc(vm_name, vm_config)
750
+ provision_win16_dsc_dc_users(vm_name, vm_config)
751
+
752
+ _track_ai_event(__method__, {
753
+ 'vm_name': vm_name
754
+ })
755
+ end
756
+
757
+ # Provisions domain join for the giving box
758
+ #
759
+ # @param vm_name [String] vagrant vm name
760
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
761
+ def provision_dc_join(vm_name, vm_config)
762
+
763
+ require_string(vm_name)
764
+ require_vagrant_config(vm_config)
765
+
766
+ log_info_light("#{vm_name}: domain join")
767
+
768
+ network_range = get_network_range
769
+ dc_ip = "#{network_range}.5"
770
+
771
+ log_info(" - dc_ip: #{dc_ip}")
772
+
773
+ vm_config.vm.provision "shell",
774
+ path: "#{vagrant_script_path}/vagrant/uplift.vagrant.dcjoin/dc.join.dsc.ps1",
775
+ env: {
776
+ "UPLF_DC_DOMAIN_NAME" => "uplift",
777
+
778
+ "UPLF_DC_JOIN_USER_NAME" => "admin",
779
+ "UPLF_DC_JOIN_USER_PASSWORD" => "uplift!QAZ",
780
+
781
+ "UPLF_DC_DOMAIN_HOST_IP" => "#{dc_ip}"
782
+ }
783
+
784
+ vm_config.vm.provision "reload"
785
+
786
+ vm_config.vm.provision "shell",
787
+ name: "dc.join.hostname.ps1",
788
+ path: "#{vagrant_script_path}/vagrant/uplift.vagrant.dcjoin/dc.join.hostname.ps1"
789
+
790
+ _track_ai_event(__method__, {
791
+ 'vm_name': vm_name
792
+ })
793
+ end
794
+
795
+ # Provisions SharePoint 2016 pre-setup, prepares box for SharePoint 2016 setup.
796
+ #
797
+ # @param vm_name [String] vagrant vm name
798
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
799
+ def provision_sp16_pre_setup(vm_name, vm_config)
800
+
801
+ require_string(vm_name)
802
+ require_vagrant_config(vm_config)
803
+
804
+ log_info_light("#{vm_name}: SharePoint 2016: farm pre-setup")
805
+
806
+ # shared scripts
807
+ vm_config.vm.provision "file",
808
+ source: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/shared/sp.helpers.ps1",
809
+ destination: "c:/windows/temp/uplift.vagrant.sharepoint/shared/sp.helpers.ps1"
810
+
811
+ # presetup sharepoint farm
812
+ # - fix iss
813
+ # - reboot
814
+ # - restore all services
815
+ vm_config.vm.provision "shell",
816
+ name: 'sp-pre_setup1',
817
+ path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/sp2016.pre_setup1.dsc.ps1"
818
+
819
+ vm_config.vm.provision "reload"
820
+
821
+ vm_config.vm.provision "shell",
822
+ name: 'sp-pre_setup2',
823
+ path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/sp2016.pre_setup2.dsc.ps1"
824
+
825
+ _track_ai_event(__method__, {
826
+ 'vm_name': vm_name
827
+ })
828
+ end
829
+
830
+ # Prepares box for SharePoint 2016 setup.
831
+ # Ensures CredSSP configs and other box-wide changes
832
+ # Normally, should be already done under packer image, this is more of a shortcut for non-uplift boxes
833
+
834
+ # @param vm_name [String] vagrant vm name
835
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
836
+ def provision_sp16_image_setup(vm_name, vm_config)
837
+ require_string(vm_name)
838
+ require_vagrant_config(vm_config)
839
+
840
+ log_info_light("#{vm_name}: SharePoint 2016: image setup")
841
+
842
+ vm_config.vm.provision "shell",
843
+ name: 'image-setup',
844
+ path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/sp2016.sp-image-setup.dsc.ps1"
845
+
846
+ vm_config.vm.provision "reload"
847
+
848
+ vm_config.vm.provision "shell",
849
+ name: 'image-setup-dsc-check',
850
+ path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/sp2016.sp-image-setup.dsc.ps1",
851
+ env: {
852
+ "UPLF_DSC_CHECK" => 1
853
+ }
854
+
855
+ _track_ai_event(__method__, {
856
+ 'vm_name': vm_name
857
+ })
858
+ end
859
+
860
+ # Installs required packages for for SharePoint 2016 setup.
861
+ # Normally, should be already done under packer image, this is more of a shortcut for non-uplift boxes
862
+ #
863
+ # @param vm_name [String] vagrant vm name
864
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
865
+ def provision_sp16_image_packages_setup(vm_name, vm_config)
866
+ require_string(vm_name)
867
+ require_vagrant_config(vm_config)
868
+
869
+ log_info_light("#{vm_name}: SharePoint 2016: image setup")
870
+
871
+ vm_config.vm.provision "shell",
872
+ name: 'image-packages-setup',
873
+ path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/_sp2013_image_packages.dsc.ps1"
874
+
875
+ _track_ai_event(__method__, {
876
+ 'vm_name': vm_name
877
+ })
878
+ end
879
+
880
+ # Prepares SharePoint 2016 setup accounts
881
+ # https://absolute-sharepoint.com/2017/03/sharepoint-2016-service-accounts-recommendations.html
882
+ #
883
+ # @param vm_name [String] vagrant vm name
884
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
885
+ def provision_sp16_sp_accounts(vm_name, vm_config)
886
+ require_string(vm_name)
887
+ require_vagrant_config(vm_config)
888
+
889
+ log_info_light("#{vm_name}: SharePoint 2016: image setup")
890
+
891
+ vm_config.vm.provision "shell",
892
+ name: 'sp-accounts-setup',
893
+ path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/sp2016.sp-accounts.dsc.ps1",
894
+ env: {
895
+ "UPLF_DSC_CHECK" => 1
896
+ }
897
+
898
+ _track_ai_event(__method__, {
899
+ 'vm_name': vm_name
900
+ })
901
+ end
902
+
903
+ # Prepares SharePoint 2016 accounts required for SQL
904
+ #
905
+ # @param vm_name [String] vagrant vm name
906
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
907
+ def provision_sp16_sql_accounts(vm_name, vm_config)
908
+ require_string(vm_name)
909
+ require_vagrant_config(vm_config)
910
+
911
+ log_info_light("#{vm_name}: SharePoint 2016: image setup")
912
+
913
+ vm_config.vm.provision "shell",
914
+ name: 'sp-sql-accounts-setup',
915
+ path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/sp2016.sp-accounts.dsc.ps1",
916
+ env: {
917
+ "UPLF_DSC_CHECK" => 1
918
+ }
919
+
920
+ _track_ai_event(__method__, {
921
+ 'vm_name': vm_name
922
+ })
923
+ end
924
+
925
+ # Provisions SharePoint 2016 post-setup, ensures all services work
926
+ #
927
+ # @param vm_name [String] vagrant vm name
928
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
929
+ def provision_sp16_farm_post_setup(vm_name, vm_config)
930
+
931
+ require_string(vm_name)
932
+ require_vagrant_config(vm_config)
933
+
934
+ log_info_light("#{vm_name}: SharePoint 2016: farm post-setup")
935
+
936
+ vm_config.vm.provision "shell",
937
+ name: 'sp-post-setup',
938
+ path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/sp2016.post_setup.dsc.ps1"
939
+
940
+ _track_ai_event(__method__, {
941
+ 'vm_name': vm_name
942
+ })
943
+ end
944
+
945
+ # Provisions SharePoint 2016 information gatherer
946
+ #
947
+ # @param vm_name [String] vagrant vm name
948
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
949
+ def provision_sp16_print_info(vm_name, vm_config)
950
+
951
+ require_string(vm_name)
952
+ require_vagrant_config(vm_config)
953
+
954
+ log_info_light("#{vm_name}: SharePoint 2016: print info")
955
+
956
+ vm_config.vm.provision "shell",
957
+ path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/sp2016.info.ps1"
958
+
959
+ _track_ai_event(__method__, {
960
+ 'vm_name': vm_name
961
+ })
962
+ end
963
+
964
+ # Provisions SharePoint 2016 SingleServerFarm using SPFarm DSC
965
+ #
966
+ # @param vm_name [String] vagrant vm name
967
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
968
+ # @param sql_server [String] sql server host name
969
+ # @param farm_prefix [String] sql server DBs prefix to use for the current SharePoint farm install
970
+ def provision_sp16_single_server_farm(vm_name, vm_config, sql_server, farm_prefix = nil, dsc_verbose: '1')
971
+
972
+ if farm_prefix.nil?
973
+ farm_prefix = "#{vm_name}_"
974
+ end
975
+
976
+ require_string(vm_name)
977
+ require_vagrant_config(vm_config)
978
+
979
+ require_string(sql_server)
980
+ require_string(farm_prefix)
981
+
982
+ log_info_light("#{vm_name}: SharePoint 2016: farm creation only")
983
+
984
+ # shared scripts
985
+ vm_config.vm.provision "file",
986
+ source: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/shared/sp.helpers.ps1",
987
+ destination: "c:/windows/temp/uplift.vagrant.sharepoint/shared/sp.helpers.ps1"
988
+
989
+ env = {
990
+ "UPLF_sp_farm_sql_server_host_name" => sql_server,
991
+ "UPLF_sp_farm_sql_db_prefix" => "#{farm_prefix}_",
992
+ "UPLF_sp_farm_passphrase" => "uplift!QAZ",
993
+
994
+ "UPLF_sp_setup_user_name" => "uplift\\vagrant",
995
+ "UPLF_sp_setup_user_password" => "vagrant",
996
+ "UPLF_DSC_VERBOSE" => dsc_verbose
997
+ }
998
+
999
+ vm_config.vm.provision "shell",
1000
+ path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/sp2016.farm-only.dsc.ps1",
1001
+ env: env
1002
+
1003
+ _track_ai_event(__method__, {
1004
+ 'vm_name': vm_name
1005
+ })
1006
+ end
1007
+
1008
+ # Provisions SharePoint 2016 minimal services: taxonomy, secure store, state service, search, user profile service and others
1009
+ #
1010
+ # @param vm_name [String] vagrant vm name
1011
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
1012
+ # @param sql_server [String] sql server host name
1013
+ # @param farm_prefix [String] sql server DBs prefix to use for the current SharePoint farm install
1014
+ def provision_sp16_minimal_services(vm_name, vm_config, sql_server, farm_prefix = nil, dsc_verbose: '1', dsc_check: '1')
1015
+
1016
+ if farm_prefix.nil?
1017
+ farm_prefix = "#{vm_name}_"
1018
+ end
1019
+
1020
+ require_string(vm_name)
1021
+ require_vagrant_config(vm_config)
1022
+
1023
+ require_string(sql_server)
1024
+ require_string(farm_prefix)
1025
+
1026
+ log_info_light("#{vm_name}: SharePoint 2016: minimal services: taxonomy, secure store, state service, search, user profile service")
1027
+
1028
+ # shared scripts
1029
+ vm_config.vm.provision "file",
1030
+ source: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/shared/sp.helpers.ps1",
1031
+ destination: "c:/windows/temp/uplift.vagrant.sharepoint/shared/sp.helpers.ps1"
1032
+
1033
+ env = {
1034
+ "UPLF_sp_farm_sql_server_host_name" => sql_server,
1035
+ "UPLF_sp_farm_sql_db_prefix" => "#{farm_prefix}_",
1036
+
1037
+ "UPLF_sp_setup_user_name" => "uplift\\vagrant",
1038
+ "UPLF_sp_setup_user_password" => "vagrant",
1039
+
1040
+ "UPLF_DSC_VERBOSE" => dsc_verbose,
1041
+ "UPLF_DSC_CHECK" => dsc_check,
1042
+ }
1043
+
1044
+ vm_config.vm.provision "shell",
1045
+ name: 'sp-minimal-services',
1046
+ path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/sp2016.farm-minimal-services.dsc.ps1",
1047
+ env: env
1048
+
1049
+ execute_tests(
1050
+ vm_config: vm_config,
1051
+ paths: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/tests/sp2016.minimal-services.Tests.ps1"
1052
+ )
1053
+
1054
+ _track_ai_event(__method__, {
1055
+ 'vm_name': vm_name
1056
+ })
1057
+
1058
+ end
1059
+
1060
+ def provision_sp16_web_application(vm_name, vm_config, dsc_verbose: '1', dsc_check: '1')
1061
+
1062
+ require_string(vm_name)
1063
+ require_vagrant_config(vm_config)
1064
+
1065
+ env = {
1066
+ "UPLF_SP_SETUP_USER_NAME" => "uplift\\vagrant",
1067
+ "UPLF_SP_SETUP_USER_PASSWORD" => "vagrant",
1068
+
1069
+ "UPLF_DSC_VERBOSE" => dsc_verbose,
1070
+ "UPLF_DSC_CHECK" => dsc_check,
1071
+
1072
+ "UPLF_SP_WEB_APP_PORT" => "80"
1073
+ }
1074
+
1075
+ vm_config.vm.provision "shell",
1076
+ name: 'sp-web-application',
1077
+ path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sharepoint/sp2016.web-application.dsc.ps1",
1078
+ env: env
1079
+ end
1080
+
1081
+ # Completes SQL Server image
1082
+ #
1083
+ # @param vm_name [String] vagrant vm name
1084
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
1085
+ def provision_sql16_complete_image(vm_name, vm_config)
1086
+
1087
+ require_string(vm_name)
1088
+ require_vagrant_config(vm_config)
1089
+
1090
+ log_info_light("#{vm_name}: SQL 2016: image completion")
1091
+
1092
+ vm_config.vm.provision "shell",
1093
+ path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sql12/sql.complete.dsc.ps1"
1094
+
1095
+ execute_tests(
1096
+ vm_config: vm_config,
1097
+ paths: "#{vagrant_script_path}/vagrant/uplift.vagrant.sql12/tests/sql16.dsc.*"
1098
+ )
1099
+
1100
+ _track_ai_event(__method__, {
1101
+ 'vm_name': vm_name
1102
+ })
1103
+ end
1104
+
1105
+ # Provisions SQL server optimization
1106
+ # Sets min/max memory and other tweaks
1107
+ #
1108
+ # @param vm_name [String] vagrant vm name
1109
+ # @param vm_config [Vagrant::Config::V2::Root] vagrant vm config
1110
+ # @param min_memory [String] min memory, default 1024
1111
+ # @param max_memory [String] max memory, default 4096
1112
+ def provision_sql16_optimize(vm_name, vm_config,
1113
+ min_memory: 1024, max_memory: 4096, instance_name: 'MSSQLSERVER',
1114
+ dsc_verbose: '1', dsc_check: '1' )
1115
+
1116
+ require_string(vm_name)
1117
+ require_vagrant_config(vm_config)
1118
+
1119
+ log_info_light("#{vm_name}: SQL 2016: optimization")
1120
+
1121
+ vm_config.vm.provision "shell",
1122
+ path: "#{vagrant_script_path}/vagrant/uplift.vagrant.sql12/sql.optimize.dsc.ps1",
1123
+ env: {
1124
+ "UPLF_SQL_SERVER_NAME" => vm_name,
1125
+ "UPLF_SQL_INSTANCE_NAME" => instance_name,
1126
+ "UPLF_SQL_MIN_MEMORY" => min_memory,
1127
+ "UPLF_SQL_MAX_MEMORY" => max_memory,
1128
+
1129
+ "UPLF_DSC_VERBOSE" => dsc_verbose,
1130
+ "UPLF_DSC_CHECK" => dsc_check,
1131
+ }
1132
+
1133
+ _track_ai_event(__method__, {
1134
+ 'vm_name': vm_name
1135
+ })
1136
+ end
1137
+
1138
+ private
1139
+
1140
+ def _logger
1141
+ @@logger = @@logger || VagrantPlugins::Uplift::Log.get_logger
1142
+ @@logger
1143
+ end
1144
+
1145
+ def _ai_client
1146
+ ai_key = ENV['UPLF_APPINSIGHTS_KEY'] || 'c297a2cc-8194-46ac-bf6b-46edd4c7d2c9'
1147
+
1148
+ @@ai_client = @@ai_client || VagrantPlugins::Uplift::AppInsights.get_client(ai_key)
1149
+ @@ai_client
1150
+ end
1151
+
1152
+ def _log
1153
+ _logger
1154
+ end
1155
+
1156
+ def _is_privileged_shell?
1157
+ # https://github.com/hashicorp/vagrant/issues/9138#issuecomment-444408251
1158
+ # https://github.com/clong/DetectionLab/issues/172
1159
+
1160
+ result = Vagrant::VERSION < '2.2.1'
1161
+
1162
+ log_debug "_is_privileged_shell: #{result}"
1163
+
1164
+ result
1165
+ end
1166
+
1167
+ def _is_powershell_elevated_interactive?
1168
+ # https://github.com/hashicorp/vagrant/issues/9138#issuecomment-444408251
1169
+ # https://github.com/clong/DetectionLab/issues/172
1170
+
1171
+ result = Vagrant::VERSION < '2.2.1'
1172
+
1173
+ # join to dc issue
1174
+ # workgroup 'WORKGROUP' with following error message: Unable to update the password. The value
1175
+ # Computer 'WIN-SN2UMLHU29M' failed to join domain 'uplift' from its current workgroup 'WORKGROUP' with following error message: Unable to update the password.
1176
+ # The value provided as the current password is incorrect.
1177
+
1178
+ # http://www.gi-architects.co.uk/2017/01/powershell-add-computer-error-when-executed-remotely/
1179
+
1180
+ log_debug "is_powershell_elevated_interactive: #{result}"
1181
+
1182
+ result
1183
+ end
1184
+
1185
+ def _track_first_initialize()
1186
+ path = File.expand_path(@@config_file_path)
1187
+ FileUtils.mkdir_p path
1188
+
1189
+ first_initialize_file = "#{@@config_file_path}/.appinsights-first-init-#{@@plugin_version}"
1190
+
1191
+ if(File.exist?(first_initialize_file) == false)
1192
+ log_debug("AppInsight: tracking first initialize event")
1193
+ track_ai_event('initialize')
1194
+
1195
+ File.open(first_initialize_file, "w") do |f|
1196
+ f.write("ok")
1197
+ end
1198
+ end
1199
+ end
1200
+
1201
+ def _track_ai_event(name, properties = {})
1202
+ uplift_vagrant_event = 'uplift-vagrant.func'
1203
+
1204
+ log_debug("AppInsight: tracking event: #{name}")
1205
+ _ai_client.track_event(
1206
+ uplift_vagrant_event,
1207
+ properties.merge(_get_default_ai_properties(name))
1208
+ )
1209
+
1210
+ end
1211
+
1212
+ def _get_default_ai_properties(name)
1213
+ {
1214
+ 'plugin_version' => @@plugin_version,
1215
+ 'success' => true,
1216
+ 'ruby_platform' => RUBY_PLATFORM,
1217
+ 'vagrant_version' => Vagrant::VERSION,
1218
+ 'config_id' => @@ai_config_id,
1219
+ 'name' => name
1220
+ }
1221
+ end
1222
+
1223
+ end
1224
+
1225
+ def self.Config
1226
+ return UpliftConfigBuilder.new
1227
+ end
1228
+
1229
+ end
1230
+
1231
+ end