Skip to content

Commit 45cf498

Browse files
Merge pull request #272 from qmfrederik/fixes/windows-7
Windows 7 script improvements
2 parents d007cb7 + c3df3cc commit 45cf498

File tree

6 files changed

+34
-234
lines changed

6 files changed

+34
-234
lines changed

ansible/connection_plugins/packer.py

Lines changed: 0 additions & 218 deletions
This file was deleted.

ansible/windows_update.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
- hosts: all
22
tasks:
3-
- name: Install only security updates
3+
- name: Install security updates, critical updates and update rollups
44
win_updates:
55
category_names:
66
- SecurityUpdates

ansible/windows_update_security_updates.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
- hosts: all
22
tasks:
3-
- name: Install only security updates
3+
- name: Install security updates
44
win_updates:
55
category_names:
66
- SecurityUpdates

scripts/win-7-update-2016-convenience-rollup.ps1

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,19 @@ Write-Host "$(Get-Date -Format G): Extracting $update"
1010
Start-Process -FilePath "wusa.exe" -ArgumentList "C:\Updates\$kbid.msu /extract:C:\Updates" -Wait
1111

1212
Write-Host "$(Get-Date -Format G): Installing $update"
13-
Start-Process -FilePath "dism.exe" -ArgumentList "/online /add-package /PackagePath:C:\Updates\$kbid.cab /quiet /norestart /LogPath:C:\Windows\Temp\$kbid.log" -Wait
13+
$process = (Start-Process -FilePath "dism.exe" -ArgumentList "/online /add-package /PackagePath:C:\Updates\$kbid.cab /quiet /norestart /LogPath:C:\Windows\Temp\$kbid.log" -PassThru)
14+
15+
# https://stackoverflow.com/questions/10262231/obtaining-exitcode-using-start-process-and-waitforexit-instead-of-wait#comment71507068_23797762
16+
$handle = $process.Handle # cache proc.Handle
17+
18+
while ($null -eq $process.ExitCode)
19+
{
20+
Write-Host "$(Get-Date -Format G): Convenience rollup update for Windows 7 is still installing (PID $($process.Id))"
21+
Wait-Process -Id $process.Id -Timeout 180 -ErrorAction SilentlyContinue
22+
$process.Refresh()
23+
}
24+
25+
Write-Host "$(Get-Date -Format G): Convenience rollup update for Windows 7 exited with exit code $($process.ExitCode)"
1426

1527
Remove-Item -LiteralPath "C:\Updates" -Force -Recurse
1628
Write-Host "$(Get-Date -Format G): Finished installing $update. The VM will now reboot and continue the installation process."

scripts/win-7-update-sp1.ps1

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,19 @@ Write-Host "$(Get-Date -Format G): Downloading Windows 7 Service Pack 1"
1616
(New-Object Net.WebClient).DownloadFile("https://download.microsoft.com/download/0/A/F/0AFB5316-3062-494A-AB78-7FB0D4461357/windows6.1-KB976932-X64.exe", "C:\Updates\windows6.1-KB976932-X64.exe")
1717

1818
Write-Host "$(Get-Date -Format G): Installing Windows 7 Service Pack 1"
19-
Start-Process -FilePath "C:\Updates\Windows6.1-KB976932-X64.exe" -ArgumentList "/unattend /nodialog /norestart" -Wait
19+
$process = (Start-Process -FilePath "C:\Updates\Windows6.1-KB976932-X64.exe" -ArgumentList "/unattend /nodialog /norestart" -PassThru)
20+
21+
# https://stackoverflow.com/questions/10262231/obtaining-exitcode-using-start-process-and-waitforexit-instead-of-wait#comment71507068_23797762
22+
$handle = $process.Handle # cache proc.Handle
23+
24+
while ($null -eq $process.ExitCode)
25+
{
26+
Write-Host "$(Get-Date -Format G): Windows 7 Service Pack 1 is still installing (PID $($process.Id))"
27+
Wait-Process -Id $process.Id -Timeout 180 -ErrorAction SilentlyContinue
28+
$process.Refresh()
29+
}
30+
31+
Write-Host "$(Get-Date -Format G): Windows 7 Service Pack 1 exited with exit code $($process.ExitCode)"
2032

2133
Remove-Item -LiteralPath "C:\Updates" -Force -Recurse
2234

windows_7.json

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,9 @@
197197
"type": "windows-restart"
198198
},
199199
{
200-
"extra_arguments": [
201-
"--extra-vars",
202-
"ansible_shell_type=powershell ansible_shell_executable=None",
203-
"--connection",
204-
"packer"
205-
],
200+
"user": "vagrant",
201+
"use_proxy": false,
202+
"extra_arguments": ["-e", "ansible_winrm_server_cert_validation=ignore", "-e", "ansible_winrm_scheme=http"],
206203
"playbook_file": "./ansible/windows_update_security_updates.yml",
207204
"type": "ansible"
208205
},
@@ -211,12 +208,9 @@
211208
"type": "windows-restart"
212209
},
213210
{
214-
"extra_arguments": [
215-
"--extra-vars",
216-
"ansible_shell_type=powershell ansible_shell_executable=None",
217-
"--connection",
218-
"packer"
219-
],
211+
"user": "vagrant",
212+
"use_proxy": false,
213+
"extra_arguments": ["-e", "ansible_winrm_server_cert_validation=ignore", "-e", "ansible_winrm_scheme=http"],
220214
"playbook_file": "./ansible/windows_update.yml",
221215
"type": "ansible"
222216
},

0 commit comments

Comments
 (0)