Created
December 20, 2016 08:50
-
-
Save jugatsu/6751b8221f4f45611073079cd567a866 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ak@ak-pc:~/code/chef/cookbooks/gf_oil$ kitchen converge -l debug | |
-----> Starting Kitchen (v1.14.2) | |
D [Vagrant command] BEGIN (vagrant --version) | |
D [Vagrant command] END (0m0.40s) | |
D [Vagrant command] BEGIN (vagrant plugin list) | |
D [Vagrant command] END (0m1.33s) | |
D Berksfile found at /home/ak/code/chef/cookbooks/gf_oil/Berksfile, loading Berkshelf | |
D Berkshelf 5.2.0 library loaded | |
D winrm requested, loading winrm gem (["~> 2.0"]) | |
D winrm is loaded. | |
D winrm-fs requested, loading winrm-fs gem (["~> 1.0"]) | |
D winrm-fs is loaded. | |
D winrm-elevated requested, loading winrm-elevated gem (["~> 1.0"]) | |
D winrm-elevated is loaded. | |
-----> Converging <default-windows-posready7>... | |
Preparing files for transfer | |
D Creating local sandbox in /tmp/default-windows-posready7-sandbox-20161220-14802-1tboux9 | |
Preparing dna.json | |
D Creating dna.json from {:chocolatey=>{:upgrade=>false}, :run_list=>["recipe[chocolatey::default]"]} | |
Resolving cookbook dependencies with Berkshelf 5.2.0... | |
D Using Berksfile from /home/ak/code/chef/cookbooks/gf_oil/Berksfile | |
Removing non-cookbook files before transfer | |
Preparing validation.pem | |
D Using a dummy validation.pem | |
Preparing client.rb | |
D Creating client.rb from {:node_name=>"default-windows-posready7", :checksum_path=>"\#{ENV['TEMP']}\\kitchen\\checksums", :file_cache_path=>"\#{ENV['TEMP']}\\kitchen\\cache", :file_backup_path=>"\#{ENV['TEMP']}\\kitchen\\backup", :cookbook_path=>["\#{ENV['TEMP']}\\kitchen\\cookbooks", "\#{ENV['TEMP']}\\kitchen\\site-cookbooks"], :data_bag_path=>"\#{ENV['TEMP']}\\kitchen\\data_bags", :environment_path=>"\#{ENV['TEMP']}\\kitchen\\environments", :node_path=>"\#{ENV['TEMP']}\\kitchen\\nodes", :role_path=>"\#{ENV['TEMP']}\\kitchen\\roles", :client_path=>"\#{ENV['TEMP']}\\kitchen\\clients", :user_path=>"\#{ENV['TEMP']}\\kitchen\\users", :validation_key=>"\#{ENV['TEMP']}\\kitchen\\validation.pem", :client_key=>"\#{ENV['TEMP']}\\kitchen\\client.pem", :chef_server_url=>"http://127.0.0.1:8889", :encrypted_data_bag_secret=>"\#{ENV['TEMP']}\\kitchen\\encrypted_data_bag_secret", :treat_deprecation_warnings_as_errors=>false, :named_run_list=>{}} | |
D [WinRM] <{:endpoint=>"http://127.0.0.1:5985/wsman", :user=>"vagrant", :password=>"vagrant", :transport=>:negotiate, :elevated_username=>"vagrant", :elevated_password=>"vagrant", :no_ssl_peer_verification=>true, :disable_sspi=>false, :basic_auth_only=>false}> ($chef_omnibus_root = "$env:systemdrive\opscode\chef" | |
$msi = "/omnibus/cache\chef-true.msi" | |
$download_directory = "/omnibus/cache" | |
$chef_metadata_url = "https://omnitruck.chef.io/metadata?p=windows&m=x86_64&pv=2008r2" | |
$pretty_version = "install only if missing" | |
$version = "true" | |
Function Check-UpdateChef($root, $version) { | |
if (-Not (Test-Path "$root\embedded")) { return $true } | |
elseif ("$version" -eq "true") { return $false } | |
elseif ("$version" -eq "latest") { return $true } | |
Try { $chef_version = (Get-Content $root\version-manifest.txt -ErrorAction stop | select-object -first 1) } | |
Catch { | |
Try { $chef_version = (& $root\bin\chef-solo.bat -v) } | |
Catch { $chef_version = " " } | |
} | |
if ($chef_version.split(" ", 2)[1].StartsWith($version)) { return $false } | |
else { return $true } | |
} | |
Function Get-ChefMetadata($url) { | |
$response = Get-WebContent $url | |
$md = ConvertFrom-StringData $response.Replace("`t", "=") | |
return @($md.url, $md.sha256) | |
} | |
Function Get-SHA256($src) { | |
Try { | |
$c = Get-SHA256Converter | |
$bytes = $c.ComputeHash(($in = (Get-Item $src).OpenRead())) | |
return ([System.BitConverter]::ToString($bytes)).Replace("-", "").ToLower() | |
} Finally { if (($c -ne $null) -and ($c.GetType().GetMethod("Dispose") -ne $null)) { $c.Dispose() }; if ($in -ne $null) { $in.Dispose() } } | |
} | |
function Get-SHA256Converter { | |
if($PSVersionTable.PSEdition -eq 'Core') { | |
[System.Security.Cryptography.SHA256]::Create() | |
} | |
else { | |
New-Object -TypeName Security.Cryptography.SHA256Managed | |
} | |
} | |
Function Download-Chef($url, $sha256, $dst) { | |
Log "Downloading package from $url" | |
Get-WebContent $url $dst | |
Log "Download complete." | |
if ($sha256 -eq $null) { Log "Skipping sha256 verification" } | |
elseif (Verify-SHA256 $dst $sha256) { Log "Successfully verified $dst" } | |
else { throw "SHA256 for $dst does not match $sha256" } | |
} | |
Function Verify-SHA256($path, $sha256) { | |
if ($sha256 -eq $null) { return $false } | |
elseif (($dsha256 = Get-SHA256 $path) -eq $sha256) { return $true } | |
else { return $false } | |
} | |
Function Install-Chef($msi, $chef_omnibus_root) { | |
Log "Installing Chef Omnibus package $msi" | |
$installingChef = $True | |
$installAttempts = 0 | |
while ($installingChef) { | |
$installAttempts++ | |
$result = $false | |
if($msi.EndsWith(".appx")) { | |
$result = Install-ChefAppx $msi $chef_omnibus_root | |
} | |
else { | |
$result = Install-ChefMsi $msi | |
} | |
if(!$result) { continue } | |
$installingChef = $False | |
} | |
Log "Installation complete" | |
} | |
Function Install-ChefMsi($msi) { | |
$p = Start-Process -FilePath "msiexec.exe" -ArgumentList "/qn /i $msi" -Passthru -Wait | |
$p.WaitForExit() | |
if ($p.ExitCode -eq 1618) { | |
Log "Another msi install is in progress (exit code 1618), retrying ($($installAttempts))..." | |
return $false | |
} elseif ($p.ExitCode -ne 0) { | |
throw "msiexec was not successful. Received exit code $($p.ExitCode)" | |
} | |
return $true | |
} | |
Function Install-ChefAppx($appx, $chef_omnibus_root) { | |
Add-AppxPackage -Path $appx -ErrorAction Stop | |
$rootParent = Split-Path $chef_omnibus_root -Parent | |
if(!(Test-Path $rootParent)) { | |
New-Item -ItemType Directory -Path $rootParent | |
} | |
# Remove old version of chef if it is here | |
if(Test-Path $chef_omnibus_root) { | |
Remove-Item -Path $chef_omnibus_root -Recurse -Force | |
} | |
# copy the appx install to the omnibus_root. There are serious | |
# ACL related issues with running chef from the appx InstallLocation | |
# Hoping this is temporary and we can eventually just symlink | |
$package = (Get-AppxPackage -Name chef).InstallLocation | |
Copy-Item $package $chef_omnibus_root -Recurse | |
return $true | |
} | |
Function Log($m) { Write-Host " $m" } | |
function Get-WebContent { | |
param ($uri, $filepath) | |
try { | |
if($PSVersionTable.PSEdition -eq 'Core') { | |
Get-WebContentOnCore $uri $filepath | |
} | |
else { | |
Get-WebContentOnFullNet $uri $filepath | |
} | |
} | |
catch { | |
$exception = $_.Exception | |
Write-Host "There was an error: " | |
do { | |
Write-Host "`t$($exception.message)" | |
$exception = $exception.innerexception | |
} while ($exception) | |
throw "Failed to download from $uri." | |
} | |
} | |
function Get-WebContentOnFullNet { | |
param ($uri, $filepath) | |
$proxy = New-Object -TypeName System.Net.WebProxy | |
$wc = new-object System.Net.WebClient | |
$proxy.Address = $env:http_proxy | |
$wc.Proxy = $proxy | |
if ([string]::IsNullOrEmpty($filepath)) { | |
$wc.downloadstring($uri) | |
} | |
else { | |
$wc.downloadfile($uri, $filepath) | |
} | |
} | |
function Get-WebContentOnCore { | |
param ($uri, $filepath) | |
$handler = New-Object System.Net.Http.HttpClientHandler | |
$client = New-Object System.Net.Http.HttpClient($handler) | |
$client.Timeout = New-Object System.TimeSpan(0, 30, 0) | |
$cancelTokenSource = [System.Threading.CancellationTokenSource]::new() | |
$responseMsg = $client.GetAsync([System.Uri]::new($uri), $cancelTokenSource.Token) | |
$responseMsg.Wait() | |
if (!$responseMsg.IsCanceled) { | |
$response = $responseMsg.Result | |
if ($response.IsSuccessStatusCode) { | |
if ([string]::IsNullOrEmpty($filepath)) { | |
$response.Content.ReadAsStringAsync().Result | |
} | |
else { | |
$downloadedFileStream = [System.IO.FileStream]::new($filepath, [System.IO.FileMode]::Create, [System.IO.FileAccess]::Write) | |
$copyStreamOp = $response.Content.CopyToAsync($downloadedFileStream) | |
$copyStreamOp.Wait() | |
$downloadedFileStream.Close() | |
if ($copyStreamOp.Exception -ne $null) { | |
throw $copyStreamOp.Exception | |
} | |
} | |
} | |
} | |
} | |
Function Unresolve-Path($p) { | |
if ($p -eq $null) { return $null } | |
else { return $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($p) } | |
} | |
$chef_omnibus_root = Unresolve-Path $chef_omnibus_root | |
if (Check-UpdateChef $chef_omnibus_root $version) { | |
Write-Host "-----> Installing Chef Omnibus ($pretty_version)" | |
if ($chef_metadata_url -ne $null) { | |
$url, $sha256 = Get-ChefMetadata "$chef_metadata_url" | |
} else { | |
$url = $chef_msi_url | |
$sha256 = $null | |
} | |
$msi = Join-Path $download_directory "$url".Split("/")[-1] | |
$msi = Unresolve-Path $msi | |
if (Verify-SHA256 $msi $sha256) { | |
Log "Skipping package download; found a matching package at $msi" | |
} else { | |
Download-Chef "$url" $sha256 $msi | |
} | |
Install-Chef $msi $chef_omnibus_root | |
} else { | |
Write-Host "-----> Chef Omnibus installation detected ($pretty_version)" | |
} | |
) | |
D [WinRM] opening remote shell on http://127.0.0.1:5985/wsman | |
D [WinRM] Waiting for output... | |
D [WinRM] Processing output | |
D [WinRM] polling for pipeline state. message: #<WinRM::PSRP::Message:0x00000004824a98 @data="\xEF\xBB\xBF<Obj RefId=\"0\"><MS><Version N=\"protocolversion\">2.1</Version><Version N=\"PSVersion\">2.0</Version><Version N=\"SerializationVersion\">1.1.0.1</Version></MS></Obj>", @destination=1, @type=65538, @pipeline_id="00000000-0000-0000-0000-000000000000", @runspace_pool_id="00000000-0000-0000-0000-000000000000"> | |
D [WinRM] polling for pipeline state. message: #<WinRM::PSRP::Message:0x00000004807088 @data="\xEF\xBB\xBF<Obj RefId=\"0\"><MS><Obj N=\"ApplicationPrivateData\" RefId=\"1\"><TN RefId=\"0\"><T>System.Management.Automation.PSPrimitiveDictionary</T><T>System.Collections.Hashtable</T><T>System.Object</T></TN><DCT><En><S N=\"Key\">PSVersionTable</S><Obj N=\"Value\" RefId=\"2\"><TNRef RefId=\"0\" /><DCT><En><S N=\"Key\">WSManStackVersion</S><Version N=\"Value\">2.0</Version></En><En><S N=\"Key\">PSCompatibleVersions</S><Obj N=\"Value\" RefId=\"3\"><TN RefId=\"1\"><T>System.Version[]</T><T>System.Array</T><T>System.Object</T></TN><LST><Version>1.0</Version><Version>2.0</Version></LST></Obj></En><En><S N=\"Key\">SerializationVersion</S><Version N=\"Value\">1.1.0.1</Version></En><En><S N=\"Key\">BuildVersion</S><Version N=\"Value\">6.1.7601.17514</Version></En><En><S N=\"Key\">PSVersion</S><Version N=\"Value\">2.0</Version></En><En><S N=\"Key\">CLRVersion</S><Version N=\"Value\">2.0.50727.5420</Version></En><En><S N=\"Key\">PSRemotingProtocolVersion</S><Version N=\"Value\">2.1</Version></En></DCT></Obj></En></DCT></Obj></MS></Obj>", @destination=1, @type=135177, @pipeline_id="00000000-0000-0000-0000-000000000000", @runspace_pool_id="00000000-0000-0000-0000-000000000000"> | |
D [WinRM] Waiting for output... | |
D [WinRM] Processing output | |
D [WinRM] polling for pipeline state. message: #<WinRM::PSRP::Message:0x000000045e7aa0 @data="\xEF\xBB\xBF<Obj RefId=\"0\"><MS><I32 N=\"RunspaceState\">2</I32></MS></Obj>", @destination=1, @type=135173, @pipeline_id="00000000-0000-0000-0000-000000000000", @runspace_pool_id="00000000-0000-0000-0000-000000000000"> | |
D [WinRM] remote shell created with shell_id: 40BD3ECA-7FA8-40C1-BBEE-61B465E6FC62 | |
D [WinRM] Command created for $env:temp | |
if (!$?) { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } } with id: ACB4499D-A5E0-409C-9FF2-0965FFE3A3C5 | |
D [WinRM] creating command_id: ACB4499D-A5E0-409C-9FF2-0965FFE3A3C5 on shell_id 40BD3ECA-7FA8-40C1-BBEE-61B465E6FC62 | |
D [WinRM] Waiting for output... | |
D [WinRM] Processing output | |
D [WinRM] cleaning up command_id: ACB4499D-A5E0-409C-9FF2-0965FFE3A3C5 on shell_id 40BD3ECA-7FA8-40C1-BBEE-61B465E6FC62 | |
D creating hash for file c:/windows/temp/winrm-elevated-shell-c084133d-80a8-4624-9774-b1d82ca491ff.ps1 | |
D Running check_files.ps1 | |
D [WinRM] opening remote shell on http://127.0.0.1:5985/wsman | |
D [WinRM] Waiting for output... | |
D [WinRM] Processing output | |
D [WinRM] polling for pipeline state. message: #<WinRM::PSRP::Message:0x0000000471c970 @data="\xEF\xBB\xBF<Obj RefId=\"0\"><MS><Version N=\"protocolversion\">2.1</Version><Version N=\"PSVersion\">2.0</Version><Version N=\"SerializationVersion\">1.1.0.1</Version></MS></Obj>", @destination=1, @type=65538, @pipeline_id="00000000-0000-0000-0000-000000000000", @runspace_pool_id="00000000-0000-0000-0000-000000000000"> | |
D [WinRM] polling for pipeline state. message: #<WinRM::PSRP::Message:0x00000004706eb8 @data="\xEF\xBB\xBF<Obj RefId=\"0\"><MS><Obj N=\"ApplicationPrivateData\" RefId=\"1\"><TN RefId=\"0\"><T>System.Management.Automation.PSPrimitiveDictionary</T><T>System.Collections.Hashtable</T><T>System.Object</T></TN><DCT><En><S N=\"Key\">PSVersionTable</S><Obj N=\"Value\" RefId=\"2\"><TNRef RefId=\"0\" /><DCT><En><S N=\"Key\">WSManStackVersion</S><Version N=\"Value\">2.0</Version></En><En><S N=\"Key\">PSCompatibleVersions</S><Obj N=\"Value\" RefId=\"3\"><TN RefId=\"1\"><T>System.Version[]</T><T>System.Array</T><T>System.Object</T></TN><LST><Version>1.0</Version><Version>2.0</Version></LST></Obj></En><En><S N=\"Key\">SerializationVersion</S><Version N=\"Value\">1.1.0.1</Version></En><En><S N=\"Key\">BuildVersion</S><Version N=\"Value\">6.1.7601.17514</Version></En><En><S N=\"Key\">PSVersion</S><Version N=\"Value\">2.0</Version></En><En><S N=\"Key\">CLRVersion</S><Version N=\"Value\">2.0.50727.5420</Version></En><En><S N=\"Key\">PSRemotingProtocolVersion</S><Version N=\"Value\">2.1</Version></En></DCT></Obj></En></DCT></Obj></MS></Obj>", @destination=1, @type=135177, @pipeline_id="00000000-0000-0000-0000-000000000000", @runspace_pool_id="00000000-0000-0000-0000-000000000000"> | |
D [WinRM] Waiting for output... | |
D [WinRM] Processing output | |
D [WinRM] polling for pipeline state. message: #<WinRM::PSRP::Message:0x00000004963850 @data="\xEF\xBB\xBF<Obj RefId=\"0\"><MS><I32 N=\"RunspaceState\">2</I32></MS></Obj>", @destination=1, @type=135173, @pipeline_id="00000000-0000-0000-0000-000000000000", @runspace_pool_id="00000000-0000-0000-0000-000000000000"> | |
D [WinRM] remote shell created with shell_id: DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D [WinRM] Command created for $hash_file = @{ | |
"2a8d5feaeb90dc85c8797052f5af1fcf" = @{ | |
"target" = "c:/windows/temp/winrm-elevated-shell-c084133d-80a8-4624-9774-b1d82ca491ff.ps1"; | |
"src_basename" = "winrm-elevated-shell20161220-14802-1kk3fagps1"; | |
"dst" = "c:/windows/temp/winrm-elevated-shell-c084133d-80a8-4624-9774-b1d82ca491ff.ps1" | |
} | |
} | |
Function Cleanup($disposable) { | |
if (($disposable -ne $null) -and ($disposable.GetType().GetMethod("Dispose") -ne $null)) { | |
$disposable.Dispose() | |
} | |
} | |
Function Check-Files($h) { | |
return $h.GetEnumerator() | ForEach-Object { | |
$dst = Unresolve-Path $_.Value.target | |
$dst_changed = $false | |
if(Test-Path $dst -PathType Container) { | |
$dst_changed = $true | |
$dst = Join-Path $dst $_.Value.src_basename | |
} | |
New-Object psobject -Property @{ | |
chk_exists = ($exists = Test-Path $dst -PathType Leaf) | |
src_md5 = ($sMd5 = $_.Key) | |
dst_md5 = ($dMd5 = if ($exists) { Get-MD5Sum $dst } else { $null }) | |
chk_dirty = ($dirty = if ($sMd5 -ne $dMd5) { $true } else { $false }) | |
verifies = if ($dirty -eq $false) { $true } else { $false } | |
target_is_folder = $dst_changed | |
} | |
} | Select-Object -Property chk_exists,src_md5,dst_md5,chk_dirty,verifies,target_is_folder | |
} | |
Function Get-MD5Sum($src) { | |
Try { | |
$c = [System.Security.Cryptography.MD5]::Create() | |
$bytes = $c.ComputeHash(($in = (Get-Item $src).OpenRead())) | |
return ([System.BitConverter]::ToString($bytes)).Replace("-", "").ToLower() | |
} | |
Finally { | |
Cleanup $c | |
Cleanup $in | |
} | |
} | |
Function Unresolve-Path($path) { | |
if ($path -eq $null) { | |
return $null | |
} | |
else { | |
return $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($path) | |
} | |
} | |
Check-Files $hash_file | ConvertTo-Csv -NoTypeInformation | |
if (!$?) { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } } with id: 57BEB4B9-F775-49CF-8BDC-836289E432CA | |
D [WinRM] creating command_id: 57BEB4B9-F775-49CF-8BDC-836289E432CA on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D [WinRM] Waiting for output... | |
D [WinRM] Processing output | |
D [WinRM] cleaning up command_id: 57BEB4B9-F775-49CF-8BDC-836289E432CA on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D Parsing CSV Response | |
D "chk_exists","src_md5","dst_md5","chk_dirty","verifies","target_is_folder" | |
"False","2a8d5feaeb90dc85c8797052f5af1fcf",,"True","False","False" | |
D Uploading /tmp/winrm-elevated-shell20161220-14802-1kk3fagps1 to c:/windows/temp/winrm-elevated-shell-c084133d-80a8-4624-9774-b1d82ca491ff.ps1 | |
D [WinRM] Command created for $to = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath("c:/windows/temp/winrm-elevated-shell-c084133d-80a8-4624-9774-b1d82ca491ff.ps1") | |
$parent = Split-Path $to | |
if(!(Test-path $parent)) { mkdir $parent | Out-Null } | |
$fileStream = New-Object -TypeName System.IO.FileStream -ArgumentList @( | |
$to, | |
[system.io.filemode]::Create, | |
[System.io.FileAccess]::Write, | |
[System.IO.FileShare]::ReadWrite | |
) | |
# Powershell caches ScrpitBlocks in a dictionary | |
# keyed on the script block text. Thats just great | |
# unless the script is super large and called a gillion | |
# times like we might do. In such a case it will saturate the | |
# Large Object Heap and lead to Out Of Memory exceptions | |
# for large files or folders. So we call the internal method | |
# ClearScriptBlockCache to clear it. | |
$bindingFlags= [Reflection.BindingFlags] "NonPublic,Static" | |
$method = [scriptblock].GetMethod("ClearScriptBlockCache", $bindingFlags) | |
if (!$?) { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } } with id: F38124B6-8F2D-43F0-AE66-D203D469533C | |
D [WinRM] creating command_id: F38124B6-8F2D-43F0-AE66-D203D469533C on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D [WinRM] Waiting for output... | |
D [WinRM] Processing output | |
D [WinRM] cleaning up command_id: F38124B6-8F2D-43F0-AE66-D203D469533C on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D [WinRM] Command created for if($method) { $method.Invoke($Null, $Null) } | |
$bytes=[Convert]::FromBase64String('JGVudjp0ZW1wPSdDOlxVc2Vyc1x2YWdyYW50XEFwcERhdGFcTG9jYWxcVGVtcCc7JGNoZWZfb21uaWJ1c19yb290ID0gIiRlbnY6c3lzdGVtZHJpdmVcb3BzY29kZVxjaGVmIgokbXNpID0gIi9vbW5pYnVzL2NhY2hlXGNoZWYtdHJ1ZS5tc2kiCiRkb3dubG9hZF9kaXJlY3RvcnkgPSAiL29tbmlidXMvY2FjaGUiCiRjaGVmX21ldGFkYXRhX3VybCA9ICJodHRwczovL29tbml0cnVjay5jaGVmLmlvL21ldGFkYXRhP3A9d2luZG93cyZtPXg4Nl82NCZwdj0yMDA4cjIiCiRwcmV0dHlfdmVyc2lvbiA9ICJpbnN0YWxsIG9ubHkgaWYgbWlzc2luZyIKJHZlcnNpb24gPSAidHJ1ZSIKCkZ1bmN0aW9uIENoZWNrLVVwZGF0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Zk1ldGFkYXRhICIkY2hlZl9tZXRhZGF0YV91cmwiCiAgfSBlbHNlIHsKICAgICR1cmwgPSAkY2hlZl9tc2lfdXJsCiAgICAkc2hhMjU2ID0gJG51bGwKICB9CiAgJG1zaSA9IEpvaW4tUGF0aCAkZG93bmxvYWRfZGlyZWN0b3J5ICIkdXJsIi5TcGxpdCgiLyIpWy0xXQogICRtc2kgPSBVbnJlc29sdmUtUGF0aCAkbXNpCiAgaWYgKFZlcmlmeS1TSEEyNTYgJG1zaSAkc2hhMjU2KSB7CiAgICBMb2cgIlNraXBwaW5nIHBhY2thZ2UgZG93bmxvYWQ7IGZvdW5kIGEgbWF0Y2hpbmcgcGFja2FnZSBhdCAkbXNpIgogIH0gZWxzZSB7CiAgICBEb3dubG9hZC1DaGVmICIkdXJsIiAkc2hhMjU2ICRtc2kKICB9CiAgSW5zdGFsbC1DaGVmICRtc2kgJGNoZWZfb21uaWJ1c19yb290Cn0gZWxzZSB7CiAgV3JpdGUtSG9zdCAiLS0tLS0+IENoZWYgT21uaWJ1cyBpbnN0YWxsYXRpb24gZGV0ZWN0ZWQgKCRwcmV0dHlfdmVyc2lvbikiCn0KDQokSG9zdC5TZXRTaG91bGRFeGl0KCRMQVNURVhJVENPREUp') | |
$fileStream.Write($bytes, 0, $bytes.length) | |
if (!$?) { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } } with id: 945FD701-67A6-490B-AA9F-71A3A55A04BE | |
D [WinRM] creating command_id: 945FD701-67A6-490B-AA9F-71A3A55A04BE on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D [WinRM] Waiting for output... | |
D [WinRM] Processing output | |
D [WinRM] cleaning up command_id: 945FD701-67A6-490B-AA9F-71A3A55A04BE on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D [WinRM] Command created for $fileStream.Dispose() | |
if (!$?) { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } } with id: B256738E-F5A2-42C2-8683-0C69CCA70E4C | |
D [WinRM] creating command_id: B256738E-F5A2-42C2-8683-0C69CCA70E4C on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D [WinRM] Waiting for output... | |
D [WinRM] Processing output | |
D [WinRM] cleaning up command_id: B256738E-F5A2-42C2-8683-0C69CCA70E4C on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D Finished uploading /tmp/winrm-elevated-shell20161220-14802-1kk3fagps1 to c:/windows/temp/winrm-elevated-shell-c084133d-80a8-4624-9774-b1d82ca491ff.ps1 (8.672 KB over 1 chunks) in (0m0.43s) | |
D No remote files to extract, skipping | |
D Uploaded 1 items dirty_check: (0m0.63s) stream_files: (0m0.43s) extract: (0m0.00s) | |
D [WinRM] Command created for $username = 'vagrant' | |
$password = 'vagrant' | |
$script_file = 'c:/windows/temp/winrm-elevated-shell-c084133d-80a8-4624-9774-b1d82ca491ff.ps1' | |
$interactive = 'false' | |
$pass_to_use = $password | |
$logon_type = 1 | |
$logon_type_xml = "<LogonType>Password</LogonType>" | |
if($pass_to_use.length -eq 0) { | |
$pass_to_use = $null | |
$logon_type = 5 | |
$logon_type_xml = "" | |
} | |
if($interactive -eq 'true') { | |
$logon_type = 3 | |
$logon_type_xml = "<LogonType>InteractiveTokenOrPassword</LogonType>" | |
} | |
$task_name = "WinRM_Elevated_Shell" | |
$out_file = [System.IO.Path]::GetTempFileName() | |
$err_file = [System.IO.Path]::GetTempFileName() | |
$task_xml = @' | |
<?xml version="1.0" encoding="UTF-16"?> | |
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"> | |
<Principals> | |
<Principal id="Author"> | |
<UserId>{username}</UserId> | |
{logon_type} | |
<RunLevel>HighestAvailable</RunLevel> | |
</Principal> | |
</Principals> | |
<Settings> | |
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy> | |
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries> | |
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries> | |
<AllowHardTerminate>true</AllowHardTerminate> | |
<StartWhenAvailable>false</StartWhenAvailable> | |
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable> | |
<IdleSettings> | |
<StopOnIdleEnd>false</StopOnIdleEnd> | |
<RestartOnIdle>false</RestartOnIdle> | |
</IdleSettings> | |
<AllowStartOnDemand>true</AllowStartOnDemand> | |
<Enabled>true</Enabled> | |
<Hidden>false</Hidden> | |
<RunOnlyIfIdle>false</RunOnlyIfIdle> | |
<WakeToRun>false</WakeToRun> | |
<ExecutionTimeLimit>PT24H</ExecutionTimeLimit> | |
<Priority>4</Priority> | |
</Settings> | |
<Actions Context="Author"> | |
<Exec> | |
<Command>cmd</Command> | |
<Arguments>{arguments}</Arguments> | |
</Exec> | |
</Actions> | |
</Task> | |
'@ | |
$arguments = "/c powershell.exe -executionpolicy bypass -NoProfile -Command `"[Console]::OutputEncoding = New-Object -typename System.Text.UTF8Encoding;Invoke-Expression (Get-Content $script_file -Encoding UTF8 | Out-String)`" > $out_file 2>$err_file" | |
$task_xml = $task_xml.Replace("{arguments}", $arguments) | |
$task_xml = $task_xml.Replace("{username}", $username) | |
$task_xml = $task_xml.Replace("{logon_type}", $logon_type_xml) | |
$schedule = New-Object -ComObject "Schedule.Service" | |
$schedule.Connect() | |
$task = $schedule.NewTask($null) | |
$task.XmlText = $task_xml | |
$folder = $schedule.GetFolder("\") | |
$folder.RegisterTaskDefinition($task_name, $task, 6, $username, $pass_to_use, $logon_type, $null) | Out-Null | |
$registered_task = $folder.GetTask("\$task_name") | |
$registered_task.Run($null) | Out-Null | |
$timeout = 10 | |
$sec = 0 | |
while ( (!($registered_task.state -eq 4)) -and ($sec -lt $timeout) ) { | |
Start-Sleep -s 1 | |
$sec++ | |
} | |
function SlurpOutput($file, $cur_line, $out_type) { | |
if (Test-Path $file) { | |
get-content $file -Encoding UTF8 | select -skip $cur_line | ForEach { | |
$cur_line += 1 | |
if ($out_type -eq 'err') { | |
$host.ui.WriteErrorLine("$_") | |
} else { | |
$host.ui.WriteLine("$_") | |
} | |
} | |
} | |
return $cur_line | |
} | |
$err_cur_line = 0 | |
$out_cur_line = 0 | |
do { | |
Start-Sleep -m 100 | |
$out_cur_line = SlurpOutput $out_file $out_cur_line 'out' | |
$err_cur_line = SlurpOutput $err_file $err_cur_line 'err' | |
} while (!($registered_task.state -eq 3)) | |
# We'll make a best effort to clean these files | |
# But a reboot could possibly end the task while the process | |
# still runs and locks the file. If we can't delete we don't want to fail | |
try { Remove-Item $out_file -ErrorAction Stop } catch {} | |
try { Remove-Item $err_file -ErrorAction Stop } catch {} | |
try { Remove-Item $script_file -ErrorAction Stop } catch {} | |
$exit_code = $registered_task.LastTaskResult | |
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($schedule) | Out-Null | |
exit $exit_code | |
if (!$?) { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } } with id: 40FA4621-0B32-4B82-966C-FA928C7EE4B6 | |
D [WinRM] creating command_id: 40FA4621-0B32-4B82-966C-FA928C7EE4B6 on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D [WinRM] Waiting for output... | |
D [WinRM] Processing output | |
-----> Chef Omnibus installation detected (install only if missing) | |
D [WinRM] cleaning up command_id: 40FA4621-0B32-4B82-966C-FA928C7EE4B6 on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D [WinRM] <{:endpoint=>"http://127.0.0.1:5985/wsman", :user=>"vagrant", :password=>"vagrant", :transport=>:negotiate, :elevated_username=>"vagrant", :elevated_password=>"vagrant", :no_ssl_peer_verification=>true, :disable_sspi=>false, :basic_auth_only=>false}> ($env:TEST_KITCHEN = "1" | |
$dirs = @("$env:TEMP\kitchen\clients", "$env:TEMP\kitchen\cookbooks", "$env:TEMP\kitchen\data", "$env:TEMP\kitchen\data_bags", "$env:TEMP\kitchen\encrypted_data_bag_secret", "$env:TEMP\kitchen\environments", "$env:TEMP\kitchen\roles") | |
$root_path = "$env:TEMP\kitchen" | |
Function Delete-AllDirs($dirs) { | |
$dirs | ForEach-Object { | |
if (Test-Path ($path = Unresolve-Path $_)) { Remove-Item $path -Recurse -Force } | |
} | |
} | |
Function Unresolve-Path($p) { | |
if ($p -eq $null) { return $null } | |
else { return $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($p) } | |
} | |
Function Make-RootPath($p) { | |
$p = Unresolve-Path $p | |
if (-Not (Test-Path $p)) { New-Item $p -ItemType directory | Out-Null } | |
} | |
Delete-AllDirs $dirs | |
Make-RootPath $root_path | |
) | |
D creating hash for file c:/windows/temp/winrm-elevated-shell-0f2c5445-4051-4558-9bf0-2078310a1fb3.ps1 | |
D Running check_files.ps1 | |
D [WinRM] Command created for $hash_file = @{ | |
"582edbc90b8f2641ac7537f5786ce583" = @{ | |
"target" = "c:/windows/temp/winrm-elevated-shell-0f2c5445-4051-4558-9bf0-2078310a1fb3.ps1"; | |
"src_basename" = "winrm-elevated-shell20161220-14802-xhr55aps1"; | |
"dst" = "c:/windows/temp/winrm-elevated-shell-0f2c5445-4051-4558-9bf0-2078310a1fb3.ps1" | |
} | |
} | |
Function Cleanup($disposable) { | |
if (($disposable -ne $null) -and ($disposable.GetType().GetMethod("Dispose") -ne $null)) { | |
$disposable.Dispose() | |
} | |
} | |
Function Check-Files($h) { | |
return $h.GetEnumerator() | ForEach-Object { | |
$dst = Unresolve-Path $_.Value.target | |
$dst_changed = $false | |
if(Test-Path $dst -PathType Container) { | |
$dst_changed = $true | |
$dst = Join-Path $dst $_.Value.src_basename | |
} | |
New-Object psobject -Property @{ | |
chk_exists = ($exists = Test-Path $dst -PathType Leaf) | |
src_md5 = ($sMd5 = $_.Key) | |
dst_md5 = ($dMd5 = if ($exists) { Get-MD5Sum $dst } else { $null }) | |
chk_dirty = ($dirty = if ($sMd5 -ne $dMd5) { $true } else { $false }) | |
verifies = if ($dirty -eq $false) { $true } else { $false } | |
target_is_folder = $dst_changed | |
} | |
} | Select-Object -Property chk_exists,src_md5,dst_md5,chk_dirty,verifies,target_is_folder | |
} | |
Function Get-MD5Sum($src) { | |
Try { | |
$c = [System.Security.Cryptography.MD5]::Create() | |
$bytes = $c.ComputeHash(($in = (Get-Item $src).OpenRead())) | |
return ([System.BitConverter]::ToString($bytes)).Replace("-", "").ToLower() | |
} | |
Finally { | |
Cleanup $c | |
Cleanup $in | |
} | |
} | |
Function Unresolve-Path($path) { | |
if ($path -eq $null) { | |
return $null | |
} | |
else { | |
return $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($path) | |
} | |
} | |
Check-Files $hash_file | ConvertTo-Csv -NoTypeInformation | |
if (!$?) { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } } with id: 0FD7ECA7-71A5-4E3D-9B84-5F424A2D4560 | |
D [WinRM] creating command_id: 0FD7ECA7-71A5-4E3D-9B84-5F424A2D4560 on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D [WinRM] Waiting for output... | |
D [WinRM] Processing output | |
D [WinRM] cleaning up command_id: 0FD7ECA7-71A5-4E3D-9B84-5F424A2D4560 on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D Parsing CSV Response | |
D "chk_exists","src_md5","dst_md5","chk_dirty","verifies","target_is_folder" | |
"False","582edbc90b8f2641ac7537f5786ce583",,"True","False","False" | |
D Uploading /tmp/winrm-elevated-shell20161220-14802-xhr55aps1 to c:/windows/temp/winrm-elevated-shell-0f2c5445-4051-4558-9bf0-2078310a1fb3.ps1 | |
D [WinRM] Command created for $to = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath("c:/windows/temp/winrm-elevated-shell-0f2c5445-4051-4558-9bf0-2078310a1fb3.ps1") | |
$parent = Split-Path $to | |
if(!(Test-path $parent)) { mkdir $parent | Out-Null } | |
$fileStream = New-Object -TypeName System.IO.FileStream -ArgumentList @( | |
$to, | |
[system.io.filemode]::Create, | |
[System.io.FileAccess]::Write, | |
[System.IO.FileShare]::ReadWrite | |
) | |
# Powershell caches ScrpitBlocks in a dictionary | |
# keyed on the script block text. Thats just great | |
# unless the script is super large and called a gillion | |
# times like we might do. In such a case it will saturate the | |
# Large Object Heap and lead to Out Of Memory exceptions | |
# for large files or folders. So we call the internal method | |
# ClearScriptBlockCache to clear it. | |
$bindingFlags= [Reflection.BindingFlags] "NonPublic,Static" | |
$method = [scriptblock].GetMethod("ClearScriptBlockCache", $bindingFlags) | |
if (!$?) { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } } with id: 8BFE9BE3-BCB3-4B4F-A39A-AE4EB93E378F | |
D [WinRM] creating command_id: 8BFE9BE3-BCB3-4B4F-A39A-AE4EB93E378F on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D [WinRM] Waiting for output... | |
D [WinRM] Processing output | |
D [WinRM] cleaning up command_id: 8BFE9BE3-BCB3-4B4F-A39A-AE4EB93E378F on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D [WinRM] Command created for if($method) { $method.Invoke($Null, $Null) } | |
$bytes=[Convert]::FromBase64String('JGVudjp0ZW1wPSdDOlxVc2Vyc1x2YWdyYW50XEFwcERhdGFcTG9jYWxcVGVtcCc7JGVudjpURVNUX0tJVENIRU4gPSAiMSIKJGRpcnMgPSBAKCIkZW52OlRFTVBca2l0Y2hlblxjbGllbnRzIiwgIiRlbnY6VEVNUFxraXRjaGVuXGNvb2tib29rcyIsICIkZW52OlRFTVBca2l0Y2hlblxkYXRhIiwgIiRlbnY6VEVNUFxraXRjaGVuXGRhdGFfYmFncyIsICIkZW52OlRFTVBca2l0Y2hlblxlbmNyeXB0ZWRfZGF0YV9iYWdfc2VjcmV0IiwgIiRlbnY6VEVNUFxraXRjaGVuXGVudmlyb25tZW50cyIsICIkZW52OlRFTVBca2l0Y2hlblxyb2xlcyIpCiRyb290X3BhdGggPSAiJGVudjpURU1QXGtpdGNoZW4iCgpGdW5jdGlvbiBEZWxldGUtQWxsRGlycygkZGlycykgewogICRkaXJzIHwgRm9yRWFjaC1PYmplY3QgewogICAgaWYgKFRlc3QtUGF0aCAoJHBhdGggPSBVbnJlc29sdmUtUGF0aCAkXykpIHsgUmVtb3ZlLUl0ZW0gJHBhdGggLVJlY3Vyc2UgLUZvcmNlIH0KICB9Cn0KCkZ1bmN0aW9uIFVucmVzb2x2ZS1QYXRoKCRwKSB7CiAgaWYgKCRwIC1lcSAkbnVsbCkgeyByZXR1cm4gJG51bGwgfQogIGVsc2UgeyByZXR1cm4gJEV4ZWN1dGlvbkNvbnRleHQuU2Vzc2lvblN0YXRlLlBhdGguR2V0VW5yZXNvbHZlZFByb3ZpZGVyUGF0aEZyb21QU1BhdGgoJHApIH0KfQoKRnVuY3Rpb24gTWFrZS1Sb290UGF0aCgkcCkgewogICRwID0gVW5yZXNvbHZlLVBhdGggJHAKICBpZiAoLU5vdCAoVGVzdC1QYXRoICRwKSkgeyBOZXctSXRlbSAkcCAtSXRlbVR5cGUgZGlyZWN0b3J5IHwgT3V0LU51bGwgfQp9CgpEZWxldGUtQWxsRGlycyAkZGlycwpNYWtlLVJvb3RQYXRoICRyb290X3BhdGgKDQokSG9zdC5TZXRTaG91bGRFeGl0KCRMQVNURVhJVENPREUp') | |
$fileStream.Write($bytes, 0, $bytes.length) | |
if (!$?) { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } } with id: 463E5E95-E484-4D36-AA0B-A019BB87BFE8 | |
D [WinRM] creating command_id: 463E5E95-E484-4D36-AA0B-A019BB87BFE8 on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D [WinRM] Waiting for output... | |
D [WinRM] Processing output | |
D [WinRM] cleaning up command_id: 463E5E95-E484-4D36-AA0B-A019BB87BFE8 on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D [WinRM] Command created for $fileStream.Dispose() | |
if (!$?) { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } } with id: F2B0185C-DC4D-47C2-A712-CD2A52165D95 | |
D [WinRM] creating command_id: F2B0185C-DC4D-47C2-A712-CD2A52165D95 on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D [WinRM] Waiting for output... | |
D [WinRM] Processing output | |
D [WinRM] cleaning up command_id: F2B0185C-DC4D-47C2-A712-CD2A52165D95 on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D Finished uploading /tmp/winrm-elevated-shell20161220-14802-xhr55aps1 to c:/windows/temp/winrm-elevated-shell-0f2c5445-4051-4558-9bf0-2078310a1fb3.ps1 (1.16 KB over 1 chunks) in (0m0.40s) | |
D No remote files to extract, skipping | |
D Uploaded 1 items dirty_check: (0m0.14s) stream_files: (0m0.40s) extract: (0m0.00s) | |
D [WinRM] Command created for $username = 'vagrant' | |
$password = 'vagrant' | |
$script_file = 'c:/windows/temp/winrm-elevated-shell-0f2c5445-4051-4558-9bf0-2078310a1fb3.ps1' | |
$interactive = 'false' | |
$pass_to_use = $password | |
$logon_type = 1 | |
$logon_type_xml = "<LogonType>Password</LogonType>" | |
if($pass_to_use.length -eq 0) { | |
$pass_to_use = $null | |
$logon_type = 5 | |
$logon_type_xml = "" | |
} | |
if($interactive -eq 'true') { | |
$logon_type = 3 | |
$logon_type_xml = "<LogonType>InteractiveTokenOrPassword</LogonType>" | |
} | |
$task_name = "WinRM_Elevated_Shell" | |
$out_file = [System.IO.Path]::GetTempFileName() | |
$err_file = [System.IO.Path]::GetTempFileName() | |
$task_xml = @' | |
<?xml version="1.0" encoding="UTF-16"?> | |
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"> | |
<Principals> | |
<Principal id="Author"> | |
<UserId>{username}</UserId> | |
{logon_type} | |
<RunLevel>HighestAvailable</RunLevel> | |
</Principal> | |
</Principals> | |
<Settings> | |
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy> | |
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries> | |
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries> | |
<AllowHardTerminate>true</AllowHardTerminate> | |
<StartWhenAvailable>false</StartWhenAvailable> | |
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable> | |
<IdleSettings> | |
<StopOnIdleEnd>false</StopOnIdleEnd> | |
<RestartOnIdle>false</RestartOnIdle> | |
</IdleSettings> | |
<AllowStartOnDemand>true</AllowStartOnDemand> | |
<Enabled>true</Enabled> | |
<Hidden>false</Hidden> | |
<RunOnlyIfIdle>false</RunOnlyIfIdle> | |
<WakeToRun>false</WakeToRun> | |
<ExecutionTimeLimit>PT24H</ExecutionTimeLimit> | |
<Priority>4</Priority> | |
</Settings> | |
<Actions Context="Author"> | |
<Exec> | |
<Command>cmd</Command> | |
<Arguments>{arguments}</Arguments> | |
</Exec> | |
</Actions> | |
</Task> | |
'@ | |
$arguments = "/c powershell.exe -executionpolicy bypass -NoProfile -Command `"[Console]::OutputEncoding = New-Object -typename System.Text.UTF8Encoding;Invoke-Expression (Get-Content $script_file -Encoding UTF8 | Out-String)`" > $out_file 2>$err_file" | |
$task_xml = $task_xml.Replace("{arguments}", $arguments) | |
$task_xml = $task_xml.Replace("{username}", $username) | |
$task_xml = $task_xml.Replace("{logon_type}", $logon_type_xml) | |
$schedule = New-Object -ComObject "Schedule.Service" | |
$schedule.Connect() | |
$task = $schedule.NewTask($null) | |
$task.XmlText = $task_xml | |
$folder = $schedule.GetFolder("\") | |
$folder.RegisterTaskDefinition($task_name, $task, 6, $username, $pass_to_use, $logon_type, $null) | Out-Null | |
$registered_task = $folder.GetTask("\$task_name") | |
$registered_task.Run($null) | Out-Null | |
$timeout = 10 | |
$sec = 0 | |
while ( (!($registered_task.state -eq 4)) -and ($sec -lt $timeout) ) { | |
Start-Sleep -s 1 | |
$sec++ | |
} | |
function SlurpOutput($file, $cur_line, $out_type) { | |
if (Test-Path $file) { | |
get-content $file -Encoding UTF8 | select -skip $cur_line | ForEach { | |
$cur_line += 1 | |
if ($out_type -eq 'err') { | |
$host.ui.WriteErrorLine("$_") | |
} else { | |
$host.ui.WriteLine("$_") | |
} | |
} | |
} | |
return $cur_line | |
} | |
$err_cur_line = 0 | |
$out_cur_line = 0 | |
do { | |
Start-Sleep -m 100 | |
$out_cur_line = SlurpOutput $out_file $out_cur_line 'out' | |
$err_cur_line = SlurpOutput $err_file $err_cur_line 'err' | |
} while (!($registered_task.state -eq 3)) | |
# We'll make a best effort to clean these files | |
# But a reboot could possibly end the task while the process | |
# still runs and locks the file. If we can't delete we don't want to fail | |
try { Remove-Item $out_file -ErrorAction Stop } catch {} | |
try { Remove-Item $err_file -ErrorAction Stop } catch {} | |
try { Remove-Item $script_file -ErrorAction Stop } catch {} | |
$exit_code = $registered_task.LastTaskResult | |
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($schedule) | Out-Null | |
exit $exit_code | |
if (!$?) { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } } with id: 7226565D-C3D9-40B0-A73D-10BF4B04F6D9 | |
D [WinRM] creating command_id: 7226565D-C3D9-40B0-A73D-10BF4B04F6D9 on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D [WinRM] Waiting for output... | |
D [WinRM] Processing output | |
D [WinRM] cleaning up command_id: 7226565D-C3D9-40B0-A73D-10BF4B04F6D9 on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
Transferring files to <default-windows-posready7> | |
D creating hash for directory $env:TEMP\kitchen | |
D Populating files | |
D +++ Adding chocolatey/README.md | |
D +++ Adding chocolatey/attributes/default.rb | |
D +++ Adding chocolatey/libraries/helpers.rb | |
D +++ Adding chocolatey/libraries/matchers.rb | |
D +++ Adding chocolatey/metadata.json | |
D +++ Adding chocolatey/providers/default.rb | |
D +++ Adding chocolatey/recipes/default.rb | |
D +++ Adding chocolatey/resources/default.rb | |
D +++ Adding chocolatey/templates/default/InstallChocolatey.ps1.erb | |
D +++ Adding compat_resource/README.md | |
D +++ Adding compat_resource/files/lib/chef_compat/copied_from_chef/chef/constants.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/copied_from_chef/chef/delayed_evaluator.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/core.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/declare_resource.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/platform_introspection.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/recipe.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/universal.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/lazy_module_include.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/notifying_block.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/params_validate.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/powershell_out.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/copied_from_chef/chef/mixin/properties.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/copied_from_chef/chef/property.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/apt_repository.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/apt_update.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/noop.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/systemd_unit.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider/yum_repository.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/action_class.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/apt_repository.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/apt_update.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/systemd_unit.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource/yum_repository.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource_builder.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/copied_from_chef.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/mixin/properties.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/monkeypatches/chef/exceptions.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/monkeypatches/chef/log.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/monkeypatches/chef/mixin/params_validate.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/monkeypatches/chef/node.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/monkeypatches/chef/property.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/monkeypatches/chef/provider.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/monkeypatches/chef/recipe.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/monkeypatches/chef/recipe_hook.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/monkeypatches/chef/resource/lwrp_base.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/monkeypatches/chef/resource.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/monkeypatches/chef/resource_builder.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/monkeypatches/chef/resource_collection/resource_list.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/monkeypatches/chef/resource_collection/resource_set.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/monkeypatches/chef/resource_collection.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/monkeypatches/chef/run_context.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/monkeypatches/chef/runner.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/monkeypatches/chef.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/monkeypatches.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/property.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/recipe.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/resource/lwrp_base.rb | |
D +++ Adding compat_resource/files/lib/chef_compat/resource.rb | |
D +++ Adding compat_resource/files/lib/chef_upstream_version.rb | |
D +++ Adding compat_resource/files/lib/compat_resource.rb | |
D +++ Adding compat_resource/libraries/autoload.rb | |
D +++ Adding compat_resource/metadata.json | |
D +++ Adding gf_oil/README.md | |
D +++ Adding gf_oil/attributes/default.rb | |
D +++ Adding gf_oil/metadata.json | |
D +++ Adding gf_oil/recipes/default.rb | |
D +++ Adding gf_oil/recipes/os.rb | |
D +++ Adding gf_oil/recipes/packages.rb | |
D +++ Adding ohai/README.md | |
D +++ Adding ohai/libraries/matchers.rb | |
D +++ Adding ohai/metadata.json | |
D +++ Adding ohai/recipes/default.rb | |
D +++ Adding ohai/resources/hint.rb | |
D +++ Adding ohai/resources/plugin.rb | |
D +++ Adding windows/README.md | |
D +++ Adding windows/attributes/default.rb | |
D +++ Adding windows/files/default/dism_features.rb | |
D +++ Adding windows/libraries/feature_base.rb | |
D +++ Adding windows/libraries/matchers.rb | |
D +++ Adding windows/libraries/powershell_helper.rb | |
D +++ Adding windows/libraries/powershell_out.rb | |
D +++ Adding windows/libraries/registry_helper.rb | |
D +++ Adding windows/libraries/version.rb | |
D +++ Adding windows/libraries/version_helper.rb | |
D +++ Adding windows/libraries/windows_helper.rb | |
D +++ Adding windows/libraries/windows_package.rb | |
D +++ Adding windows/libraries/windows_privileged.rb | |
D +++ Adding windows/libraries/wmi_helper.rb | |
D +++ Adding windows/metadata.json | |
D +++ Adding windows/providers/auto_run.rb | |
D +++ Adding windows/providers/certificate.rb | |
D +++ Adding windows/providers/certificate_binding.rb | |
D +++ Adding windows/providers/feature_dism.rb | |
D +++ Adding windows/providers/feature_powershell.rb | |
D +++ Adding windows/providers/feature_servermanagercmd.rb | |
D +++ Adding windows/providers/font.rb | |
D +++ Adding windows/providers/http_acl.rb | |
D +++ Adding windows/providers/pagefile.rb | |
D +++ Adding windows/providers/path.rb | |
D +++ Adding windows/providers/printer.rb | |
D +++ Adding windows/providers/printer_port.rb | |
D +++ Adding windows/providers/shortcut.rb | |
D +++ Adding windows/providers/task.rb | |
D +++ Adding windows/providers/zipfile.rb | |
D +++ Adding windows/recipes/default.rb | |
D +++ Adding windows/resources/auto_run.rb | |
D +++ Adding windows/resources/certificate.rb | |
D +++ Adding windows/resources/certificate_binding.rb | |
D +++ Adding windows/resources/feature.rb | |
D +++ Adding windows/resources/font.rb | |
D +++ Adding windows/resources/http_acl.rb | |
D +++ Adding windows/resources/pagefile.rb | |
D +++ Adding windows/resources/path.rb | |
D +++ Adding windows/resources/printer.rb | |
D +++ Adding windows/resources/printer_port.rb | |
D +++ Adding windows/resources/shortcut.rb | |
D +++ Adding windows/resources/task.rb | |
D +++ Adding windows/resources/zipfile.rb | |
D === All files added. | |
D creating hash for directory $env:TEMP\kitchen | |
D Populating files | |
D === All files added. | |
D creating hash for file $env:TEMP\kitchen | |
D creating hash for file $env:TEMP\kitchen | |
D creating hash for file $env:TEMP\kitchen | |
D Running check_files.ps1 | |
D [WinRM] Command created for $hash_file = @{ | |
"6813c0ead412d13dffaaf8f59b878631" = @{ | |
"target" = "$env:TEMP\winrm-upload\tmpzip-6813c0ead412d13dffaaf8f59b878631.zip"; | |
"src_basename" = "cookbooks"; | |
"dst" = "$env:TEMP\kitchen\cookbooks" | |
}; | |
"76cdb2bad9582d23c1f6f4d868218d6c" = @{ | |
"target" = "$env:TEMP\winrm-upload\tmpzip-76cdb2bad9582d23c1f6f4d868218d6c.zip"; | |
"src_basename" = "cache"; | |
"dst" = "$env:TEMP\kitchen\cache" | |
}; | |
"49abb94825cb80b9a9cd59e5f76daf4a" = @{ | |
"target" = "$env:TEMP\kitchen"; | |
"src_basename" = "validation.pem"; | |
"dst" = "$env:TEMP\kitchen" | |
}; | |
"4299eeac2149fa275d629ea1a8d7e4c2" = @{ | |
"target" = "$env:TEMP\kitchen"; | |
"src_basename" = "dna.json"; | |
"dst" = "$env:TEMP\kitchen" | |
}; | |
"37ab21ff3f023fa19b613e4d69cb643b" = @{ | |
"target" = "$env:TEMP\kitchen"; | |
"src_basename" = "client.rb"; | |
"dst" = "$env:TEMP\kitchen" | |
} | |
} | |
Function Cleanup($disposable) { | |
if (($disposable -ne $null) -and ($disposable.GetType().GetMethod("Dispose") -ne $null)) { | |
$disposable.Dispose() | |
} | |
} | |
Function Check-Files($h) { | |
return $h.GetEnumerator() | ForEach-Object { | |
$dst = Unresolve-Path $_.Value.target | |
$dst_changed = $false | |
if(Test-Path $dst -PathType Container) { | |
$dst_changed = $true | |
$dst = Join-Path $dst $_.Value.src_basename | |
} | |
New-Object psobject -Property @{ | |
chk_exists = ($exists = Test-Path $dst -PathType Leaf) | |
src_md5 = ($sMd5 = $_.Key) | |
dst_md5 = ($dMd5 = if ($exists) { Get-MD5Sum $dst } else { $null }) | |
chk_dirty = ($dirty = if ($sMd5 -ne $dMd5) { $true } else { $false }) | |
verifies = if ($dirty -eq $false) { $true } else { $false } | |
target_is_folder = $dst_changed | |
} | |
} | Select-Object -Property chk_exists,src_md5,dst_md5,chk_dirty,verifies,target_is_folder | |
} | |
Function Get-MD5Sum($src) { | |
Try { | |
$c = [System.Security.Cryptography.MD5]::Create() | |
$bytes = $c.ComputeHash(($in = (Get-Item $src).OpenRead())) | |
return ([System.BitConverter]::ToString($bytes)).Replace("-", "").ToLower() | |
} | |
Finally { | |
Cleanup $c | |
Cleanup $in | |
} | |
} | |
Function Unresolve-Path($path) { | |
if ($path -eq $null) { | |
return $null | |
} | |
else { | |
return $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($path) | |
} | |
} | |
Check-Files $hash_file | ConvertTo-Csv -NoTypeInformation | |
if (!$?) { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } } with id: 62959A95-0876-4F16-978D-106B747DF7A0 | |
D [WinRM] creating command_id: 62959A95-0876-4F16-978D-106B747DF7A0 on shell_id 40BD3ECA-7FA8-40C1-BBEE-61B465E6FC62 | |
D [WinRM] Waiting for output... | |
D [WinRM] Processing output | |
D [WinRM] cleaning up command_id: 62959A95-0876-4F16-978D-106B747DF7A0 on shell_id 40BD3ECA-7FA8-40C1-BBEE-61B465E6FC62 | |
D Parsing CSV Response | |
D "chk_exists","src_md5","dst_md5","chk_dirty","verifies","target_is_folder" | |
"True","76cdb2bad9582d23c1f6f4d868218d6c","76cdb2bad9582d23c1f6f4d868218d6c","False","True","False" | |
"True","6813c0ead412d13dffaaf8f59b878631","6813c0ead412d13dffaaf8f59b878631","False","True","False" | |
"True","37ab21ff3f023fa19b613e4d69cb643b","37ab21ff3f023fa19b613e4d69cb643b","False","True","True" | |
"True","49abb94825cb80b9a9cd59e5f76daf4a","49abb94825cb80b9a9cd59e5f76daf4a","False","True","True" | |
"True","4299eeac2149fa275d629ea1a8d7e4c2","4299eeac2149fa275d629ea1a8d7e4c2","False","True","True" | |
D File $env:TEMP\kitchen\cookbooks is up to date, skipping | |
D File $env:TEMP\kitchen\cache is up to date, skipping | |
D File $env:TEMP\kitchen/validation.pem is up to date, skipping | |
D File $env:TEMP\kitchen/dna.json is up to date, skipping | |
D File $env:TEMP\kitchen/client.rb is up to date, skipping | |
D Running extract_files.ps1 | |
D [WinRM] Command created for trap { | |
$e = $_.Exception | |
$e.InvocationInfo.ScriptName | |
do { | |
$e.Message | |
$e = $e.InnerException | |
} while ($e) | |
break | |
} | |
function folder($path){ | |
$path | ? {-not (test-path $_)} | % {$null = mkdir $_} | |
} | |
Function Decode-Files($hash) { | |
foreach ($key in $hash.keys) { | |
$value = $hash[$key] | |
$tzip, $dst = $Value["tmpzip"], $Value["dst"] | |
if ($tzip) {Unzip-File $tzip $dst} | |
New-Object psobject -Property @{dst=$dst;src_md5=$key;tmpzip=$tzip} | |
} | |
} | |
Function Unzip-File($src, $dst) { | |
$unpack = $src -replace '\.zip' | |
$dst_parent = Split-Path -Path $dst -Parent | |
if(!(Test-Path $dst_parent)) { $dst = $dst_parent } | |
folder $unpack, $dst | |
try { | |
try{ | |
[IO.Compression.ZipFile]::ExtractToDirectory($src, $unpack) | |
} | |
catch { | |
Add-Type -AssemblyName System.IO.Compression.FileSystem -ErrorAction Stop | |
[IO.Compression.ZipFile]::ExtractToDirectory($src, $unpack) | |
} | |
} | |
catch { | |
Try { | |
$s = New-Object -ComObject Shell.Application | |
($s.NameSpace($unpack)).CopyHere(($s.NameSpace($src)).Items(), 0x610) | |
} | |
Finally { | |
[void][Runtime.Interopservices.Marshal]::ReleaseComObject($s) | |
} | |
} | |
dir $unpack | cp -dest "$dst/" -force -recurse | |
rm $unpack -recurse -force | |
} | |
$hash_file = @{ | |
"6813c0ead412d13dffaaf8f59b878631" = @{ | |
"dst" = "$env:TEMP\kitchen\cookbooks"; | |
"tmpzip" = "$env:TEMP\winrm-upload\tmpzip-6813c0ead412d13dffaaf8f59b878631.zip" | |
}; | |
"76cdb2bad9582d23c1f6f4d868218d6c" = @{ | |
"dst" = "$env:TEMP\kitchen\cache"; | |
"tmpzip" = "$env:TEMP\winrm-upload\tmpzip-76cdb2bad9582d23c1f6f4d868218d6c.zip" | |
} | |
} | |
Decode-Files $hash_file | ConvertTo-Csv -NoTypeInformation | |
if (!$?) { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } } with id: 17D47225-3A15-45D1-819F-AB7D106B045F | |
D [WinRM] creating command_id: 17D47225-3A15-45D1-819F-AB7D106B045F on shell_id 40BD3ECA-7FA8-40C1-BBEE-61B465E6FC62 | |
D [WinRM] Waiting for output... | |
D [WinRM] Processing output | |
D [WinRM] Waiting for output... | |
D [WinRM] Processing output | |
D [WinRM] cleaning up command_id: 17D47225-3A15-45D1-819F-AB7D106B045F on shell_id 40BD3ECA-7FA8-40C1-BBEE-61B465E6FC62 | |
D Parsing CSV Response | |
D "tmpzip","src_md5","dst" | |
"C:\Users\vagrant\AppData\Local\Temp\winrm-upload\tmpzip-76cdb2bad9582d23c1f6f4d868218d6c.zip","76cdb2bad9582d23c1f6f4d868218d6c","C:\Users\vagrant\AppData\Local\Temp\kitchen\cache" | |
"C:\Users\vagrant\AppData\Local\Temp\winrm-upload\tmpzip-6813c0ead412d13dffaaf8f59b878631.zip","6813c0ead412d13dffaaf8f59b878631","C:\Users\vagrant\AppData\Local\Temp\kitchen\cookbooks" | |
D Cleaned up src_zip /tmp/tmpzip-20161220-14802-11t7jbi.zip | |
D Cleaned up src_zip /tmp/tmpzip-20161220-14802-y0wakq.zip | |
D Uploaded 5 items dirty_check: (0m0.29s) stream_files: (0m0.00s) extract: (0m2.97s) | |
D Transfer complete | |
D Attempting to execute command - try 1 of 1. | |
D [WinRM] <{:endpoint=>"http://127.0.0.1:5985/wsman", :user=>"vagrant", :password=>"vagrant", :transport=>:negotiate, :elevated_username=>"vagrant", :elevated_password=>"vagrant", :no_ssl_peer_verification=>true, :disable_sspi=>false, :basic_auth_only=>false}> ($env:TEST_KITCHEN = "1" | |
$env:PATH = try { | |
[System.Environment]::GetEnvironmentVariable('PATH','Machine') | |
} catch { $env:PATH } | |
& $env:systemdrive\opscode\chef\bin\chef-client.bat --local-mode --config $env:TEMP\kitchen\client.rb --log_level auto --force-formatter --no-color --json-attributes $env:TEMP\kitchen\dna.json --chef-zero-port 8889 ; exit $LastExitCode) | |
D creating hash for file c:/windows/temp/winrm-elevated-shell-db533f8c-58ea-4b56-8a44-92556ba431ff.ps1 | |
D Running check_files.ps1 | |
D [WinRM] Command created for $hash_file = @{ | |
"0dac0ee601ea2725a94ff33001544650" = @{ | |
"target" = "c:/windows/temp/winrm-elevated-shell-db533f8c-58ea-4b56-8a44-92556ba431ff.ps1"; | |
"src_basename" = "winrm-elevated-shell20161220-14802-1ob7ljops1"; | |
"dst" = "c:/windows/temp/winrm-elevated-shell-db533f8c-58ea-4b56-8a44-92556ba431ff.ps1" | |
} | |
} | |
Function Cleanup($disposable) { | |
if (($disposable -ne $null) -and ($disposable.GetType().GetMethod("Dispose") -ne $null)) { | |
$disposable.Dispose() | |
} | |
} | |
Function Check-Files($h) { | |
return $h.GetEnumerator() | ForEach-Object { | |
$dst = Unresolve-Path $_.Value.target | |
$dst_changed = $false | |
if(Test-Path $dst -PathType Container) { | |
$dst_changed = $true | |
$dst = Join-Path $dst $_.Value.src_basename | |
} | |
New-Object psobject -Property @{ | |
chk_exists = ($exists = Test-Path $dst -PathType Leaf) | |
src_md5 = ($sMd5 = $_.Key) | |
dst_md5 = ($dMd5 = if ($exists) { Get-MD5Sum $dst } else { $null }) | |
chk_dirty = ($dirty = if ($sMd5 -ne $dMd5) { $true } else { $false }) | |
verifies = if ($dirty -eq $false) { $true } else { $false } | |
target_is_folder = $dst_changed | |
} | |
} | Select-Object -Property chk_exists,src_md5,dst_md5,chk_dirty,verifies,target_is_folder | |
} | |
Function Get-MD5Sum($src) { | |
Try { | |
$c = [System.Security.Cryptography.MD5]::Create() | |
$bytes = $c.ComputeHash(($in = (Get-Item $src).OpenRead())) | |
return ([System.BitConverter]::ToString($bytes)).Replace("-", "").ToLower() | |
} | |
Finally { | |
Cleanup $c | |
Cleanup $in | |
} | |
} | |
Function Unresolve-Path($path) { | |
if ($path -eq $null) { | |
return $null | |
} | |
else { | |
return $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($path) | |
} | |
} | |
Check-Files $hash_file | ConvertTo-Csv -NoTypeInformation | |
if (!$?) { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } } with id: D7BB5B1C-387E-4879-92B8-E50C96019C55 | |
D [WinRM] creating command_id: D7BB5B1C-387E-4879-92B8-E50C96019C55 on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D [WinRM] Waiting for output... | |
D [WinRM] Processing output | |
D [WinRM] cleaning up command_id: D7BB5B1C-387E-4879-92B8-E50C96019C55 on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D Parsing CSV Response | |
D "chk_exists","src_md5","dst_md5","chk_dirty","verifies","target_is_folder" | |
"False","0dac0ee601ea2725a94ff33001544650",,"True","False","False" | |
D Uploading /tmp/winrm-elevated-shell20161220-14802-1ob7ljops1 to c:/windows/temp/winrm-elevated-shell-db533f8c-58ea-4b56-8a44-92556ba431ff.ps1 | |
D [WinRM] Command created for $to = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath("c:/windows/temp/winrm-elevated-shell-db533f8c-58ea-4b56-8a44-92556ba431ff.ps1") | |
$parent = Split-Path $to | |
if(!(Test-path $parent)) { mkdir $parent | Out-Null } | |
$fileStream = New-Object -TypeName System.IO.FileStream -ArgumentList @( | |
$to, | |
[system.io.filemode]::Create, | |
[System.io.FileAccess]::Write, | |
[System.IO.FileShare]::ReadWrite | |
) | |
# Powershell caches ScrpitBlocks in a dictionary | |
# keyed on the script block text. Thats just great | |
# unless the script is super large and called a gillion | |
# times like we might do. In such a case it will saturate the | |
# Large Object Heap and lead to Out Of Memory exceptions | |
# for large files or folders. So we call the internal method | |
# ClearScriptBlockCache to clear it. | |
$bindingFlags= [Reflection.BindingFlags] "NonPublic,Static" | |
$method = [scriptblock].GetMethod("ClearScriptBlockCache", $bindingFlags) | |
if (!$?) { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } } with id: EE5D5146-EE58-429E-BDD5-6B114285C8F0 | |
D [WinRM] creating command_id: EE5D5146-EE58-429E-BDD5-6B114285C8F0 on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D [WinRM] Waiting for output... | |
D [WinRM] Processing output | |
D [WinRM] cleaning up command_id: EE5D5146-EE58-429E-BDD5-6B114285C8F0 on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D [WinRM] Command created for if($method) { $method.Invoke($Null, $Null) } | |
$bytes=[Convert]::FromBase64String('JGVudjp0ZW1wPSdDOlxVc2Vyc1x2YWdyYW50XEFwcERhdGFcTG9jYWxcVGVtcCc7JGVudjpURVNUX0tJVENIRU4gPSAiMSIKJGVudjpQQVRIID0gdHJ5IHsKW1N5c3RlbS5FbnZpcm9ubWVudF06OkdldEVudmlyb25tZW50VmFyaWFibGUoJ1BBVEgnLCdNYWNoaW5lJykKfSBjYXRjaCB7ICRlbnY6UEFUSCB9CgomICRlbnY6c3lzdGVtZHJpdmVcb3BzY29kZVxjaGVmXGJpblxjaGVmLWNsaWVudC5iYXQgLS1sb2NhbC1tb2RlIC0tY29uZmlnICRlbnY6VEVNUFxraXRjaGVuXGNsaWVudC5yYiAtLWxvZ19sZXZlbCBhdXRvIC0tZm9yY2UtZm9ybWF0dGVyIC0tbm8tY29sb3IgLS1qc29uLWF0dHJpYnV0ZXMgJGVudjpURU1QXGtpdGNoZW5cZG5hLmpzb24gLS1jaGVmLXplcm8tcG9ydCA4ODg5IDsgZXhpdCAkTGFzdEV4aXRDb2RlDQokSG9zdC5TZXRTaG91bGRFeGl0KCRMQVNURVhJVENPREUp') | |
$fileStream.Write($bytes, 0, $bytes.length) | |
if (!$?) { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } } with id: 31302E2C-6C69-46A9-9754-7CD1219E698F | |
D [WinRM] creating command_id: 31302E2C-6C69-46A9-9754-7CD1219E698F on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D [WinRM] Waiting for output... | |
D [WinRM] Processing output | |
D [WinRM] cleaning up command_id: 31302E2C-6C69-46A9-9754-7CD1219E698F on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D [WinRM] Command created for $fileStream.Dispose() | |
if (!$?) { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } } with id: 87D430FB-F4C6-4405-B59B-DCB16F86FD0F | |
D [WinRM] creating command_id: 87D430FB-F4C6-4405-B59B-DCB16F86FD0F on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D [WinRM] Waiting for output... | |
D [WinRM] Processing output | |
D [WinRM] cleaning up command_id: 87D430FB-F4C6-4405-B59B-DCB16F86FD0F on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D Finished uploading /tmp/winrm-elevated-shell20161220-14802-1ob7ljops1 to c:/windows/temp/winrm-elevated-shell-db533f8c-58ea-4b56-8a44-92556ba431ff.ps1 (0.596 KB over 1 chunks) in (0m0.39s) | |
D No remote files to extract, skipping | |
D Uploaded 1 items dirty_check: (0m0.15s) stream_files: (0m0.39s) extract: (0m0.00s) | |
D [WinRM] Command created for $username = 'vagrant' | |
$password = 'vagrant' | |
$script_file = 'c:/windows/temp/winrm-elevated-shell-db533f8c-58ea-4b56-8a44-92556ba431ff.ps1' | |
$interactive = 'false' | |
$pass_to_use = $password | |
$logon_type = 1 | |
$logon_type_xml = "<LogonType>Password</LogonType>" | |
if($pass_to_use.length -eq 0) { | |
$pass_to_use = $null | |
$logon_type = 5 | |
$logon_type_xml = "" | |
} | |
if($interactive -eq 'true') { | |
$logon_type = 3 | |
$logon_type_xml = "<LogonType>InteractiveTokenOrPassword</LogonType>" | |
} | |
$task_name = "WinRM_Elevated_Shell" | |
$out_file = [System.IO.Path]::GetTempFileName() | |
$err_file = [System.IO.Path]::GetTempFileName() | |
$task_xml = @' | |
<?xml version="1.0" encoding="UTF-16"?> | |
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"> | |
<Principals> | |
<Principal id="Author"> | |
<UserId>{username}</UserId> | |
{logon_type} | |
<RunLevel>HighestAvailable</RunLevel> | |
</Principal> | |
</Principals> | |
<Settings> | |
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy> | |
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries> | |
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries> | |
<AllowHardTerminate>true</AllowHardTerminate> | |
<StartWhenAvailable>false</StartWhenAvailable> | |
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable> | |
<IdleSettings> | |
<StopOnIdleEnd>false</StopOnIdleEnd> | |
<RestartOnIdle>false</RestartOnIdle> | |
</IdleSettings> | |
<AllowStartOnDemand>true</AllowStartOnDemand> | |
<Enabled>true</Enabled> | |
<Hidden>false</Hidden> | |
<RunOnlyIfIdle>false</RunOnlyIfIdle> | |
<WakeToRun>false</WakeToRun> | |
<ExecutionTimeLimit>PT24H</ExecutionTimeLimit> | |
<Priority>4</Priority> | |
</Settings> | |
<Actions Context="Author"> | |
<Exec> | |
<Command>cmd</Command> | |
<Arguments>{arguments}</Arguments> | |
</Exec> | |
</Actions> | |
</Task> | |
'@ | |
$arguments = "/c powershell.exe -executionpolicy bypass -NoProfile -Command `"[Console]::OutputEncoding = New-Object -typename System.Text.UTF8Encoding;Invoke-Expression (Get-Content $script_file -Encoding UTF8 | Out-String)`" > $out_file 2>$err_file" | |
$task_xml = $task_xml.Replace("{arguments}", $arguments) | |
$task_xml = $task_xml.Replace("{username}", $username) | |
$task_xml = $task_xml.Replace("{logon_type}", $logon_type_xml) | |
$schedule = New-Object -ComObject "Schedule.Service" | |
$schedule.Connect() | |
$task = $schedule.NewTask($null) | |
$task.XmlText = $task_xml | |
$folder = $schedule.GetFolder("\") | |
$folder.RegisterTaskDefinition($task_name, $task, 6, $username, $pass_to_use, $logon_type, $null) | Out-Null | |
$registered_task = $folder.GetTask("\$task_name") | |
$registered_task.Run($null) | Out-Null | |
$timeout = 10 | |
$sec = 0 | |
while ( (!($registered_task.state -eq 4)) -and ($sec -lt $timeout) ) { | |
Start-Sleep -s 1 | |
$sec++ | |
} | |
function SlurpOutput($file, $cur_line, $out_type) { | |
if (Test-Path $file) { | |
get-content $file -Encoding UTF8 | select -skip $cur_line | ForEach { | |
$cur_line += 1 | |
if ($out_type -eq 'err') { | |
$host.ui.WriteErrorLine("$_") | |
} else { | |
$host.ui.WriteLine("$_") | |
} | |
} | |
} | |
return $cur_line | |
} | |
$err_cur_line = 0 | |
$out_cur_line = 0 | |
do { | |
Start-Sleep -m 100 | |
$out_cur_line = SlurpOutput $out_file $out_cur_line 'out' | |
$err_cur_line = SlurpOutput $err_file $err_cur_line 'err' | |
} while (!($registered_task.state -eq 3)) | |
# We'll make a best effort to clean these files | |
# But a reboot could possibly end the task while the process | |
# still runs and locks the file. If we can't delete we don't want to fail | |
try { Remove-Item $out_file -ErrorAction Stop } catch {} | |
try { Remove-Item $err_file -ErrorAction Stop } catch {} | |
try { Remove-Item $script_file -ErrorAction Stop } catch {} | |
$exit_code = $registered_task.LastTaskResult | |
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($schedule) | Out-Null | |
exit $exit_code | |
if (!$?) { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } } with id: 466C7B3C-56B7-4416-8644-02903947776B | |
D [WinRM] creating command_id: 466C7B3C-56B7-4416-8644-02903947776B on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D [WinRM] Waiting for output... | |
D [WinRM] Processing output | |
Starting Chef Client, version 12.15.19 | |
D [WinRM] Waiting for output... | |
D [WinRM] Processing output | |
resolving cookbooks for run list: ["chocolatey::default"] | |
D [WinRM] Waiting for output... | |
D [WinRM] Processing output | |
Synchronizing Cookbooks: | |
- chocolatey (1.0.3) | |
- windows (2.1.1) | |
- ohai (4.2.2) | |
- compat_resource (12.16.2) | |
Installing Cookbook Gems: | |
Compiling Cookbooks... | |
Converging 2 resources | |
Recipe: chocolatey::default | |
* template[C:\Users\vagrant\AppData\Local\Temp\kitchen\cache/install.ps1] action create (up to date) | |
* powershell_script[Install Chocolatey] action run | |
D [WinRM] Waiting for output... | |
D [WinRM] Processing output | |
================================================================================ | |
Error executing action `run` on resource 'powershell_script[Install Chocolatey]' | |
================================================================================ | |
Encoding::UndefinedConversionError | |
---------------------------------- | |
"\xEF" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to UTF-16LE | |
Resource Declaration: | |
--------------------- | |
# In C:/Users/vagrant/AppData/Local/Temp/kitchen/cache/cookbooks/chocolatey/recipes/default.rb | |
36: powershell_script 'Install Chocolatey' do | |
37: environment node['chocolatey']['install_vars'] | |
38: cwd Chef::Config['file_cache_path'] | |
39: code install_ps1 | |
40: not_if { chocolatey_installed? && (node['chocolatey']['upgrade'] == false) } | |
41: end | |
Compiled Resource: | |
------------------ | |
# Declared in C:/Users/vagrant/AppData/Local/Temp/kitchen/cache/cookbooks/chocolatey/recipes/default.rb:36:in `from_file' | |
powershell_script("Install Chocolatey") do | |
action [:run] | |
retries 0 | |
retry_delay 2 | |
default_guard_interpreter :powershell_script | |
command "Install Chocolatey" | |
backup 5 | |
cwd "C:\\Users\\vagrant\\AppData\\Local\\Temp\\kitchen\\cache" | |
environment {"chocolateyProxyLocation"=>nil, "chocolateyProxyUser"=>nil, "chocolateyProxyPassword"=>nil, "chocolateyVersion"=>nil, "chocolateyDownloadUrl"=>"https://chocolatey.org/api/v2/package/chocolatey", "chocolateyUseWindowsCompression"=>nil} | |
returns 0 | |
code "C:\\Users\\vagrant\\AppData\\Local\\Temp\\kitchen\\cache/install.ps1" | |
interpreter "powershell.exe" | |
declared_type :powershell_script | |
cookbook_name "chocolatey" | |
recipe_name "default" | |
not_if { #code block } | |
end | |
Platform: | |
--------- | |
i386-mingw32 | |
Running handlers: | |
[2016-12-20T11:48:37+03:00] ERROR: Running exception handlers | |
Running handlers complete | |
[2016-12-20T11:48:37+03:00] ERROR: Exception handlers complete | |
Chef Client failed. 0 resources updated in 08 seconds | |
[2016-12-20T11:48:37+03:00] FATAL: Stacktrace dumped to C:/Users/vagrant/AppData/Local/Temp/kitchen/cache/chef-stacktrace.out | |
[2016-12-20T11:48:37+03:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report | |
[2016-12-20T11:48:37+03:00] FATAL: Encoding::UndefinedConversionError: powershell_script[Install Chocolatey] (chocolatey::default line 36) had an error: Encoding::UndefinedConversionError: "\xEF" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to UTF-16LE | |
D [WinRM] cleaning up command_id: 466C7B3C-56B7-4416-8644-02903947776B on shell_id DE4A02DC-FBCB-49AC-85D3-8CFAFD4548CC | |
D Cleaning up local sandbox in /tmp/default-windows-posready7-sandbox-20161220-14802-1tboux9 | |
>>>>>> ------Exception------- | |
>>>>>> Class: Kitchen::ActionFailed | |
>>>>>> Message: 1 actions failed. | |
>>>>>> Converge failed on instance <default-windows-posready7>. Please see .kitchen/logs/default-windows-posready7.log for more details | |
>>>>>> ---------------------- | |
>>>>>> Please see .kitchen/logs/kitchen.log for more details | |
>>>>>> Also try running `kitchen diagnose --all` for configuration | |
D ------Exception------- | |
D Class: Kitchen::ActionFailed | |
D Message: 1 actions failed. | |
>>>>>> Converge failed on instance <default-windows-posready7>. Please see .kitchen/logs/default-windows-posready7.log for more details | |
D ---------------------- | |
D ------Backtrace------- | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/command.rb:183:in `report_errors' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/command.rb:174:in `run_action' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/command/action.rb:36:in `block in call' | |
D /opt/chefdk/embedded/lib/ruby/2.3.0/benchmark.rb:293:in `measure' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/command/action.rb:34:in `call' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/cli.rb:53:in `perform' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/cli.rb:187:in `block (2 levels) in <class:CLI>' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/thor-0.19.4/lib/thor/command.rb:27:in `run' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/thor-0.19.4/lib/thor/invocation.rb:126:in `invoke_command' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/cli.rb:334:in `invoke_task' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/thor-0.19.4/lib/thor.rb:369:in `dispatch' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/thor-0.19.4/lib/thor/base.rb:444:in `start' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/bin/kitchen:13:in `block in <top (required)>' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/errors.rb:171:in `with_friendly_errors' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/bin/kitchen:13:in `<top (required)>' | |
D /opt/chefdk/bin/kitchen:21:in `load' | |
D /opt/chefdk/bin/kitchen:21:in `<main>' | |
D ----End Backtrace----- | |
D -Composite Exception-- | |
D Class: Kitchen::InstanceFailure | |
D Message: Converge failed on instance <default-windows-posready7>. Please see .kitchen/logs/default-windows-posready7.log for more details | |
D ---------------------- | |
D ------Backtrace------- | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/provisioner/base.rb:83:in `rescue in call' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/provisioner/base.rb:86:in `call' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/instance.rb:384:in `block in converge_action' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/instance.rb:527:in `synchronize_or_call' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/instance.rb:489:in `block in action' | |
D /opt/chefdk/embedded/lib/ruby/2.3.0/benchmark.rb:293:in `measure' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/instance.rb:488:in `action' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/instance.rb:380:in `converge_action' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/instance.rb:359:in `block in transition_to' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/instance.rb:358:in `each' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/instance.rb:358:in `transition_to' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/instance.rb:135:in `converge' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/command.rb:197:in `public_send' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/command.rb:197:in `run_action_in_thread' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/command.rb:169:in `block (2 levels) in run_action' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/logging-2.1.0/lib/logging/diagnostic_context.rb:450:in `block in create_with_logging_context' | |
D ----End Backtrace----- | |
D ---Nested Exception--- | |
D Class: Kitchen::ActionFailed | |
D Message: WinRM exited (1) for command: [$env:TEST_KITCHEN = "1" | |
$env:PATH = try { | |
[System.Environment]::GetEnvironmentVariable('PATH','Machine') | |
} catch { $env:PATH } | |
& $env:systemdrive\opscode\chef\bin\chef-client.bat --local-mode --config $env:TEMP\kitchen\client.rb --log_level auto --force-formatter --no-color --json-attributes $env:TEMP\kitchen\dna.json --chef-zero-port 8889 ; exit $LastExitCode] | |
D ---------------------- | |
D ------Backtrace------- | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/provisioner/base.rb:83:in `rescue in call' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/provisioner/base.rb:86:in `call' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/instance.rb:384:in `block in converge_action' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/instance.rb:527:in `synchronize_or_call' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/instance.rb:489:in `block in action' | |
D /opt/chefdk/embedded/lib/ruby/2.3.0/benchmark.rb:293:in `measure' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/instance.rb:488:in `action' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/instance.rb:380:in `converge_action' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/instance.rb:359:in `block in transition_to' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/instance.rb:358:in `each' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/instance.rb:358:in `transition_to' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/instance.rb:135:in `converge' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/command.rb:197:in `public_send' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/command.rb:197:in `run_action_in_thread' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/test-kitchen-1.14.2/lib/kitchen/command.rb:169:in `block (2 levels) in run_action' | |
D /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/logging-2.1.0/lib/logging/diagnostic_context.rb:450:in `block in create_with_logging_context' | |
D ----End Backtrace----- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment