wombat-cli 0.4.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/generator_files/cookbooks/wombat/attributes/default.rb +1 -1
  4. data/generator_files/cookbooks/wombat/metadata.rb +1 -1
  5. data/generator_files/cookbooks/workstation/.kitchen.ec2.yml +1 -1
  6. data/generator_files/cookbooks/workstation/libraries/home.rb +4 -0
  7. data/generator_files/cookbooks/workstation/metadata.rb +1 -1
  8. data/generator_files/cookbooks/workstation/recipes/browser.rb +0 -1
  9. data/generator_files/cookbooks/workstation/recipes/certs-keys.rb +1 -1
  10. data/generator_files/cookbooks/workstation/recipes/chef.rb +0 -1
  11. data/generator_files/cookbooks/workstation/recipes/default.rb +5 -5
  12. data/generator_files/cookbooks/workstation/recipes/editor.rb +2 -3
  13. data/generator_files/cookbooks/workstation/recipes/profile.rb +6 -7
  14. data/generator_files/cookbooks/workstation/recipes/terminal.rb +0 -2
  15. data/generator_files/cookbooks/workstation/test/integration/default/workstation_spec.rb +1 -1
  16. data/generator_files/packer/automate.json +8 -3
  17. data/generator_files/packer/build-node.json +8 -3
  18. data/generator_files/packer/chef-server.json +8 -3
  19. data/generator_files/packer/compliance.json +8 -3
  20. data/generator_files/packer/infranodes-windows.json +8 -3
  21. data/generator_files/packer/infranodes.json +8 -3
  22. data/generator_files/packer/workstation.json +8 -3
  23. data/generator_files/templates/arm.md.json.erb +755 -0
  24. data/generator_files/templates/{arm.json.erb → arm.vhd.json.erb} +62 -7
  25. data/generator_files/templates/bootstrap-aws.erb +3 -0
  26. data/generator_files/wombat.yml +3 -0
  27. data/lib/wombat/build.rb +101 -5
  28. data/lib/wombat/common.rb +26 -3
  29. data/lib/wombat/version.rb +1 -1
  30. data/wombat-cli.gemspec +1 -0
  31. metadata +19 -3
@@ -102,7 +102,7 @@
102
102
  }
103
103
  },
104
104
 
105
- "customData": "#cloud-config\nmanage_etc_hosts: true\n\npackage_update: false"
105
+ "customData": "#cloud-config\nmanage_etc_hosts: false\n\npackage_update: false"
106
106
  },
107
107
  "resources": [
108
108
 
@@ -190,7 +190,7 @@
190
190
  },
191
191
  "osProfile": {
192
192
  "computerName": "[concat(variables('network').ipAddresses.workstation.external.domainNameLabel, '-', '<%= i.to_s %>')]",
193
- "adminUsername": "azure",
193
+ "adminUsername": "chef",
194
194
  "adminPassword": "[parameters('adminPassword')]"
195
195
  },
