vagrant-dsc 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8ec166dab0cf1c326f7d0f943abcee534574d68
4
- data.tar.gz: aad0961c447ebf11921c64c920d43463fb2410b5
3
+ metadata.gz: 8240a3495c72f76f0e6401942afde084014bc466
4
+ data.tar.gz: 3e8f36d14b7ef86b7e556435e8fd3d151f2e0b62
5
5
  SHA512:
6
- metadata.gz: 16b406fbc437d601f40536c687efac1536588655a4813a3592ebfc9f19f0496cfaa1750a87b640d8ba5e429e68e453fd07d45774c1817408e1650b0ad3eac0bb
7
- data.tar.gz: 603e019f5b4444ef240733f8a8eb417f3ed003a3ed394fe64212218736936c5549b8401409d47ea7f901a962d119694411758c9920b26504520631bf1027662d
6
+ metadata.gz: 24fa42974fa2cbf15b6d3e170a4f66a7dcc5b45f405f55a4f693fd93c2c550495f5d9f793adcfbe8749ee88d2d609d4a7f3bfa300723a40cc93a2e717415acbe
7
+ data.tar.gz: e5a2da9736b7bdcd84d10ae2bb5d2a33db9654b34c8c0b256e18e3f46575563e1e6bd2989eda3e266cc967ef4eaed13fe6f4c0829f6799822a8c4a4db737e4f8
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Vagrant DSC Plugin
2
2
 
