Add yamllint;Replay downstream changes
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Danny Bessems 2021-04-09 11:43:42 +02:00
parent 8f54a61482
commit 34e14e721f
3 changed files with 28 additions and 18 deletions

View File

@ -19,6 +19,8 @@ steps:
sed -i -e "s/<<img-password>>/$${WINRM_PASSWORD}/g" \ sed -i -e "s/<<img-password>>/$${WINRM_PASSWORD}/g" \
packer/preseed/Server2019/Autounattend.xml \ packer/preseed/Server2019/Autounattend.xml \
packer/preseed/Server2019/Sysprep_Unattend.xml packer/preseed/Server2019/Sysprep_Unattend.xml
- |
yamllint -d "{extends: relaxed, rules: {line-length: disable}}" scripts
- | - |
packer validate \ packer validate \
-var-file=packer/variables.vsphere.json \ -var-file=packer/variables.vsphere.json \

View File

@ -4,4 +4,4 @@ Param(
) )
# Create scheduled task # Create scheduled task
& schtasks.exe /Create /TN 'OVF-Properties' /SC ONSTART /RU SYSTEM /TR "powershell.exe -file C:\Payload\Apply-OVFProperties.ps1" & schtasks.exe /Create /TN 'FirstBoot' /SC ONSTART /RU SYSTEM /TR "powershell.exe -file C:\Payload\Apply-FirstBootConfig.ps1"

View File

@ -3,18 +3,23 @@ Param(
# No parameters # No parameters
) )
$SetLocationSplat = @{
Path = $PSScriptRoot
}
Set-Location @SetLocationSplat
$NewEventLogSplat = @{ $NewEventLogSplat = @{
LogName = 'Application' LogName = 'Application'
Source = 'OVF-Properties' Source = 'FirstBoot'
ErrorAction = 'SilentlyContinue' ErrorAction = 'SilentlyContinue'
} }
New-EventLog @NewEventLogSplat New-EventLog @NewEventLogSplat
$WriteEventLogSplat = @{ $WriteEventLogSplat = @{
LogName = 'Application' LogName = 'Application'
Source = 'OVF-Properties' Source = 'FirstBoot'
EntryType = 'Information' EntryType = 'Information'
EventID = 1 EventID = 1
Message = 'OVF-Properties sequence initiated' Message = "FirstBoot sequence initiated [working directory: '$PWD']"
} }
Write-EventLog @WriteEventLogSplat Write-EventLog @WriteEventLogSplat
@ -40,13 +45,13 @@ Switch ($ovfPropertyValues['deployment.type']) {
# Mandatory values missing, cannot provision. # Mandatory values missing, cannot provision.
$WriteEventLogSplat = @{ $WriteEventLogSplat = @{
LogName = 'Application' LogName = 'Application'
Source = 'OVF-Properties' Source = 'FirstBoot'
EntryType = 'Error' EntryType = 'Error'
EventID = 66 EventID = 66
Message = "Unexpected or no value set for property 'deployment.type', cannot provision." Message = "Unexpected or no value set for property 'deployment.type', cannot provision."
} }
Write-EventLog @WriteEventLogSplat Write-EventLog @WriteEventLogSplat
& schtasks.exe /Change /TN 'OVF-Properties' /DISABLE & schtasks.exe /Change /TN 'FirstBoot' /DISABLE
Stop-Computer -Force Stop-Computer -Force
Exit Exit
} }
@ -60,13 +65,13 @@ If ($MissingProperties.Length -gt 0) {
# Mandatory values missing, cannot provision. # Mandatory values missing, cannot provision.
$WriteEventLogSplat = @{ $WriteEventLogSplat = @{
LogName = 'Application' LogName = 'Application'
Source = 'OVF-Properties' Source = 'FirstBoot'
EntryType = 'Error' EntryType = 'Error'
EventID = 66 EventID = 66
Message = "Missing values for mandatory properties $(($MissingProperties | ForEach-Object {"'{0}'" -f $_}) -join ', '), cannot provision." Message = "Missing values for mandatory properties $(($MissingProperties | ForEach-Object {"'{0}'" -f $_}) -join ', '), cannot provision."
} }
Write-EventLog @WriteEventLogSplat Write-EventLog @WriteEventLogSplat
& schtasks.exe /Change /TN 'OVF-Properties' /DISABLE & schtasks.exe /Change /TN 'FirstBoot' /DISABLE
Stop-Computer -Force Stop-Computer -Force
Exit Exit
} }
@ -109,7 +114,7 @@ If ((Get-WmiObject -Class 'Win32_NetworkAdapterConfiguration').IPAddress -NotCon
If ($Timestamp.AddMinutes($TimeoutMinutes) -lt (Get-Date)) { If ($Timestamp.AddMinutes($TimeoutMinutes) -lt (Get-Date)) {
$WriteEventLogSplat = @{ $WriteEventLogSplat = @{
LogName = 'Application' LogName = 'Application'
Source = 'OVF-Properties' Source = 'FirstBoot'
EntryType = 'Warning' EntryType = 'Warning'
EventID = 13 EventID = 13
Message = "Timeout after $($TimeoutMinutes) minutes waiting for network connection to become available." Message = "Timeout after $($TimeoutMinutes) minutes waiting for network connection to become available."
@ -195,25 +200,28 @@ Switch ($ovfPropertyValues['deployment.type']) {
$GetItemSplat = @{ $GetItemSplat = @{
Path = "$($PSScriptRoot)\Scripts\*.ps1" Path = "$($PSScriptRoot)\Scripts\*.ps1"
} }
Get-Item @GetItemSplat | ForEach-Object { ForEach ($Script in (Get-Item @GetItemSplat)) {
Try { Try {
$WriteEventLogSplat = @{ $WriteEventLogSplat = @{
LogName = 'Application' LogName = 'Application'
Source = 'OVF-Properties' Source = 'FirstBoot'
EntryType = 'Information' EntryType = 'Information'
EventID = 4 EventID = 4
Message = "Running script: '$($_.FullName)'" Message = "Running script: '$($Script.FullName)'"
} }
Write-EventLog @WriteEventLogSplat Write-EventLog @WriteEventLogSplat
& $_.FullName -Parameter $ovfPropertyValues & $Script.FullName -Parameter $ovfPropertyValues
} }
Catch { Catch {
$WriteEventLogSplat = @{ $WriteEventLogSplat = @{
LogName = 'Application' LogName = 'Application'
Source = 'OVF-Properties' Source = 'FirstBoot'
EntryType = 'Error' EntryType = 'Error'
EventID = 66 EventID = 66
Message = $_.Exception.Message Message = @"
Error occurred while executing script '$($Script.Name)':
$($_.Exception.Message)
"@
} }
Write-EventLog @WriteEventLogSplat Write-EventLog @WriteEventLogSplat
} }
@ -221,10 +229,10 @@ Get-Item @GetItemSplat | ForEach-Object {
$WriteEventLogSplat = @{ $WriteEventLogSplat = @{
LogName = 'Application' LogName = 'Application'
Source = 'OVF-Properties' Source = 'FirstBoot'
EntryType = 'Information' EntryType = 'Information'
EventID = 42 EventID = 42
Message = 'OVF-Properties sequence applied and finished' Message = 'FirstBoot sequence applied and finished'
} }
Write-EventLog @WriteEventLogSplat Write-EventLog @WriteEventLogSplat
& schtasks.exe /Change /TN 'OVF-Properties' /DISABLE & schtasks.exe /Change /TN 'FirstBoot' /DISABLE