196
196
  "storageProfile": {
@@ -263,7 +263,18 @@
263
263
  "osProfile": {
264
264
  "computerName": "build-node-<%= i.to_s %>",
265
265
  "adminUsername": "ubuntu",
266
- "adminPassword": "[parameters('adminPassword')]"
266
+ "adminPassword": "[parameters('adminPassword')]",
267
+ "linuxConfiguration": {
268
+ "disablePasswordAuthentication": "true",
269
+ "ssh": {
270
+ "publicKeys": [
271
+ {
272
+ "path": "/home/ubuntu/.ssh/authorized_keys",
273
+ "keyData": "<%= @public_key -%>"
274
+ }
275
+ ]
276
+ }
277
+ }
267
278
  },
268
279
  "storageProfile": {
269
280
  "osDisk": {
@@ -335,7 +346,18 @@
335
346
  "osProfile": {
336
347
  "computerName": "<%= name %>",
337
348
  "adminUsername": "ubuntu",
338
- "adminPassword": "[parameters('adminPassword')]"
349
+ "adminPassword": "[parameters('adminPassword')]",
350
+ "linuxConfiguration": {
351
+ "disablePasswordAuthentication": "true",
352
+ "ssh": {
353
+ "publicKeys": [
354
+ {
355
+ "path": "/home/ubuntu/.ssh/authorized_keys",
356
+ "keyData": "<%= @public_key -%>"
357
+ }
358
+ ]
359
+ }
360
+ }
339
361
  },
340
362
  "storageProfile": {
341
363
  "osDisk": {
@@ -406,7 +428,18 @@
406
428
  "computerName": "[concat('chef-', variables('uniqueShort'))]",
407
429
  "customData": "[base64(concat(variables('customData'), '\n\nruncmd:\n - hostnamectl set-hostname chef\n - chef-server-ctl reconfigure'))]",
408
430
  "adminUsername": "ubuntu",
409
- "adminPassword": "[parameters('adminPassword')]"
431
+ "adminPassword": "[parameters('adminPassword')]",
432
+ "linuxConfiguration": {
433
+ "disablePasswordAuthentication": "true",
434
+ "ssh": {
435
+ "publicKeys": [
436
+ {
437
+ "path": "/home/ubuntu/.ssh/authorized_keys",
438
+ "keyData": "<%= @public_key -%>"
439
+ }
440
+ ]
441
+ }
442
+ }
410
443
  },
411
444
  "storageProfile": {
412
445
  "osDisk": {
@@ -475,7 +508,18 @@
475
508
  "computerName": "[concat('chef-', variables('uniqueShort'))]",
476
509
  "customData": "[base64(concat(variables('customData'), '\n\nruncmd:\n - hostnamectl set-hostname automate\n - chef-server-ctl reconfigure'))]",
477
510
  "adminUsername": "ubuntu",
478
- "adminPassword": "[parameters('adminPassword')]"
511
+ "adminPassword": "[parameters('adminPassword')]",
512
+ "linuxConfiguration": {
513
+ "disablePasswordAuthentication": "true",
514
+ "ssh": {
515
+ "publicKeys": [
516
+ {
517
+ "path": "/home/ubuntu/.ssh/authorized_keys",
518
+ "keyData": "<%= @public_key -%>"
519
+ }
520
+ ]
521
+ }
522
+ }
479
523
  },
480
524
  "storageProfile": {
481
525
  "osDisk": {
@@ -544,7 +588,18 @@
544
588
  "computerName": "[concat('chef-', variables('uniqueShort'))]",
545
589
  "customData": "[base64(concat(variables('customData'), '\n\nruncmd:\n - hostnamectl set-hostname compliance\n - compliance-ctl reconfigure'))]",
546
590
  "adminUsername": "ubuntu",
547
- "adminPassword": "[parameters('adminPassword')]"
591
+ "adminPassword": "[parameters('adminPassword')]",
592
+ "linuxConfiguration": {
593
+ "disablePasswordAuthentication": "true",
594
+ "ssh": {
595
+ "publicKeys": [
596
+ {
597
+ "path": "/home/ubuntu/.ssh/authorized_keys",
598
+ "keyData": "<%= @public_key -%>"
599
+ }
600
+ ]
601
+ }
602
+ }
548
603
  },
549
604
  "storageProfile": {
550
605
  "osDisk": {
@@ -5,6 +5,8 @@ write-host "(host) Running User Data Script"
5
5
 
6
6
  # set administrator password
7
7
  cmd.exe /c net user Administrator <%= @workstation_passwd %>
8
+ cmd.exe /c net user chef <%= @workstation_passwd %> /add /LOGONPASSWORDCHG:NO
9
+ cmd.exe /c net localgroup Administrators /add chef
8
10
 
9
11
  # RDP
10
12
  cmd.exe /c netsh advfirewall firewall add rule name="Open Port 3389" dir=in action=allow protocol=TCP localport=3389
@@ -30,6 +32,7 @@ cmd.exe /c net stop winrm
30
32
  cmd.exe /c sc config winrm start= auto
31
33
  cmd.exe /c net start winrm
32
34
  cmd.exe /c wmic useraccount where "name='Administrator'" set PasswordExpires=FALSE
35
+ cmd.exe /c wmic useraccount where "name='chef'" set PasswordExpires=FALSE
33
36
 
34
37
  set-executionpolicy -executionpolicy bypass -force
35
38
 
@@ -62,6 +62,9 @@ aws:
62
62
  azure:
63
63
  location: eastus
64
64
  storage_account:
65
+ source_image:
66
+ ubuntu: Canonical:UbuntuServer:14.04.5-LTS
67
+ windows: MicrosoftWindowsServer:WindowsServer:2012-R2-Datacenter
65
68
  gce:
66
69
  zone: us-east1-b
67
70
  project: wombat-gce
data/lib/wombat/build.rb CHANGED
@@ -6,13 +6,15 @@ require 'parallel'
6
6
  require 'ms_rest_azure'
7
7
  require 'azure_mgmt_resources'
8
8
  require 'azure_mgmt_storage'
9
+ require 'azure/storage'
10
+ require 'uri'
9
11
 
10
12
  module Wombat
11
13
  class BuildRunner
12
14
  include Wombat::Common
13
15
  include Wombat::Crypto
14
16
 
15
- attr_reader :templates, :builder, :parallel
17
+ attr_reader :templates, :builder, :parallel, :storage_access_key
16
18
 
17
19
  def initialize(opts)
18
20
  @templates = opts.templates.nil? ? calculate_templates : opts.templates
@@ -52,6 +54,10 @@ module Wombat
52
54
  build_parallel(templates)
53
55
  end
54
56
  end
57
+
58
+ # Copy the images to the correct location if running Azure builder
59
+ azure_copy_images if builder == "azure-arm"
60
+
55
61
  shell_out_command("say -v fred \"Wombat has made an #{build_hash.keys}\" for you") if audio?
56
62
  banner("Build finished in #{duration(time.real)}.")
57
63
  end
@@ -97,7 +103,8 @@ module Wombat
97
103
 
98
104
  # Create hash to be used as tags on the resource group
99
105
  tags = {
100
- owner: ENV['USER']
106
+ owner: ENV['USER'],
107
+ provider: azure_provider_tag
101
108
  }
102
109
 
103
110
  # If an owner has been specified in the wombat file override the owner value
@@ -117,7 +124,7 @@ module Wombat
117
124
  wombat['azure']['tags'].each_with_index do |(key, value), index|
118
125
  tags[key] = value
119
126
 
120
- if index == 13
127
+ if index == 12
121
128
  break
122
129
  end
123
130
  end
@@ -147,6 +154,76 @@ module Wombat
147
154
 
148
155
  storage_management_client.storage_accounts.create(wombat['name'], wombat['azure']['storage_account'], storage_account)
149
156
 
157
+ # Get the keys from the storage management client so that the container that the images will be moved into
158
+ # can be checked for and created if required
159
+ # Once Packer uses the MD features in the GO library this can be removed
160
+ # ------------------------------------------------------------------------
161
+ keys = storage_management_client.storage_accounts.list_keys(wombat['name'], wombat['azure']['storage_account'])
162
+ @storage_access_key = keys.keys[0].value
163
+
164
+ # Use the key to configure the storage library
165
+ Azure::Storage.setup(:storage_account_name => wombat['azure']['storage_account'], :storage_access_key => storage_access_key)
166
+ blobs = Azure::Storage::Blob::BlobService.new
167
+
168
+ # Get all the containers to determine if the one that is required already exists
169
+ container_names = []
170
+ blobs.list_containers().each do |container|
171
+ container_names.push(container.name)
172
+ end
173
+
174
+ # create the container if it does not exist
175
+ container_name = "mdimages"
176
+ if !container_names.include?(container_name)
177
+ info("Creating storage container")
178
+ container = blobs.create_container(container_name)
179
+ end
180
+ # ------------------------------------------------------------------------
181
+
182
+ end
183
+
184
+ # Packer does not put custom images into a location that is supported by Managed Disks
185
+ # So to be able to use the MD feature of Azure, the images have to be copied to a location that
186
+ # does work. This method is responsible for doing this work.
187
+ #
188
+ # @author Russell Seymour
189
+ def azure_copy_images()
190
+
191
+ container_name = "mdimages"
192
+
193
+ Azure::Storage.setup(:storage_account_name => wombat['azure']['storage_account'], :storage_access_key => storage_access_key)
194
+ blobs = Azure::Storage::Blob::BlobService.new
195
+
196
+ # Read the logs for azure
197
+ path = "#{wombat['conf']['log_dir']}/azure*.log"
198
+ logs = Dir.glob(path).reject { |l| !l.match(wombat['linux']) }
199
+
200
+ # iterate around the log files and get the image location
201
+ time = Benchmark.measure do
202
+ logs.each do |log|
203
+
204
+ # get the image uri
205
+ url = File.read(log).split("\n").grep(/OSDiskUri:/) {|x| x.split[1]}.last
206
+
207
+ next if url.nil?
208
+
209
+ # Use the storage library to copy the image from source to destination
210
+ uri = URI(url)
211
+
212
+ blob_name = uri.path.split(/\//).last
213
+
214
+ info "Copying: #{blob_name}"
215
+
216
+ status = blobs.copy_blob_from_uri(container_name, blob_name, url)
217
+
218
+ # Append the new location for the image to the log file
219
+ append_text = format("\nManagedDiskOSDiskUri: https://%s.blob.core.windows.net/%s/%s", wombat['azure']['storage_account'], container_name, blob_name)
220
+ File.open(log, 'a') { |f| f.write(append_text) }
221
+
222
+ end
223
+ end
224
+
225
+ info (format("Images copied in %s", duration(time.real)))
226
+
150
227
  end
151
228
 
152
229
  def build(template, options)
@@ -329,9 +406,28 @@ module Wombat
329
406
  cmd.insert(2, "--var gce_source_image=#{base_image(template, builder, options)}") if builder =~ /googlecompute/
330
407
  cmd.insert(2, "--var azure_location=#{wombat['azure']['location']}")
331
408
  cmd.insert(2, "--var ssh_username=#{linux}")
332
- cmd.insert(2, "--var azure_resource_group=#{wombat['name']}")
333
- cmd.insert(2, "--var azure_storage_account=#{wombat['azure']['storage_account']}")
334
409
  cmd.insert(2, "--debug") if @debug
410
+
411
+ # If running with the azure-arm builder add the necessary arguments
412
+ if builder =~ /azure-arm/
413
+
414
+ # Get the information about the base image to use
415
+ base_image = base_image(template, builder, options)
416
+
417
+ if !base_image.nil?
418
+ # This is a URN so it needs to be split out using : as delimiters
419
+ base_image_parts = base_image.split(/:/)
420
+
421
+ cmd.insert(2, "--var azure_image_publisher=#{base_image_parts[0]}")
422
+ cmd.insert(2, "--var azure_image_offer=#{base_image_parts[1]}")
423
+ cmd.insert(2, "--var azure_image_sku=#{base_image_parts[2]}")
424
+ cmd.insert(2, "--var azure_image_version=#{base_image_parts[3]}") if base_image_parts.length == 4
425
+ end
426
+
427
+ cmd.insert(2, "--var azure_resource_group=#{wombat['name']}")
428
+ cmd.insert(2, "--var azure_storage_account=#{wombat['azure']['storage_account']}")
429
+ end
430
+
335
431
  cmd.join(' ')
336
432
  end
337
433
  end
data/lib/wombat/common.rb CHANGED
@@ -60,7 +60,13 @@ module Wombat
60
60
  when 'gcp'
61
61
  'A disk image was created:'
62
62
  when 'azure'
63
- 'OSDiskUri:'
63
+
64
+ if !wombat['azure'].key?('use_managed_disks') || !wombat['azure']['use_managed_disks']
65
+ '^OSDiskUri:'
66
+ else
67
+ '^ManagedDiskOSDiskUri:'
68
+ end
69
+
64
70
  else
65
71
  "#{wombat['aws']['region']}:"
66
72
  end
@@ -226,14 +232,26 @@ module Wombat
226
232
  when 'azure'
227
233
  region = lock['azure']['location']
228
234
  @storage_account = lock['azure']['storage_account']
235
+
229
236
  template_files = {
230
- "arm.json.erb": "#{conf['stack_dir']}/#{@demo}.json",
231
- "arm.tidy.json.erb": "#{conf['stack_dir']}/#{@demo}.tidy.json"
237
+ "arm.tidy.json.erb": format("%s/%s.tidy.json", conf['stack_dir'], @demo)
232
238
  }
239
+
240
+ # determine whether to use VHD or Managed Disks
241
+ if !lock['azure'].key?('use_managed_disks') || !lock['azure']['use_managed_disks']
242
+ template_files['arm.vhd.json.erb'] = format("%s/%s.json", conf['stack_dir'], @demo)
243
+ else
244
+ template_files['arm.md.json.erb'] = format("%s/%s.json", conf['stack_dir'], @demo)
245
+ end
246
+
233
247
  @chef_server_uri = lock['amis'][region]['chef-server']
234
248
  @automate_uri = lock['amis'][region]['automate']
235
249
  @compliance_uri = lock['amis'][region]['compliance']
236
250
  @password = lock['workstations']['password']
251
+ @public_key = File.read("#{conf['key_dir']}/public.pub").chomp
252
+
253
+ # Set the Azure Tag used to identify Chef products in Azure
254
+ @chef_tag = azure_provider_tag
237
255
  when 'gce'
238
256
  region = lock['gce']['zone']
239
257
  end
@@ -278,6 +296,11 @@ module Wombat
278
296
  end
279
297
  end
280
298
 
299
+ # Return the Azure Provider tag that should be applied to resource
300
+ def azure_provider_tag
301
+ "33194f91-eb5f-4110-827a-e95f640a9e46".upcase
302
+ end
303
+
281
304
  # Connect to Azure using environment variables
282
305
  #
283
306
  #
@@ -1,3 +1,3 @@
1
1
  module Wombat
2
- VERSION = "0.4.3"
2
+ VERSION = "0.5.0"
3
3
  end
data/wombat-cli.gemspec CHANGED
@@ -31,4 +31,5 @@ Gem::Specification.new do |gem|
31
31
  gem.add_dependency 'azure_mgmt_resources', '~> 0.9'
32
32
  gem.add_dependency 'azure_mgmt_storage', '~> 0.9'
33
33
  gem.add_dependency 'azure_mgmt_network', '~> 0.9'
34
+ gem.add_dependency 'azure-storage', '~> 0.11.5.preview'
34
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wombat-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andre Elizondo
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-02-23 00:00:00.000000000 Z
12
+ date: 2017-03-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -123,6 +123,20 @@ dependencies:
123
123
  - - "~>"
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0.9'
126
+ - !ruby/object:Gem::Dependency
127
+ name: azure-storage
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: 0.11.5.preview
133
+ type: :runtime
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: 0.11.5.preview
126
140
  description: With a tough barrel-like body, short powerful legs, and long flat claws,
127
141
  the wombat walks with a shuffling gait but is extremely adept at tunneling
128
142
  email:
@@ -272,6 +286,7 @@ files:
272
286
  - generator_files/cookbooks/workstation/files/atom.apm.list
273
287
  - generator_files/cookbooks/workstation/files/atom.config.cson
274
288
  - generator_files/cookbooks/workstation/files/cmder.xml
289
+ - generator_files/cookbooks/workstation/libraries/home.rb
275
290
  - generator_files/cookbooks/workstation/metadata.rb
276
291
  - generator_files/cookbooks/workstation/recipes/browser.rb
277
292
  - generator_files/cookbooks/workstation/recipes/certs-keys.rb
@@ -306,8 +321,9 @@ files:
306
321
  - generator_files/packer/infranodes-windows.json
307
322
  - generator_files/packer/infranodes.json
308
323
  - generator_files/packer/workstation.json
309
- - generator_files/templates/arm.json.erb
324
+ - generator_files/templates/arm.md.json.erb
310
325
  - generator_files/templates/arm.tidy.json.erb
326
+ - generator_files/templates/arm.vhd.json.erb
311
327
  - generator_files/templates/bootstrap-aws.erb
312
328
  - generator_files/templates/cfn.json.erb
313
329
  - generator_files/wombat.yml