This commit is contained in:
39
packer/oci/scripts/attach_secondary_vnic.ps1
Normal file
39
packer/oci/scripts/attach_secondary_vnic.ps1
Normal file
@ -0,0 +1,39 @@
|
||||
function Get-Second-Vnic-Ocid() {
|
||||
$ocid = ""
|
||||
$vnics = Invoke-RestMethod -Uri "http://169.254.169.254/opc/v1/vnics/"
|
||||
if ($vnics.Count -eq 2) {
|
||||
$ocid = $vnics[1].vnicId
|
||||
} else {
|
||||
Write-Host "vnics count not equal 2"
|
||||
}
|
||||
return $ocid
|
||||
}
|
||||
|
||||
$vnicId = Get-Second-Vnic-Ocid
|
||||
Write-Host "found vnic id: ${vnicId}"
|
||||
|
||||
|
||||
$retryDelaySeconds = 30
|
||||
# We should continue to retry indefinitely until the vnic is
|
||||
# detected by IMDS
|
||||
# https://docs.oracle.com/en-us/iaas/Content/Compute/Tasks/gettingmetadata.htm
|
||||
while($vnicId -eq "") {
|
||||
$vnicId = Get-Second-Vnic-Ocid
|
||||
Write-Host("Getting second vnic failed. Waiting " + $retryDelaySeconds + " seconds before next attempt.")
|
||||
Start-Sleep -Seconds $retryDelaySeconds
|
||||
}
|
||||
|
||||
if ($vnicId -ne "") {
|
||||
Write-Host "Pulling down the secondary_vnic_windows_configure.ps1"
|
||||
Invoke-WebRequest -Uri "https://docs.oracle.com/en-us/iaas/Content/Resources/Assets/secondary_vnic_windows_configure.ps1" -OutFile "C:\Users\opc\secondary_vnic_windows_configure.ps1"
|
||||
|
||||
Write-Host "calling script using ${vnicId}"
|
||||
|
||||
, 'Y', 'A' | powershell "C:\Users\opc\secondary_vnic_windows_configure.ps1 ${vnicId}"
|
||||
Write-Error "secondary_vnic_windows_configure.ps1 - done"
|
||||
|
||||
$ipconfig = ipconfig
|
||||
Write-Error "${ipconfig}"
|
||||
}else{
|
||||
Write-Error "VNIC OCID is empty. Can't configure."
|
||||
}
|
47
packer/oci/scripts/enable_second_nic.ps1
Normal file
47
packer/oci/scripts/enable_second_nic.ps1
Normal file
@ -0,0 +1,47 @@
|
||||
|
||||
$newNetAdapterName = "Ethernet 2"
|
||||
|
||||
# check for two nics
|
||||
$netAdapters = Get-NetAdapter
|
||||
if ($netAdapters.Length -le 1) {
|
||||
Write-Output "Could not find multiple Network Adapters."
|
||||
Exit 1
|
||||
}
|
||||
|
||||
$secondNic = $netAdapters[1]
|
||||
|
||||
# make sure the network adapter is known
|
||||
if ($secondNic.Name -ne "") {
|
||||
Write-Output "Changing ${secondNic.Name} to ${newNetAdapterName} ..."
|
||||
try
|
||||
{
|
||||
Rename-NetAdapter -Name $secondNic.Name -NewName "${newNetAdapterName}"
|
||||
$secondNic.Name = $newNetAdapterName
|
||||
}
|
||||
catch
|
||||
{
|
||||
Write-Output "Could not rename net adapter"
|
||||
Write-Output $_
|
||||
}
|
||||
} else {
|
||||
Write-Output "Can not change network adapter named: ${secondNic.Name}"
|
||||
}
|
||||
|
||||
# check that second is disabled
|
||||
if ($secondNic.Status -ne "up") {
|
||||
|
||||
try
|
||||
{
|
||||
Enable-NetAdapter -Name $secondNic.Name
|
||||
Write-Output "${secondNic.Name} enabled ..."
|
||||
}
|
||||
catch
|
||||
{
|
||||
Write-Output "Could not enable net adapter"
|
||||
Write-Output $_
|
||||
}
|
||||
} else {
|
||||
Write-Output "${secondNic.Name} already enabled ..."
|
||||
}
|
||||
|
||||
Remove-Item -Path .\enable_second_nic.ps1
|
27
packer/oci/scripts/set_bootstrap.sh
Executable file
27
packer/oci/scripts/set_bootstrap.sh
Executable file
@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 2021 The Kubernetes Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# This script overrides the 'opc' password set in the winrm_bootstrap.txt file
|
||||
# This script is assumed to be run from the make file hence the pathing to the winrm_bootstrap.txt
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
echo "Changing Password in winrm_bootstrap.txt"
|
||||
|
||||
cp packer/oci/scripts/winrm_bootstrap_template.txt packer/oci/scripts/winrm_bootstrap.txt
|
||||
|
||||
sed "s/(\[adsi\].*/([adsi](\"WinNT:\/\/\"+\$opcUser.caption).replace(\"\\\\\",\"\/\")).SetPassword(\"$OPC_USER_PASSWORD\")/g" packer/oci/scripts/winrm_bootstrap.txt | tee packer/oci/scripts/winrm_bootstrap.txt >/dev/null
|
37
packer/oci/scripts/sysprep.ps1
Normal file
37
packer/oci/scripts/sysprep.ps1
Normal file
@ -0,0 +1,37 @@
|
||||
# Copyright 2020 The Kubernetes Authors.
|
||||
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
if( Test-Path $Env:SystemRoot\system32\Sysprep\unattend.xml ) {
|
||||
Remove-Item $Env:SystemRoot\system32\Sysprep\unattend.xml -Force
|
||||
}
|
||||
|
||||
$unattendedXml = "$ENV:ProgramFiles\Cloudbase Solutions\Cloudbase-Init\conf\Unattend.xml"
|
||||
$FileExists = Test-Path $unattendedXml
|
||||
If ($FileExists -eq $True) {
|
||||
# Use the Cloudbase-init provided unattend file during install
|
||||
Write-Output "Using cloudbase-init unattend file for sysprep: $unattendedXml"
|
||||
& $Env:SystemRoot\System32\Sysprep\Sysprep.exe /oobe /generalize /mode:vm /quit /quiet /unattend:$unattendedXml
|
||||
}else {
|
||||
& $Env:SystemRoot\System32\Sysprep\Sysprep.exe /oobe /generalize /mode:vm /quit /quiet
|
||||
}
|
||||
|
||||
# Wait for the image to be reset
|
||||
while($true) {
|
||||
$imageState = (Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\State).ImageState
|
||||
Write-Output $imageState
|
||||
if ($imageState -eq 'IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE') { break }
|
||||
Start-Sleep -s 5
|
||||
}
|
||||
|
||||
Write-Output '>>> Sysprep complete ...'
|
25
packer/oci/scripts/unset_bootstrap.sh
Executable file
25
packer/oci/scripts/unset_bootstrap.sh
Executable file
@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 2021 The Kubernetes Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# This script overrides the 'opc' password set in the winrm_bootstrap.txt file
|
||||
# This script is assumed to be run from the make file hence the pathing to the winrm_bootstrap.txt
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
echo "resetting Password in winrm_bootstrap.txt"
|
||||
|
||||
rm packer/oci/scripts/winrm_bootstrap.txt
|
50
packer/oci/scripts/winrm_bootstrap_template.txt
Normal file
50
packer/oci/scripts/winrm_bootstrap_template.txt
Normal file
@ -0,0 +1,50 @@
|
||||
<powershell>
|
||||
|
||||
# MAKE SURE IN YOUR PACKER CONFIG TO SET:
|
||||
#
|
||||
#
|
||||
# "winrm_username": "Administrator",
|
||||
# "winrm_insecure": true,
|
||||
# "winrm_use_ssl": true,
|
||||
#
|
||||
#
|
||||
#ps1_sysnative
|
||||
cmd /C 'wmic UserAccount where Name="opc" set PasswordExpires=False'
|
||||
$opcUser = get-wmiobject win32_useraccount | Where-Object { $_.Name -match 'opc' }
|
||||
([adsi]("WinNT://"+$opcUser.caption).replace("\","/")).SetPassword("myTemp#Pa55_Word")
|
||||
|
||||
write-output "Running User Data Script"
|
||||
write-host "(host) Running User Data Script"
|
||||
|
||||
Set-ExecutionPolicy Unrestricted -Scope LocalMachine -Force -ErrorAction Ignore
|
||||
|
||||
# Don't set this before Set-ExecutionPolicy as it throws an error
|
||||
$ErrorActionPreference = "stop"
|
||||
|
||||
# Remove HTTP listener
|
||||
Remove-Item -Path WSMan:\Localhost\listener\listener* -Recurse
|
||||
|
||||
# Create a self-signed certificate to let ssl work
|
||||
$Cert = New-SelfSignedCertificate -CertstoreLocation Cert:\LocalMachine\My -DnsName "packer"
|
||||
New-Item -Path WSMan:\LocalHost\Listener -Transport HTTPS -Address * -CertificateThumbPrint $Cert.Thumbprint -Force
|
||||
|
||||
# WinRM
|
||||
write-output "Setting up WinRM"
|
||||
write-host "(host) setting up WinRM"
|
||||
|
||||
cmd.exe /c winrm quickconfig -q
|
||||
cmd.exe /c winrm set "winrm/config" '@{MaxTimeoutms="1800000"}'
|
||||
cmd.exe /c winrm set "winrm/config/winrs" '@{MaxMemoryPerShellMB="1024"}'
|
||||
cmd.exe /c winrm set "winrm/config/service" '@{AllowUnencrypted="true"}'
|
||||
cmd.exe /c winrm set "winrm/config/client" '@{AllowUnencrypted="true"}'
|
||||
cmd.exe /c winrm set "winrm/config/service/auth" '@{Basic="true"}'
|
||||
cmd.exe /c winrm set "winrm/config/client/auth" '@{Basic="true"}'
|
||||
cmd.exe /c winrm set "winrm/config/service/auth" '@{CredSSP="true"}'
|
||||
cmd.exe /c winrm set "winrm/config/listener?Address=*+Transport=HTTPS" "@{Port=`"5986`";Hostname=`"packer`";CertificateThumbprint=`"$($Cert.Thumbprint)`"}"
|
||||
cmd.exe /c netsh advfirewall firewall set rule group="remote administration" new enable=yes
|
||||
cmd.exe /c netsh firewall add portopening TCP 5986 "Port 5986"
|
||||
cmd.exe /c net stop winrm
|
||||
cmd.exe /c sc config winrm start= auto
|
||||
cmd.exe /c net start winrm
|
||||
|
||||
</powershell>
|
Reference in New Issue
Block a user