Skip to content

Commit

Permalink
Merge pull request #1057 from chef/windows_v2
Browse files Browse the repository at this point in the history
Improvements for Windows 2008 R2
  • Loading branch information
tas50 authored Jun 6, 2018
2 parents f33c532 + 7504dbe commit 19f1f05
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 13 deletions.
14 changes: 13 additions & 1 deletion windows/2008r2.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,23 @@
"install_command": "powershell.exe -Command \"(new-object Net.WebClient).DownloadString('https://omnitruck.chef.io/install.ps1') | iex; install\"",
"run_list": [
"packer::vm_tools",
"packer::uninstall_powershell_ise",
"packer::features",
"packer::enable_file_sharing",
"packer::enable_remote_desktop",
"packer::ui_tweaks",
"packer::power",
"packer::updates"
]
},
{
"type": "windows-restart"
},
{
"type": "chef-solo",
"cookbook_paths": ["cookbooks"],
"guest_os_type": "windows",
"install_command": "powershell.exe -Command \"(new-object Net.WebClient).DownloadString('https://omnitruck.chef.io/install.ps1') | iex; install\"",
"run_list": [
"packer::cleanup",
"packer::defrag"
]
Expand Down
2 changes: 1 addition & 1 deletion windows/2012r2.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"guest_os_type": "windows",
"run_list": [
"packer::vm_tools",
"packer::uninstall_powershell_ise",
"packer::features",
"packer::enable_file_sharing",
"packer::enable_remote_desktop",
"packer::ui_tweaks",
Expand Down
2 changes: 1 addition & 1 deletion windows/2016.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"guest_os_type": "windows",
"run_list": [
"packer::vm_tools",
"packer::uninstall_powershell_ise",
"packer::features",
"packer::enable_file_sharing",
"packer::enable_remote_desktop",
"packer::ui_tweaks",
Expand Down
2 changes: 1 addition & 1 deletion windows/7.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"install_command": "powershell.exe -Command \"(new-object Net.WebClient).DownloadString('https://omnitruck.chef.io/install.ps1') | iex; install\"",
"run_list": [
"packer::vm_tools",
"packer::uninstall_powershell_ise",
"packer::features",
"packer::enable_file_sharing",
"packer::enable_remote_desktop",
"packer::ui_tweaks",
Expand Down
2 changes: 1 addition & 1 deletion windows/cookbooks/packer/kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ suites:
- name: default
run_list:
- recipe[packer::vm_tools]
- recipe[packer::uninstall_powershell_ise]
- recipe[packer::features]
- recipe[packer::enable_file_sharing]
- recipe[packer::enable_remote_desktop]
- recipe[packer::ui_tweaks]
Expand Down
10 changes: 9 additions & 1 deletion windows/cookbooks/packer/recipes/cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"C:\\Recovery",
"$env:localappdata\\temp\\*",
"$env:windir\\logs",
"$env:windir\\winsxs\\manifestcache"
"$env:windir\\winsxs\\manifestcache",
"C:\\Users\\vagrant\Favorites\\*"
) | % {
if(Test-Path $_) {
Write-Host "Removing $_"
Expand All @@ -30,6 +31,13 @@
EOH
end

# clean all of the event logs
%w(Application Security Setup System).each do |log|
execute "Cleaning the #{log} event log" do
command "wevtutil clear-log #{log}"
end
end

# remove pagefile
registry_key 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' do
values [{
Expand Down
8 changes: 8 additions & 0 deletions windows/cookbooks/packer/recipes/features.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
windows_feature 'NetFx3' do
action :install
only_if { node['platform_version'].to_f == 6.1 }
end

windows_feature 'MicrosoftWindowsPowerShellISE' do
action :remove
end
3 changes: 0 additions & 3 deletions windows/cookbooks/packer/recipes/uninstall_powershell_ise.rb

This file was deleted.

17 changes: 17 additions & 0 deletions windows/cookbooks/packer/recipes/updates.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Don't check for updates automatically. This needs to be configured before you can install updates
registry_key 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update' do
values [{
name: 'AUOptions',
type: :dword,
data: 1,
}]
end

if node['platform_version'].to_f == 6.1 # 2008R2

# This is basically a service pack and we should install it to fix a giant pile of bugs
msu_package '2018-05 monthly rollup' do
source 'http://download.windowsupdate.com/d/msdownload/update/software/secu/2018/05/windows6.1-kb4103718-x64_c051268978faef39e21863a95ea2452ecbc0936d.msu'
action :install
end
end
12 changes: 8 additions & 4 deletions windows/scripts/cleanup.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
Write-Host "Uninstall Chef..."
Write-Host "Uninstalling Chef..."
if(Test-Path "c:\windows\temp\chef.msi") {
Start-Process MSIEXEC.exe '/uninstall c:\windows\temp\chef.msi /quiet' -Wait
}

Write-Host "Cleaning Temp Files"
Write-Host "Removing leftover Chef files..."
Remove-Item "C:\Opscode\" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item "C:\Chef\" -Recurse -Force -ErrorAction SilentlyContinue

Write-Host "Cleaning Temp Files..."
try {
Takeown /d Y /R /f "C:\Windows\Temp\*"
Icacls "C:\Windows\Temp\*" /GRANT:r administrators:F /T /c /q 2>&1
Expand All @@ -20,7 +24,7 @@ $ArraySize= 64kb
$SpaceToLeave= $Volume.Size * 0.05
$FileSize= $Volume.FreeSpace - $SpacetoLeave
$ZeroArray= new-object byte[]($ArraySize)

$Stream= [io.File]::OpenWrite($FilePath)
try {
$CurFileSize = 0
Expand All @@ -34,5 +38,5 @@ finally {
$Stream.Close()
}
}

Remove-Item $FilePath

0 comments on commit 19f1f05

Please sign in to comment.