3
3
  [![Build Status](https://travis-ci.org/mefellows/vagrant-dsc.svg)](https://travis-ci.org/mefellows/vagrant-dsc)
4
- [![Coverage Status](https://coveralls.io/repos/mefellows/vagrant-dsc/badge.png)](https://coveralls.io/r/mefellows/vagrant-dsc)
4
+ [![Coverage Status](https://coveralls.io/repos/mefellows/vagrant-dsc/badge.png?branch=master)](https://coveralls.io/r/mefellows/vagrant-dsc?branch=master)
5
5
  [![Gem Version](https://badge.fury.io/rb/vagrant-dsc.svg)](http://badge.fury.io/rb/vagrant-dsc)
6
6
 
7
7
  [Desired State Configuration](http://technet.microsoft.com/en-au/library/dn249912.aspx) provisioning plugin for Vagrant, enabling you to quickly configure & bootstrap a Windows Virtual Machine in a repeatable, reliable fashion - the Vagrant way.
@@ -33,7 +33,7 @@ In your Vagrantfile, add the following plugin and configure to your needs:
33
33
  # Set of Parameters to pass to the DSC Configuration.
34
34
  #
35
35
  # To pass in flags, simply set the value to `nil`
36
- dsc.configuration_params = {"machineName => "localhost", "-EnableDebug" => nil}
36
+ dsc.configuration_params = {"machineName" => "localhost", "-EnableDebug" => nil}
37
37
 
38
38
  # Relative path to a folder containing a pre-generated MOF file.
39
39
  #
@@ -10,66 +10,28 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
10
10
  # please see the online documentation at vagrantup.com.
11
11
 
12
12
  # Every Vagrant virtual environment requires a box to build off of.
13
- config.vm.box = "win-dev"
13
+ config.vm.box = "kensykora/windows_2012_r2_standard"
14
14
 
15
15
  config.vm.guest = :windows
16
16
  config.vm.communicator = "winrm"
17
17
 
18
- config.vm.network :forwarded_port, guest: 3389, host: 3389
19
18
  config.vm.network :forwarded_port, guest: 5985, host: 5985, id: "winrm", auto_correct: true
20
- config.vm.network :forwarded_port, guest: 80, host: 8000 # Port forward for IIS
19
+ config.vm.network :forwarded_port, guest: 80, host: 8000, id: "web" # Port forward for IIS
20
+ config.vm.network :forwarded_port, guest: 8443, host: 443, id: "ssl" # Port forward for SSL IIS
21
21
 
22
22
  config.vm.provider "virtualbox" do |v|
23
+ v.customize ["modifyvm", :id, "--vram", "128"]
23
24
  v.gui = true
24
25
  end
25
26
 
26
- $script = <<SCRIPT
27
- #
28
- # Script that gets executed on the remote machine
29
- #
30
-
31
- function Write-BootstrapProgress
32
- {
33
- param($message)
34
- Write-Host " ${message}"
35
- }
36
-
37
- # Install Choco if not already installed
38
-
39
- if ( (Get-Command "choco" -errorAction SilentlyContinue) ) {
40
- Write-BootstrapProgress "Chocolatey already installed. Skipping."
41
- } else {
42
- Write-BootstrapProgress "Installing Chocolatey"
43
- $wc=new-object net.webclient; $wp=[system.net.WebProxy]::GetDefaultProxy(); $wp.UseDefaultCredentials=$true; $wc.Proxy=$wp; iex ($wc.DownloadString('https://chocolatey.org/install.ps1'))
44
- # Add to path
45
- $env:Path = $env:Path + ";C:\ProgramData\chocolatey\bin"
46
- [Environment]::SetEnvironmentVariable( "Path", $env:Path, [System.EnvironmentVariableTarget]::Machine )
47
- }
48
-
49
- Write-BootstrapProgress "Installing required software"
50
- if ( -Not (Get-Command "Install-Module" -errorAction SilentlyContinue) ) {
51
- Write-BootstrapProgress "Installing PSGet"
52
- (new-object Net.WebClient).DownloadString("http://psget.net/GetPsGet.ps1") | iex
53
- }
54
- Install-Module Posh-Git
55
-
56
- Write-BootstrapProgress "Installing required packages"
57
- $packages = @(
58
- "git.commandline"
59
- "git"
60
- "seek-dsc"
61
- "NuGet.CommandLine"
62
- "invokemsbuild"
63
- )
64
-
65
- Write-BootstrapProgress "Packages installed"
66
- SCRIPT
67
-
68
- # First pre-configure the machine with required software
69
- config.vm.provision "shell", inline: $script
70
-
71
27
  config.vm.provision "dsc" do |dsc|
72
- # The (Vagrantfile) relative path(s) to any folder containing DSC Resources
28
+
29
+ # Set of module paths relative to the Vagrantfile dir.
30
+ #
31
+ # These paths are added to the DSC Configuration running
32
+ # environment to enable local modules to be addressed.
33
+ #
34
+ # @return [Array] Set of relative module paths.
73
35
  dsc.module_path = ["manifests", "modules"]
74
36
 
75
37
  # The path relative to `dsc.manifests_path` pointing to the Configuration file
@@ -81,12 +43,12 @@ SCRIPT
81
43
 
82
44
  # Commandline arguments to the Configuration run
83
45
  # Set of Parameters to pass to the DSC Configuration.
84
- dsc.configuration_params = {[:machineName] => "localhost"}
46
+ dsc.configuration_params = {"-MachineName" => "localhost"}
85
47
 
86
48
  # Relative path to a pre-generated MOF file.
87
49
  #
88
50
  # Path is relative to the folder containing the Vagrantfile.
89
- #dsc.mof_file = "localhost.mof"
51
+ #dsc.mof_path = "mof"
90
52
 
91
53
  # Relative path to the folder containing the root Configuration manifest file.
92
54
  # Defaults to 'manifests'.
@@ -94,14 +56,6 @@ SCRIPT
94
56
  # Path is relative to the folder containing the Vagrantfile.
95
57
  # dsc.manifests_path = "manifests"
96
58
 
97
- # Set of module paths relative to the Vagrantfile dir.
98
- #
99
- # These paths are added to the DSC Configuration running
100
- # environment to enable local modules to be addressed.
101
- #
102
- # @return [Array] Set of relative module paths.
103
- #dsc.module_path = []
104
-
105
59
  # The type of synced folders to use when sharing the data
106
60
  # required for the provisioner to work properly.
107
61
  #
@@ -96,7 +96,9 @@ module VagrantPlugins
96
96
 
97
97
  verify_dsc
98
98
 
99
- run_dsc_apply(generate_dsc_runner_script)
99
+ write_dsc_runner_script(generate_dsc_runner_script)
100
+
101
+ run_dsc_apply
100
102
  end
101
103
 
102
104
  # Cleanup after a destroy action.
@@ -170,6 +172,7 @@ module VagrantPlugins
170
172
  # @return [String] the Path to the uploaded location on the guest machine.
171
173
  def write_dsc_runner_script(script)
172
174
  guest_script_path = DSC_GUEST_RUNNER_PATH
175
+ # TODO: Get a counter in here in case of multiple runs
173
176
  file = Tempfile.new(["vagrant-dsc-runner", "ps1"])
174
177
  begin
175
178
  file.write(script)
@@ -183,24 +186,9 @@ module VagrantPlugins
183
186
  guest_script_path
184
187
  end
185
188
 
186
- # Runs the DSC Configuration over the guest machine.
187
- #
188
- # Expects
189
+ # Runs the DSC Configuration on the guest machine.
189
190
  def run_dsc_apply
190
-
191
- # Check the DSC_GUEST_RUNNER_PATH exists?
192
-
193
- # Set up Configuration arguments (hostname, manifest/module location, error levels ...)
194
-
195
- # Where are the modules?
196
-
197
- # Where is the manifest
198
-
199
- # TODO: Get a counter in here in case of multiple runs
200
-
201
- # Import starting point configuration into scope
202
-
203
- command = ".\\'#{DSC_GUEST_RUNNER_PATH}'"
191
+ command = ". '#{DSC_GUEST_RUNNER_PATH}'"
204
192
 
205
193
  @machine.ui.info(I18n.t(
206
194
  "vagrant_dsc.running_dsc",
@@ -209,12 +197,21 @@ module VagrantPlugins
209
197
  opts = {
210
198
  elevated: true,
211
199
  error_key: :ssh_bad_exit_status_muted,
212
- good_exit: [0,2],
200
+ good_exit: 0,
201
+ shell: :powershell
213
202
  }
214
203
 
215
204
  @machine.communicate.sudo(command, opts) do |type, data|
216
205
  if !data.chomp.empty?
217
- @machine.ui.info(data.chomp)
206
+ if [:stderr, :stdout].include?(type)
207
+ # Output the data with the proper color based on the stream.
208
+ # TODO: Seems the WinRM communicator or a bug in my powershell code
209
+ # precludes from errors coming back in the :stderr stream
210
+ color = type == :stdout ? :green : :red
211
+ @machine.ui.info(
212
+ data.chomp,
213
+ color: color, new_line: false, prefix: false)
214
+ end
218
215
  end
219
216
  end
220
217
  end
@@ -23,13 +23,11 @@ echo "Running Configuration file: ${script}"
23
23
 
24
24
  cd "<%= options[:temp_path] %>"
25
25
  $StagingPath = $(Join-Path "<%= options[:temp_path] %>" "staging")
26
- <%=options[:configuration_name]%> -MachineName "localhost" -OutputPath $StagingPath <%= options[:parameters] %>
27
- <% else %>
26
+ $response = <%=options[:configuration_name]%> -OutputPath $StagingPath <%= options[:parameters] %> 4>&1 5>&1 | Out-String
27
+ <% else %>
28
28
  $StagingPath = "<%= options[:mof_path] %>"
29
29
  <% end %>
30
30
 
31
31
  # Start a DSC Configuration run
32
- Start-DscConfiguration -Force -Wait -Verbose -Path $StagingPath
33
-
34
- # Cleanup
35
- del -Path $StagingPath -Recurse
32
+ $response += Start-DscConfiguration -Force -Wait -Verbose -Path $StagingPath 4>&1 5>&1 | Out-String
33
+ $response
@@ -1,5 +1,5 @@
1
1
  module Vagrant
2
2
  module Dsc
3
- VERSION = "1.0.0"
3
+ VERSION = "1.0.1"
4
4
  end
5
5
  end
@@ -127,6 +127,7 @@ describe VagrantPlugins::DSC::Provisioner do
127
127
  it "should allow reboot capability when capability exists" do
128
128
  allow(communicator).to receive(:sudo)
129
129
  allow(communicator).to receive(:test)
130
+ allow(communicator).to receive(:upload)
130
131
  allow(subject).to receive(:verify_shared_folders).and_return(true)
131
132
  allow(subject).to receive(:verify_dsc).and_return(true)
132
133
  allow(subject).to receive(:run_dsc_apply).and_return(true)
@@ -139,6 +140,7 @@ describe VagrantPlugins::DSC::Provisioner do
139
140
  it "should not allow reboot capability when capability does not exist" do
140
141
  allow(communicator).to receive(:sudo)
141
142
  allow(communicator).to receive(:test)
143
+ allow(communicator).to receive(:upload)
142
144
  allow(subject).to receive(:verify_shared_folders).and_return(true)
143
145
  allow(subject).to receive(:verify_dsc).and_return(true)
144
146
  allow(subject).to receive(:run_dsc_apply).and_return(true)
@@ -150,6 +152,7 @@ describe VagrantPlugins::DSC::Provisioner do
150
152
 
151
153
  it "should create temporary folders on the guest" do
152
154
  allow(communicator).to receive(:test)
155
+ allow(communicator).to receive(:upload)
153
156
  allow(subject).to receive(:verify_shared_folders).and_return(true)
154
157
  allow(subject).to receive(:verify_dsc).and_return(true)
155
158
  allow(subject).to receive(:run_dsc_apply).and_return(true)
@@ -162,9 +165,28 @@ describe VagrantPlugins::DSC::Provisioner do
162
165
  subject.provision
163
166
  end
164
167
 
168
+ it "should generate and write the runner script to the guest" do
169
+ allow(communicator).to receive(:test)
170
+ allow(communicator).to receive(:upload)
171
+ allow(subject).to receive(:verify_shared_folders).and_return(true)
172
+ allow(subject).to receive(:verify_dsc).and_return(true)
173
+ allow(subject).to receive(:run_dsc_apply).and_return(true)
174
+ allow(guest).to receive(:capability?)
175
+ allow(guest).to receive(:capability)
176
+
177
+ expect(communicator).to receive(:sudo).with("mkdir -p #{root_config.temp_dir}")
178
+ expect(communicator).to receive(:sudo).with("chmod 0777 #{root_config.temp_dir}")
179
+ expect(subject).to receive(:verify_dsc)
180
+ expect(subject).to receive(:write_dsc_runner_script)
181
+ expect(subject).to receive(:run_dsc_apply)
182
+
183
+ subject.provision
184
+ end
185
+
165
186
  it "should ensure shared folders are properly configured" do
166
187
  allow(communicator).to receive(:test)
167
188
  allow(communicator).to receive(:sudo)
189
+ allow(communicator).to receive(:upload)
168
190
  allow(subject).to receive(:verify_dsc).and_return(true)
169
191
  allow(subject).to receive(:run_dsc_apply).and_return(true)
170
192
  allow(guest).to receive(:capability?)
@@ -247,20 +269,14 @@ echo \"Running Configuration file: ${script}\"
247
269
 
248
270
  cd \"/tmp/vagrant-dsc-1\"
249
271
  $StagingPath = $(Join-Path \"/tmp/vagrant-dsc-1\" \"staging\")
250
- MyWebsite -MachineName \"localhost\" -OutputPath $StagingPath
272
+ $response = MyWebsite -OutputPath $StagingPath 4>&1 5>&1 | Out-String
251
273
 
252
274
  # Start a DSC Configuration run
253
- Start-DscConfiguration -Force -Wait -Verbose -Path $StagingPath
254
-
255
- # Cleanup
256
- del -Path $StagingPath -Recurse"
275
+ $response += Start-DscConfiguration -Force -Wait -Verbose -Path $StagingPath 4>&1 5>&1 | Out-String
276
+ $response"
257
277
 
258
278
  expect(script).to eq(expect_script)
259
279
  end
260
-
261
- it "should skip MOF file generation if one already provided" do
262
-
263
- end
264
280
  end
265
281
 
266
282
  context "with custom DSC Parameters" do
@@ -290,13 +306,11 @@ echo \"Running Configuration file: ${script}\"
290
306
 
291
307
  cd \"/tmp/vagrant-dsc-1\"
292
308
  $StagingPath = $(Join-Path \"/tmp/vagrant-dsc-1\" \"staging\")
293
- MyWebsite -MachineName \"localhost\" -OutputPath $StagingPath -Foo \"bar\" -ComputerName \"catz\"
309
+ $response = MyWebsite -OutputPath $StagingPath -Foo \"bar\" -ComputerName \"catz\" 4>&1 5>&1 | Out-String
294
310
 
295
311
  # Start a DSC Configuration run
296
- Start-DscConfiguration -Force -Wait -Verbose -Path $StagingPath
297
-
298
- # Cleanup
299
- del -Path $StagingPath -Recurse"
312
+ $response += Start-DscConfiguration -Force -Wait -Verbose -Path $StagingPath 4>&1 5>&1 | Out-String
313
+ $response"
300
314
 
301
315
  expect(script).to eq(expect_script)
302
316
  end
@@ -327,13 +341,11 @@ echo \"Running Configuration file: ${script}\"
327
341
 
328
342
  cd \"/tmp/vagrant-dsc-1\"
329
343
  $StagingPath = $(Join-Path \"/tmp/vagrant-dsc-1\" \"staging\")
330
- MyWebsite -MachineName \"localhost\" -OutputPath $StagingPath -FooFlag -BarFlag -FooParam \"FooVal\"
344
+ $response = MyWebsite -OutputPath $StagingPath -FooFlag -BarFlag -FooParam \"FooVal\" 4>&1 5>&1 | Out-String
331
345
 
332
346
  # Start a DSC Configuration run
333
- Start-DscConfiguration -Force -Wait -Verbose -Path $StagingPath
334
-
335
- # Cleanup
336
- del -Path $StagingPath -Recurse"
347
+ $response += Start-DscConfiguration -Force -Wait -Verbose -Path $StagingPath 4>&1 5>&1 | Out-String
348
+ $response"
337
349
 
338
350
  expect(script).to eq(expect_script)
339
351
  end
@@ -365,10 +377,8 @@ echo \"Running Configuration file: ${script}\"
365
377
  $StagingPath = \"staging\"
366
378
 
367
379
  # Start a DSC Configuration run
368
- Start-DscConfiguration -Force -Wait -Verbose -Path $StagingPath
369
-
370
- # Cleanup
371
- del -Path $StagingPath -Recurse"
380
+ $response += Start-DscConfiguration -Force -Wait -Verbose -Path $StagingPath 4>&1 5>&1 | Out-String
381
+ $response"
372
382
 
373
383
  expect(script).to eq(expect_script)
374
384
  end
@@ -397,9 +407,19 @@ del -Path $StagingPath -Recurse"
397
407
  describe "Apply DSC" do
398
408
  it "should invoke the DSC Runner and notify the User of provisioning status" do
399
409
  expect(ui).to receive(:info).with(any_args).once
400
- expect(ui).to receive(:info).with("provisioned!").once
410
+ expect(ui).to receive(:info).with("provisioned!", {color: :green, new_line: false, prefix: false}).once
401
411
  allow(machine).to receive(:communicate).and_return(communicator)
402
- expect(communicator).to receive(:sudo).with('.\\' + "'c:/tmp/vagrant-dsc-runner.ps1'",{:elevated=>true, :error_key=>:ssh_bad_exit_status_muted, :good_exit=>[0, 2]}).and_yield("type", "provisioned!")
412
+ expect(communicator).to receive(:sudo).with('. ' + "'c:/tmp/vagrant-dsc-runner.ps1'",{:elevated=>true, :error_key=>:ssh_bad_exit_status_muted, :good_exit=>0, :shell=>:powershell}).and_yield(:stdout, "provisioned!")
413
+
414
+ subject.run_dsc_apply
415
+ end
416
+
417
+ it "should show error output in red" do
418
+ expect(ui).to receive(:info).with(any_args).once
419
+ expect(ui).to receive(:info).with("provisioned!", {color: :red, new_line: false, prefix: false}).once
420
+ allow(machine).to receive(:communicate).and_return(communicator)
421
+ expect(communicator).to receive(:sudo).with('. ' + "'c:/tmp/vagrant-dsc-runner.ps1'",{:elevated=>true, :error_key=>:ssh_bad_exit_status_muted, :good_exit=>0, :shell=>:powershell}).and_yield(:stderr, "provisioned!")
422
+
403
423
  subject.run_dsc_apply
404
424
  end
405
425
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-dsc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Fellows
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-01 00:00:00.000000000 Z
11
+ date: 2014-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake