Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Bob Tanner
packer-windows
Commits
9ae028e9
Commit
9ae028e9
authored
Oct 19, 2020
by
Bob Tanner
Browse files
Merge branch 'main' of
https://github.com/StefanScherer/packer-windows
into my
parents
4baf4fe7
2e3ce2c7
Changes
54
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
9ae028e9
...
...
@@ -19,7 +19,7 @@ Some of my enhancements are:
### Packer Version
[
Packer
](
https://github.com/mitchellh/packer/blob/master/CHANGELOG.md
)
`1.
3.3
`
is recommended.
[
Packer
](
https://github.com/mitchellh/packer/blob/master/CHANGELOG.md
)
`1.
6.0
`
is recommended.
### Windows Versions
...
...
ansible/connection_plugins/packer.py
deleted
100644 → 0
View file @
4baf4fe7
from
__future__
import
(
absolute_import
,
division
,
print_function
)
__metaclass__
=
type
from
ansible.plugins.connection.ssh
import
Connection
as
SSHConnection
DOCUMENTATION
=
'''
connection: packer
short_description: ssh based connections for powershell via packer
description:
- This connection plugin allows ansible to communicate to the target packer machines via ssh based connections for powershell.
author: Packer Community
version_added: na
options:
host:
description: Hostname/ip to connect to.
default: inventory_hostname
vars:
- name: ansible_host
- name: ansible_ssh_host
host_key_checking:
description: Determines if ssh should check host keys
type: boolean
ini:
- section: defaults
key: 'host_key_checking'
- section: ssh_connection
key: 'host_key_checking'
version_added: '2.5'
env:
- name: ANSIBLE_HOST_KEY_CHECKING
- name: ANSIBLE_SSH_HOST_KEY_CHECKING
version_added: '2.5'
vars:
- name: ansible_host_key_checking
version_added: '2.5'
- name: ansible_ssh_host_key_checking
version_added: '2.5'
password:
description: Authentication password for the C(remote_user). Can be supplied as CLI option.
vars:
- name: ansible_password
- name: ansible_ssh_pass
ssh_args:
description: Arguments to pass to all ssh cli tools
default: '-C -o ControlMaster=auto -o ControlPersist=60s'
ini:
- section: 'ssh_connection'
key: 'ssh_args'
env:
- name: ANSIBLE_SSH_ARGS
ssh_common_args:
description: Common extra args for all ssh CLI tools
vars:
- name: ansible_ssh_common_args
ssh_executable:
default: ssh
description:
- This defines the location of the ssh binary. It defaults to ``ssh`` which will use the first ssh binary available in $PATH.
- This option is usually not required, it might be useful when access to system ssh is restricted,
or when using ssh wrappers to connect to remote hosts.
env: [{name: ANSIBLE_SSH_EXECUTABLE}]
ini:
- {key: ssh_executable, section: ssh_connection}
#const: ANSIBLE_SSH_EXECUTABLE
version_added: "2.2"
sftp_executable:
default: sftp
description:
- This defines the location of the sftp binary. It defaults to ``sftp`` which will use the first binary available in $PATH.
env: [{name: ANSIBLE_SFTP_EXECUTABLE}]
ini:
- {key: sftp_executable, section: ssh_connection}
version_added: "2.6"
scp_executable:
default: scp
description:
- This defines the location of the scp binary. It defaults to `scp` which will use the first binary available in $PATH.
env: [{name: ANSIBLE_SCP_EXECUTABLE}]
ini:
- {key: scp_executable, section: ssh_connection}
version_added: "2.6"
scp_extra_args:
description: Extra exclusive to the ``scp`` CLI
vars:
- name: ansible_scp_extra_args
sftp_extra_args:
description: Extra exclusive to the ``sftp`` CLI
vars:
- name: ansible_sftp_extra_args
ssh_extra_args:
description: Extra exclusive to the 'ssh' CLI
vars:
- name: ansible_ssh_extra_args
retries:
# constant: ANSIBLE_SSH_RETRIES
description: Number of attempts to connect.
default: 3
type: integer
env:
- name: ANSIBLE_SSH_RETRIES
ini:
- section: connection
key: retries
- section: ssh_connection
key: retries
port:
description: Remote port to connect to.
type: int
default: 22
ini:
- section: defaults
key: remote_port
env:
- name: ANSIBLE_REMOTE_PORT
vars:
- name: ansible_port
- name: ansible_ssh_port
remote_user:
description:
- User name with which to login to the remote server, normally set by the remote_user keyword.
- If no user is supplied, Ansible will let the ssh client binary choose the user as it normally
ini:
- section: defaults
key: remote_user
env:
- name: ANSIBLE_REMOTE_USER
vars:
- name: ansible_user
- name: ansible_ssh_user
pipelining:
default: ANSIBLE_PIPELINING
description:
- Pipelining reduces the number of SSH operations required to execute a module on the remote server,
by executing many Ansible modules without actual file transfer.
- This can result in a very significant performance improvement when enabled.
- However this conflicts with privilege escalation (become).
For example, when using sudo operations you must first disable 'requiretty' in the sudoers file for the target hosts,
which is why this feature is disabled by default.
env:
- name: ANSIBLE_PIPELINING
#- name: ANSIBLE_SSH_PIPELINING
ini:
- section: defaults
key: pipelining
#- section: ssh_connection
# key: pipelining
type: boolean
vars:
- name: ansible_pipelining
- name: ansible_ssh_pipelining
private_key_file:
description:
- Path to private key file to use for authentication
ini:
- section: defaults
key: private_key_file
env:
- name: ANSIBLE_PRIVATE_KEY_FILE
vars:
- name: ansible_private_key_file
- name: ansible_ssh_private_key_file
control_path:
description:
- This is the location to save ssh's ControlPath sockets, it uses ssh's variable substitution.
- Since 2.3, if null, ansible will generate a unique hash. Use `%(directory)s` to indicate where to use the control dir path setting.
env:
- name: ANSIBLE_SSH_CONTROL_PATH
ini:
- key: control_path
section: ssh_connection
control_path_dir:
default: ~/.ansible/cp
description:
- This sets the directory to use for ssh control path if the control path setting is null.
- Also, provides the `%(directory)s` variable for the control path setting.
env:
- name: ANSIBLE_SSH_CONTROL_PATH_DIR
ini:
- section: ssh_connection
key: control_path_dir
sftp_batch_mode:
default: 'yes'
description: 'TODO: write it'
env: [{name: ANSIBLE_SFTP_BATCH_MODE}]
ini:
- {key: sftp_batch_mode, section: ssh_connection}
type: bool
scp_if_ssh:
default: smart
description:
- "Prefered method to use when transfering files over ssh"
- When set to smart, Ansible will try them until one succeeds or they all fail
- If set to True, it will force 'scp', if False it will use 'sftp'
env: [{name: ANSIBLE_SCP_IF_SSH}]
ini:
- {key: scp_if_ssh, section: ssh_connection}
use_tty:
version_added: '2.5'
default: 'yes'
description: add -tt to ssh commands to force tty allocation
env: [{name: ANSIBLE_SSH_USETTY}]
ini:
- {key: usetty, section: ssh_connection}
type: bool
yaml: {key: connection.usetty}
'''
class
Connection
(
SSHConnection
):
''' ssh based connections for powershell via packer'''
transport
=
'packer'
has_pipelining
=
True
become_methods
=
[]
allow_executable
=
False
module_implementation_preferences
=
(
'.ps1'
,
''
)
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
Connection
,
self
).
__init__
(
*
args
,
**
kwargs
)
\ No newline at end of file
ansible/windows_update.yml
View file @
9ae028e9
-
hosts
:
all
tasks
:
-
name
:
Install
only
security updates
-
name
:
Install security updates
, critical updates and update rollups
win_updates
:
category_names
:
-
SecurityUpdates
...
...
ansible/windows_update_security_updates.yml
View file @
9ae028e9
-
hosts
:
all
tasks
:
-
name
:
Install
only
security updates
-
name
:
Install security updates
win_updates
:
category_names
:
-
SecurityUpdates
...
...
build_windows_10.ps1
View file @
9ae028e9
#packer build --only=vmware-iso `
# --var disk_size=102400 `
# --var iso_url=C:/packer_cache/Win10_1607_English_x64.iso `
# --var iso_checksum=99fd8082a609997ae97a514dca22becf20420891 `
# --var iso_checksum=
sha1:
99fd8082a609997ae97a514dca22becf20420891 `
# --var autounattend=./tmp/10/Autounattend.xml `
# windows_10.json
...
...
build_windows_10.sh
View file @
9ae028e9
#!/bin/bash
#packer build --only=vmware-iso \
# --var iso_url=~/Downloads/19041.264.200511-0456.vb_release_svc_refresh_CLIENTENTERPRISEEVAL_OEMRET_x64FRE_en-us.iso \
# windows_10.json
packer build
--only
=
vmware-iso
\
--var
iso_url
=
~/Downloads/19041.264.200511-0456.vb_release_svc_refresh_CLIENTENTERPRISEEVAL_OEMRET_x64FRE_en-us.iso
\
--var
iso_url
=
~/packer_cache/msdn/de_windows_10_consumer_editions_version_2004_x64_dvd_7efdffc7.iso
\
--var
iso_checksum
=
sha256:908bca712c7f5ec5655882237aa447dde446e9a5e5178e2202ebae0157fd0d29
\
--var
autounattend
=
tmp/10_pro_de/Autounattend.xml
\
windows_10.json
#packer build --only=vmware-iso \
# --var iso_url=~/packer_cache/msdn/de_windows_10_consumer_editions_version_2004_x64_dvd_7efdffc7.iso \
# --var iso_checksum=908bca712c7f5ec5655882237aa447dde446e9a5e5178e2202ebae0157fd0d29 \
# --var autounattend=tmp/10_pro_de/Autounattend.xml \
# windows_10_insider.json
build_windows_10_insider.sh
View file @
9ae028e9
#!/bin/bash
packer build
--only
=
vmware-iso
\
--var
iso_url
=
~/packer_cache/insider/Windows10_InsiderPreview_Client_x64_en-us_
19041
.iso
\
--var
iso_checksum
=
49103c4311c63c41690b0bb445e3d3adc7904a0c29ad031169d18d4d85b66478
\
--var
iso_url
=
~/packer_cache/insider/Windows10_InsiderPreview_Client_x64_en-us_
20150
.iso
\
--var
iso_checksum
=
sha256:368483372dd7c391ee02d1847630fbba89f5ed014389ce0b942ed7863bd2b04c
\
--var
autounattend
=
tmp/10_pro/Autounattend.xml
\
windows_10_insider.json
# packer build --only=vmware-iso \
# --var iso_url=~/packer_cache/insider/uupdump_19041.1_PROFESSIONAL_X64_EN-US.iso \
# --var iso_checksum=bcf500c09e2048c8bd2b710ba2b75bed9fe6ef07ea2a584599af81b4b8baa5ed \
# --var iso_checksum=
sha256:
bcf500c09e2048c8bd2b710ba2b75bed9fe6ef07ea2a584599af81b4b8baa5ed \
# --var autounattend=tmp/10_pro/Autounattend.xml \
# windows_10_insider.json
build_windows_2016_core.sh
View file @
9ae028e9
...
...
@@ -2,4 +2,4 @@
# packer build --only=vmware-iso --var iso_url=~/packer_cache/14393.0.160715-1616.RS1_RELEASE_SERVER_EVAL_X64FRE_EN-US.ISO windows_2016_docker.json
# MSDN ISO
packer build
--only
=
vmware-iso
--var
iso_url
=
~/packer_cache/msdn/en_windows_server_2016_x64_dvd_9718492.iso
--var
iso_checksum
=
F185197AF68FAE4F0E06510A4579FC511BA27616
--var
iso_checksum_type
=
sha1
--var
autounattend
=
./tmp/2016/Autounattend.xml windows_2016_core.json
packer build
--only
=
vmware-iso
--var
iso_url
=
~/packer_cache/msdn/en_windows_server_2016_x64_dvd_9718492.iso
--var
iso_checksum
=
sha1:
F185197AF68FAE4F0E06510A4579FC511BA27616
--var
autounattend
=
./tmp/2016/Autounattend.xml windows_2016_core.json
build_windows_2016_dc.sh
View file @
9ae028e9
#!/bin/bash
#packer build --only=vmware-iso --var iso_url=~/packer_cache/14393.0.160715-1616.RS1_RELEASE_SERVER_EVAL_X64FRE_EN-US.ISO windows_2016_docker.json
packer build
--only
=
vmware-iso
--var
iso_url
=
~/packer_cache/en_windows_server_2016_x64_dvd_9327751.iso
--var
iso_checksum
=
91d7b2ebcff099b3557570af7a8a5cd6
--var
autounattend
=
./tmp/2016_core/Autounattend.xml windows_2016_dc.json
packer build
--only
=
vmware-iso
--var
iso_url
=
~/packer_cache/en_windows_server_2016_x64_dvd_9327751.iso
--var
iso_checksum
=
sha1:
91d7b2ebcff099b3557570af7a8a5cd6
--var
autounattend
=
./tmp/2016_core/Autounattend.xml windows_2016_dc.json
build_windows_2016_docker.ps1
View file @
9ae028e9
#packer build --only=vmware-iso `
# --var disk_size=102400 `
# --var iso_url=C:/packer_cache/Win10_1607_English_x64.iso `
# --var iso_checksum=99fd8082a609997ae97a514dca22becf20420891 `
# --var iso_checksum=
sha1:
99fd8082a609997ae97a514dca22becf20420891 `
# --var autounattend=./tmp/10/Autounattend.xml `
# windows_10.json
packer
build
windows_2016_docker.json
build_windows_2019_docker.ps1
View file @
9ae028e9
...
...
@@ -4,5 +4,5 @@ if (Test-Path ./output-hyperv-iso) {
packer
build
--only
=
hyperv-iso
`
--var
iso_url
=.
/iso/17763.379.190312-0539.rs5_release_svc_refresh_SERVER_EVAL_x64FRE_en-us.iso
`
--var
iso_checksum
=
"221F9ACBC727297A56674A0F1722B8AC7B6E840B4E1FFBDD538A9ED0DA823562"
`
--var
iso_checksum
=
"
sha256:
221F9ACBC727297A56674A0F1722B8AC7B6E840B4E1FFBDD538A9ED0DA823562"
`
windows_2019_docker.json
build_windows_2019_docker.sh
View file @
9ae028e9
...
...
@@ -5,5 +5,5 @@ packer build \
--var
vhv_enable
=
true
\
--var
autounattend
=
./tmp/2019_core/Autounattend.xml
\
--var
iso_url
=
~/packer_cache/msdn/en_windows_server_2019_x64_dvd_4cb967d8.iso
\
--var
iso_checksum
=
"4C5DD63EFEE50117986A2E38D4B3A3FBAF3C1C15E2E7EA1D23EF9D8AF148DD2D"
\
--var
iso_checksum
=
"
sha256:
4C5DD63EFEE50117986A2E38D4B3A3FBAF3C1C15E2E7EA1D23EF9D8AF148DD2D"
\
windows_2019_docker.json
build_windows_server_1709_docker.sh
View file @
9ae028e9
...
...
@@ -4,8 +4,7 @@ packer build \
--only
=
vmware-iso
\
--var
vhv_enable
=
true
\
--var
iso_url
=
~/packer_cache/msdn/en_windows_server_version_1709_x64_dvd_100090904.iso
\
--var
iso_checksum
=
ca1108d5be2c091bfb57e8f3db3be1e8baa9c32802131f7a6e43e63f7b596591
\
--var
iso_checksum_type
=
sha256
\
--var
iso_checksum
=
sha256:ca1108d5be2c091bfb57e8f3db3be1e8baa9c32802131f7a6e43e63f7b596591
\
--var
autounattend
=
./tmp/1709/Autounattend.xml
\
windows_server_1709_docker.json
# --var disk_type_id=3 \
...
...
scripts/docker/install-docker.ps1
View file @
9ae028e9
...
...
@@ -11,9 +11,6 @@ if (Test-Path env:docker_version) {
$ProgressPreference
=
'SilentlyContinue'
if
(
$docker_provider
-eq
"ce"
)
{
$zip_url
=
$
(
"https://download.docker.com/win/static/edge/x86_64/docker-{0}-ce.zip"
-f
$docker_version
)
}
elseif
(
$docker_provider
-eq
"ee"
)
{
$folder
=
$docker_version
-replace
"\.\d+$"
,
""
$zip_url
=
$
(
"https://download.docker.com/components/engine/windows-server/{0}/docker-{1}.zip"
-f
$folder
,
$docker_version
)
}
elseif
(
$docker_provider
-eq
"master"
)
{
$docker_version
=
"master"
$zip_url
=
"https://master.dockerproject.com/windows/x86_64/docker.zip"
...
...
@@ -33,15 +30,8 @@ if ($zip_url) {
Write-Output
"Registering docker service ..."
.
dockerd
--register-service
}
else
{
Write-Output
"Install-PackageProvider ..."
Install-PackageProvider
-Name
NuGet
-MinimumVersion
2.8.5.201
-Force
Write-Output
"Install-Module
$docker_provider
..."
Install-Module
-Name
$docker_provider
-Repository
PSGallery
-Force
Write-Output
"Install-Package docker version
$docker_version
..."
Set-PSRepository
-InstallationPolicy
Trusted
-Name
PSGallery
$Error
ActionStop
=
'SilentlyContinue'
Install-Package
-Name
docker
-ProviderName
$docker_provider
-RequiredVersion
$docker_version
-Force
Set-PSRepository
-InstallationPolicy
Untrusted
-Name
PSGallery
Write-Output
"Use get.mirantis.com/install.ps1 ..."
iwr
-useb
https://get.mirantis.com/install.ps1
|
iex
}
$Error
ActionPreference
=
'Stop'
...
...
scripts/vm-guest-tools.bat
View file @
9ae028e9
...
...
@@ -19,7 +19,7 @@ if exist "C:\Users\vagrant\windows.iso" (
)
if
not
exist
"C:\Windows\Temp\windows.iso"
(
powershell
-Command
"(New-Object System.Net.WebClient).DownloadFile('https://softwareupdate.vmware.com/cds/vmw-desktop/ws/15.5.
5
/16
285975
/windows/packages/tools-windows.tar', 'C:\Windows\Temp\vmware-tools.tar')"
<
NUL
powershell
-Command
"(New-Object System.Net.WebClient).DownloadFile('https://softwareupdate.vmware.com/cds/vmw-desktop/ws/15.5.
6
/16
341506
/windows/packages/tools-windows.tar', 'C:\Windows\Temp\vmware-tools.tar')"
<
NUL
cmd
/c
""
C
:\Program
Files
\7
-Zip
\7z.exe
" x C:\Windows\Temp\vmware-tools.tar -oC:\Windows\Temp"
FOR
/r
"C:\Windows\Temp"
%%a
in
(
VMware
-tools-windows
-*
.iso
)
DO
REN
"
%%~a
"
"windows.iso"
rd
/S /Q
"C:\Program Files (x86)\VMWare"
...
...
@@ -40,7 +40,7 @@ if exist "C:\Users\vagrant\VBoxGuestAdditions.iso" (
)
if
not
exist
"C:\Windows\Temp\VBoxGuestAdditions.iso"
(
powershell
-Command
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (New-Object System.Net.WebClient).DownloadFile('https://download.virtualbox.org/virtualbox/6.1.
8
/VBoxGuestAdditions_6.1.
8
.iso', 'C:\Windows\Temp\VBoxGuestAdditions.iso')"
<
NUL
powershell
-Command
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (New-Object System.Net.WebClient).DownloadFile('https://download.virtualbox.org/virtualbox/6.1.
14
/VBoxGuestAdditions_6.1.
14
.iso', 'C:\Windows\Temp\VBoxGuestAdditions.iso')"
<
NUL
)
cmd
/c
""
C
:\Program
Files
\7
-Zip
\7z.exe
" x C:\Windows\Temp\VBoxGuestAdditions.iso -oC:\Windows\Temp\virtualbox"
...
...
scripts/vm-guest-tools.ps1
0 → 100644
View file @
9ae028e9
if
(
!
(
Test-Path
"C:\Windows\Temp\7z1900-x64.msi"
))
{
[
Net.ServicePointManager
]::
SecurityProtocol
=
[
Net.SecurityProtocolType
]::
Tls12
;
(
New-Object
System.Net.WebClient
)
.
DownloadFile
(
'https://www.7-zip.org/a/7z1900-x64.msi'
,
'C:\Windows\Temp\7z1900-x64.msi'
)
}
if
(
!
(
Test-Path
"C:\Windows\Temp\7z1900-x64.msi"
))
{
Start-Sleep
5
;
[
Net.ServicePointManager
]::
SecurityProtocol
=
[
Net.SecurityProtocolType
]::
Tls12
;
(
New-Object
System.Net.WebClient
)
.
DownloadFile
(
'https://www.7-zip.org/a/7z1900-x64.msi'
,
'C:\Windows\Temp\7z1900-x64.msi'
)
}
cmd
/c
msiexec
/qb
/i
C:\Windows\Temp\7z1900-x64.msi
if
(
"
$
env
:
PACKER_BUILDER_TYPE
"
-eq
"vmware-iso"
)
{
Write-Host
"Using VMware"
if
(
Test-Path
"C:\Users\vagrant\windows.iso"
)
{
Move-Item
-force
C:\Users\vagrant\windows.iso
C:\Windows\Temp
}
if
(
!
(
Test-Path
"C:\Windows\Temp\windows.iso"
))
{
Try
{
# Disabling the progress bar speeds up IWR https://github.com/PowerShell/PowerShell/issues/2138
$ProgressPreference
=
'SilentlyContinue'
$pageContentLinks
=
(
Invoke-WebRequest
(
'https://softwareupdate.vmware.com/cds/vmw-desktop/ws'
)
-UseBasicParsing
)
.
Links
|
where-object
{
$_
.
href
-Match
"[0-9]"
}
|
Select-Object
href
|
%
{
$_
.
href
.
Trim
(
'/'
)
}
$versionObject
=
$pageContentLinks
|
%
{
new-object
System.Version
(
$_
)
}
|
sort-object
-Descending
|
select-object
-First
1
-Property
:
Major
,
Minor
,
Build
$newestVersion
=
$versionObject
.
Major
.
ToString
()
+
"."
+
$versionObject
.
Minor
.
ToString
()
+
"."
+
$versionObject
.
Build
.
ToString
()
|
out-string
$newestVersion
=
$newestVersion
.
TrimEnd
(
"
`r
?
`n
"
)
$nextURISubdirectoryObject
=
(
Invoke-WebRequest
(
"https://softwareupdate.vmware.com/cds/vmw-desktop/ws/
$newestVersion
/"
)
-UseBasicParsing
)
.
Links
|
where-object
{
$_
.
href
-Match
"[0-9]"
}
|
Select-Object
href
|
where-object
{
$_
.
href
-Match
"[0-9]"
}
$nextUriSubdirectory
=
$nextURISubdirectoryObject
.
href
|
Out-String
$nextUriSubdirectory
=
$nextUriSubdirectory
.
TrimEnd
(
"
`r
?
`n
"
)
$newestVMwareToolsURL
=
"https://softwareupdate.vmware.com/cds/vmw-desktop/ws/
$newestVersion
/
$nextURISubdirectory
/windows/packages/tools-windows.tar"
Write-Host
"The latest version of VMware tools has been determined to be downloadable from
$newestVMwareToolsURL
"
[
Net.ServicePointManager
]::
SecurityProtocol
=
[
Net.SecurityProtocolType
]::
Tls12
;
(
New-Object
System.Net.WebClient
)
.
DownloadFile
(
"
$newestVMwareToolsURL
"
,
'C:\Windows\Temp\vmware-tools.tar'
)
}
Catch
{
Write-Host
"Unable to determine the latest version of VMware tools. Falling back to hardcoded URL."
(
New-Object
System.Net.WebClient
)
.
DownloadFile
(
'https://softwareupdate.vmware.com/cds/vmw-desktop/ws/15.5.5/16285975/windows/packages/tools-windows.tar'
,
'C:\Windows\Temp\vmware-tools.tar'
)
}
cmd
/c
"C:\PROGRA~1\7-Zip\7z.exe"
x
C:\Windows\Temp\vmware-tools.tar
-oC
:
\Windows\Temp
Move-Item
c:\windows\temp\VMware-tools-windows-
*.
iso
c:\windows\temp\windows.iso
Try
{
Remove-Item
"C:\Program Files (x86)\VMWare"
-Recurse
-Force
-ErrorAction
Stop
}
Catch
{
Write-Host
"Directory didn't exist to be removed."
}
}
cmd
/c
"C:\PROGRA~1\7-Zip\7z.exe"
x
"C:\Windows\Temp\windows.iso"
-oC
:
\Windows\Temp\VMWare
cmd
/c
C:\Windows\Temp\VMWare\setup.exe
/S
/v
"/qn REBOOT=R\"
Remove-Item
-Force
"C:\Windows\Temp\vmware-tools.tar"
Remove-Item
-Force
"C:\Windows\Temp\windows.iso"
Remove-Item
-Force
-Recurse
"C:\Windows\Temp\VMware"
}
if
(
"
$
env
:
PACKER_BUILDER_TYPE
"
-eq
"virtualbox-iso"
)
{
Write-Host
"Using Virtualbox"
if
(
Test-Path
"C:\Users\vagrant\VBoxGuestAdditions.iso"
)
{
Move-Item
-Force
C:\Users\vagrant\VBoxGuestAdditions.iso
C:\Windows\Temp
}
if
(
!
(
Test-Path
"C:\Windows\Temp\VBoxGuestAdditions.iso"
))
{
Try
{
$pageContentLinks
=
(
Invoke-WebRequest
(
'https://download.virtualbox.org/virtualbox'
)
-UseBasicParsing
)
.
Links
|
where-object
{
$_
.
href
-Match
"[0-9]"
}
|
Select-Object
href
|
where-object
{
$_
.
href
-NotMatch
"BETA"
}
|
where-object
{
$_
.
href
-NotMatch
"RC"
}
|
where-object
{
$_
.
href
-Match
"[0-9]\.[0-9]"
}
|
%
{
$_
.
href
.
Trim
(
'/'
)
}
$versionObject
=
$pageContentLinks
|
%
{
new-object
System.Version
(
$_
)
}
|
sort-object
-Descending
|
select-object
-First
1
-Property
:
Major
,
Minor
,
Build
$newestVersion
=
$versionObject
.
Major
.
ToString
()
+
"."
+
$versionObject
.
Minor
.
ToString
()
+
"."
+
$versionObject
.
Build
.
ToString
()
|
out-string
$newestVersion
=
$newestVersion
.
TrimEnd
(
"
`r
?
`n
"
)
$nextURISubdirectoryObject
=
(
Invoke-WebRequest
(
"https://download.virtualbox.org/virtualbox/
$newestVersion
/"
)
-UseBasicParsing
)
.
Links
|
Select-Object
href
|
where-object
{
$_
.
href
-Match
"GuestAdditions"
}
$nextUriSubdirectory
=
$nextURISubdirectoryObject
.
href
|
Out-String
$nextUriSubdirectory
=
$nextUriSubdirectory
.
TrimEnd
(
"
`r
?
`n
"
)
$newestVboxToolsURL
=
"https://download.virtualbox.org/virtualbox/
$newestVersion
/
$nextUriSubdirectory
"
Write-Host
"The latest version of VirtualBox tools has been determined to be downloadable from
$newestVboxToolsURL
"
[
Net.ServicePointManager
]::
SecurityProtocol
=
[
Net.SecurityProtocolType
]::
Tls12
;
(
New-Object
System.Net.WebClient
)
.
DownloadFile
(
"
$newestVboxToolsURL
"
,
'C:\Windows\Temp\VBoxGuestAdditions.iso'
)
}
Catch
{
Write-Host
"Unable to determine the latest version of VBox tools. Falling back to hardcoded URL."
[
Net.ServicePointManager
]::
SecurityProtocol
=
[
Net.SecurityProtocolType
]::
Tls12
;
(
New-Object
System.Net.WebClient
)
.
DownloadFile
(
'https://download.virtualbox.org/virtualbox/6.1.8/VBoxGuestAdditions_6.1.8.iso'
,
'C:\Windows\Temp\VBoxGuestAdditions.iso'
)
}
}
cmd
/c
""
C:\PROGRA~1\7-Zip\7z.exe
" x C:\Windows\Temp\VBoxGuestAdditions.iso -oC:\Windows\Temp\virtualbox"
Get-ChildItem
"C:\Windows\Temp\virtualbox\cert\"
-Filter
vbox
*.
cer
|
Foreach-Object
{
C:\Windows\Temp\virtualbox\cert\VBoxCertUtil
add-trusted-publisher
$_
.
FullName
--root
$_
.
FullName
}
cmd
/c
C:\Windows\Temp\virtualbox\VBoxWindowsAdditions.exe
/S
cmd
/c
rd
/S
/Q
"C:\Windows\Temp\virtualbox"
}
cmd
/c
msiexec
/qb
/x
C:\Windows\Temp\7z1900-x64.msi
\ No newline at end of file
scripts/win-7-update-2016-convenience-rollup.ps1
View file @
9ae028e9
...
...
@@ -10,7 +10,19 @@ Write-Host "$(Get-Date -Format G): Extracting $update"
Start-Process -FilePath "
wusa.exe
" -ArgumentList "
C:\Updates\
$kbid
.
msu
/extract:C:\Updates
" -Wait
Write-Host "
$
(
Get-Date
-Format
G
):
Installing
$update
"
Start-Process -FilePath "
dism.exe
" -ArgumentList "
/online
/add-package
/PackagePath:C:\Updates\
$kbid
.
cab
/quiet
/norestart
/LogPath:C:\Windows\Temp\
$kbid
.
log
" -Wait
$process
= (Start-Process -FilePath "
dism.exe
" -ArgumentList "
/online
/add-package
/PackagePath:C:\Updates\
$kbid
.
cab
/quiet
/norestart
/LogPath:C:\Windows\Temp\
$kbid
.
log
" -PassThru)
# https://stackoverflow.com/questions/10262231/obtaining-exitcode-using-start-process-and-waitforexit-instead-of-wait#comment71507068_23797762
$handle
=
$process
.Handle # cache proc.Handle
while (
$null
-eq
$process
.ExitCode)
{
Write-Host "
$
(
Get-Date
-Format
G
):
Convenience
rollup
update
for
Windows
7
is
still
installing
(
PID
$
(
$process
.
Id
)
)"
Wait-Process
-Id
$process
.
Id
-Timeout
180
-ErrorAction
SilentlyContinue
$process
.
Refresh
()
}
Write-Host
"
$(
Get-Date
-Format
G
):
Convenience
rollup
update
for
Windows
7
exited
with
exit
code
$
(
$process
.
ExitCode
)
"
Remove-Item
-LiteralPath
"C:\Updates"
-Force
-Recurse
Write-Host
"
$(
Get-Date
-Format
G
):
Finished
installing
$update
.
The
VM
will
now
reboot
and
continue
the
installation
process.
"
\ No newline at end of file
scripts/win-7-update-sp1.ps1
View file @
9ae028e9
...
...
@@ -16,7 +16,19 @@ Write-Host "$(Get-Date -Format G): Downloading Windows 7 Service Pack 1"
(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
")
Write-Host "
$
(
Get-Date
-Format
G
):
Installing
Windows
7
Service
Pack
1
"
Start-Process -FilePath "
C:\Updates\Windows6.1-KB976932-X64.exe
" -ArgumentList "
/unattend
/nodialog
/norestart
" -Wait
$process
= (Start-Process -FilePath "
C:\Updates\Windows6.1-KB976932-X64.exe
" -ArgumentList "
/unattend
/nodialog
/norestart
" -PassThru)
# https://stackoverflow.com/questions/10262231/obtaining-exitcode-using-start-process-and-waitforexit-instead-of-wait#comment71507068_23797762
$handle
=
$process
.Handle # cache proc.Handle
while (
$null
-eq
$process
.ExitCode)
{
Write-Host "
$
(
Get-Date
-Format
G
):
Windows
7
Service
Pack
1
is
still
installing
(
PID
$
(
$process
.
Id
)
)"
Wait-Process
-Id
$process
.
Id
-Timeout
180
-ErrorAction
SilentlyContinue
$process
.
Refresh
()
}
Write-Host
"
$(
Get-Date
-Format
G
):
Windows
7
Service
Pack
1
exited
with
exit
code
$
(
$process
.
ExitCode
)
"
Remove-Item
-LiteralPath
"C:\Updates"
-Force
-Recurse
...
...
windows_10.json
View file @
9ae028e9
{
"builders"
:
[
{
"accelerator"
:
"kvm"
,
"boot_wait"
:
"6m"
,
"communicator"
:
"winrm"
,
"cpus"
:
"2"
,
...
...
@@ -18,17 +19,21 @@
],
"headless"
:
true
,
"iso_checksum"
:
"{{user `iso_checksum`}}"
,
"iso_checksum_type"
:
"{{user `iso_checksum_type`}}"
,
"iso_url"
:
"{{user `iso_url`}}"
,
"memory"
:
"2048"
,
"shutdown_command"
:
"shutdown /s /t 10 /f /d p:4:1 /c
\"
Packer Shutdown
\"
"
,
"type"
:
"qemu"
,
"accelerator"
:
"kvm"
,
"memory"
:
"{{user `memory`}}"
,
"output_directory"
:
"windows_10-qemu"
,
"qemuargs"
:
[
[
"-drive"
,
"file=windows_10-qemu/{{ .Name }},if=virtio,cache=writeback,discard=ignore,format=qcow2,index=1"
],
[
"-drive"
,
"file={{ user `virtio_win_iso` }},media=cdrom,index=3"
]
[
"-drive"
,
"file=windows_10-qemu/{{ .Name }},if=virtio,cache=writeback,discard=ignore,format=qcow2,index=1"
],
[
"-drive"
,
"file={{ user `virtio_win_iso` }},media=cdrom,index=3"
]
],
"shutdown_command"
:
"shutdown /s /t 10 /f /d p:4:1 /c
\"
Packer Shutdown
\"
"
,
"type"
:
"qemu"
,
"vm_name"
:
"{{user `vm_name`}}"
,
"winrm_password"
:
"vagrant"
,
"winrm_timeout"
:
"{{user `winrm_timeout`}}"
,
...
...
@@ -53,9 +58,8 @@
],
"guest_additions_mode"
:
"none"
,
"iso_checksum"
:
"{{user `iso_checksum`}}"
,
"iso_checksum_type"
:
"{{user `iso_checksum_type`}}"
,
"iso_url"
:
"{{user `iso_url`}}"
,
"memory"
:
"
2048
"
,
"memory"
:
"
{{user `memory`}}
"
,
"shutdown_command"
:
"shutdown /s /t 10 /f /d p:4:1 /c
\"
Packer Shutdown
\"
"
,
"switch_name"
:
"{{user `switch_name`}}"
,
"type"
:
"hyperv-iso"
,
...
...
@@ -86,9 +90,8 @@
"guest_os_type"
:
"windows9-64"
,
"headless"
:
"{{user `headless`}}"
,
"iso_checksum"
:
"{{user `iso_checksum`}}"
,
"iso_checksum_type"
:
"{{user `iso_checksum_type`}}"
,
"iso_url"
:
"{{user `iso_url`}}"
,
"memory"
:
2048
,
"memory"
:
"{{user `memory`}}"
,
"shutdown_command"
:
"shutdown /s /t 10 /f /d p:4:1 /c
\"
Packer Shutdown
\"
"
,
"type"
:
"vmware-iso"
,
"version"
:
14
,
...
...
@@ -125,15 +128,58 @@
"guest_os_type"
:
"Windows10_64"
,
"headless"
:
"{{user `headless`}}"
,
"iso_checksum"
:
"{{user `iso_checksum`}}"
,
"iso_checksum_type"
:
"{{user `iso_checksum_type`}}"
,
"iso_url"
:
"{{user `iso_url`}}"
,
"memory"
:
2048
,
"memory"
:
"{{user `memory`}}"
,
"shutdown_command"
:
"shutdown /s /t 10 /f /d p:4:1 /c
\"
Packer Shutdown
\"
"
,
"type"
:
"virtualbox-iso"
,
"vm_name"
:
"{{user `vm_name`}}"
,
"winrm_password"
:
"vagrant"
,
"winrm_timeout"
:
"{{user `winrm_timeout`}}"
,
"winrm_username"
:
"vagrant"
},
{
"boot_command"
:
""
,
"boot_wait"
:
"6m"
,
"communicator"
:
"winrm"
,
"cpus"
:
2
,
"disk_size"
:
"{{user `disk_size`}}"
,
"floppy_files"
:
[
"{{user `autounattend`}}"
,
"./floppy/WindowsPowershell.lnk"
,
"./floppy/PinTo10.exe"
,
"./scripts/fixnetwork.ps1"
,
"./scripts/disable-screensaver.ps1"
,
"./scripts/disable-winrm.ps1"
,
"./scripts/enable-winrm.ps1"
,