Skip to content

Commit

Permalink
Various bootstrap fixes for Server 2008, install roles during CI
Browse files Browse the repository at this point in the history
jborean93 committed Jan 19, 2019
1 parent bb46158 commit c0769bf
Showing 3 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ hosts-*
*.retry

# Galaxy files
roles/jborean.*
roles/jborean93.*

# Temp Packer files
2008-x86/
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ install:
- pip install pip setuptools
- pip install -U pip setuptools
- pip install ansible-lint
- ansible-galaxy install -r requirements.yml -p roles

script:
# show the ansible-lint version
27 changes: 24 additions & 3 deletions roles/packer-setup/templates/bootstrap.ps1.j2
Original file line number Diff line number Diff line change
@@ -2,6 +2,12 @@ $ErrorActionPreference = 'Stop'
$tmp_dir = "$env:SystemDrive\temp"
$script_dir = Split-Path -Path $($script:MyInvocation.MyCommand.Path) -Parent

trap {
$msg = "Unhandled exception`r`n$($_ | Out-String)"
Write-Log -message $msg -level "ERROR"
Write-Error -ErrorRecord $_
}

Function Write-Log($message, $level="INFO") {
# Poor man's implementation of Log4Net
$date_stamp = Get-Date -Format s
@@ -73,7 +79,16 @@ Function Extract-Zip($zip, $dest) {
}

Function Get-NetKVMDriverPath {
$drive = (Get-PSDrive -PSProvider FileSystem).Name | Where-Object { Test-Path -LiteralPath "$($_):\NetKVM" }
$drive = (Get-PSDrive -PSProvider FileSystem).Name | Where-Object {
$drive = $_
# Annoying hack to run with PSv1, Test-Path complain if a null value is
# in the string, and $_ isn't valid in PSv1. We don't run this cmdlet
# in this version so this is just to get the whole script running
if ($null -eq $drive) {
$drive = "C"
}
Test-Path -LiteralPath "$($drive):\NetKVM"
}

$host_key = "{{ pri_packer_setup_config.driver_host_string }}"
$architecture = $env:PROCESSOR_ARCHITECTURE
@@ -201,7 +216,12 @@ namespace PackerWindoze
$driver_cert = (Get-AuthenticodeSignature -LiteralPath $sys_path.FullName).SignerCertificate

$trusted_certs = (Get-ChildItem -Path Cert:\LocalMachine\TrustedPublisher).Thumbprint
if ($driver_cert.Thumbprint -notin $trusted_certs) {
if ($null -eq $trusted_certs) {
# The 1st arg of IndexOf cannot be $null so this is a sanity check for that
$trusted_certs = @()
}
# Cannot use -in or -notin as PSv1 (Server 2008) will fail to parse the script
if (($null -ne $driver_cert.Thumbprint) -and ([System.Array]::IndexOf($trusted_certs, $driver_cert.Thumbprint) -eq -1)) {
Write-Log -message "Certificate $($driver_cert.Thumbprint) not in TrustedPublisher store"
$store_name = [System.Security.Cryptography.X509Certificates.StoreName]::TrustedPublisher
$store_location = [System.Security.Cryptography.X509Certificates.Storelocation]::LocalMachine
@@ -211,7 +231,8 @@ namespace PackerWindoze
try {
$store.Add($driver_cert)
} finally {
$store.Dispose()
# Only .NET 4.6.2 has X509 as an IDisposable, use Close for backwards compatibility
$store.Close()
}
}

0 comments on commit c0769bf

Please sign in to comment.