Skip to content

Instantly share code, notes, and snippets.

@ruo91
Last active September 26, 2023 04:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruo91/6332459b3d54b01029d162c1a69c28b7 to your computer and use it in GitHub Desktop.
Save ruo91/6332459b3d54b01029d162c1a69c28b7 to your computer and use it in GitHub Desktop.
OpenShift on vSphere - Create vCenter Role (PowerShell)
<#
.SYNOPSIS
openshift-vcenter-role.ps1 - PowerShell Script to create a new vCenter Roles algined with the prereqs for the OpenShift Container Platform Install.
.DESCRIPTION
This script is used to create a new roles on your vCenter server.
The newly created role will be filled with the needed permissions for installing OpenShift Container Platform using the IPI Method.
The permissions are based on the documentation found here: https://docs.openshift.com/container-platform/4.13/installing/installing_vsphere/installing-vsphere-installer-provisioned.html
.OUTPUTS
Results are printed to the console.
.NOTES
Author Dean Lewis, https://vEducate.co.uk, Twitter: @saintdle
Modify Yongbok Kim, https://yongbok.net/blog/
Change Log V1.00, 09/26/2023 - Initial version
.LICENSE
MIT License
Copyright (c) 2020 Dean Lewis
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
#>
# Load the PowerCLI SnapIn and set the configuration
Add-PSSnapin VMware.VimAutomation.Core -ea "SilentlyContinue"
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false | Out-Null
# Get the vCenter Server Name to connect to
$vCenterServer = Read-Host "Enter vCenter Server host name (DNS with FQDN or IP address)"
# Get User to connect to vCenter Server
$vCenterUser = Read-Host "Enter your user name (DOMAIN\User or user@domain.com)"
# Get Password to connect to the vCenter Server
$vCenterUserPassword = Read-Host "Enter your password (this will be converted to a secure string)" -AsSecureString:$true
# Collect username and password as credentials
$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $vCenterUser,$vCenterUserPassword
# Connect to the vCenter Server with collected credentials
Connect-VIServer -Server $vCenterServer -Credential $Credentials | Out-Null
Write-Host "Connected to your vCenter server $vCenterServer" -ForegroundColor Green
# Create OpenShift-Install role
$OpenShiftInstallPrivilege = @(
'Folder.Create'
'Folder.Delete'
'Cns.Searchable'
'Network.Assign'
'Sessions.ValidateSession'
'StorageProfile.Update'
'StorageProfile.View'
'Host.Config.Storage'
'Resource.AssignVMToPool'
'VApp.Import'
'VApp.AssignResourcePool'
'Datastore.Browse'
'Datastore.AllocateSpace'
'Datastore.FileManagement'
'InventoryService.Tagging.AttachTag'
'InventoryService.Tagging.CreateCategory'
'InventoryService.Tagging.CreateTag'
'InventoryService.Tagging.DeleteCategory'
'InventoryService.Tagging.DeleteTag'
'InventoryService.Tagging.EditCategory'
'InventoryService.Tagging.EditTag'
'InventoryService.Tagging.ObjectAttachable'
'VirtualMachine.Config.AddExistingDisk'
'VirtualMachine.Config.AddNewDisk'
'VirtualMachine.Config.AddRemoveDevice'
'VirtualMachine.Config.AdvancedConfig'
'VirtualMachine.Config.Annotation'
'VirtualMachine.Config.CPUCount'
'VirtualMachine.Config.DiskExtend'
'VirtualMachine.Config.DiskLease'
'VirtualMachine.Config.EditDevice'
'VirtualMachine.Config.Memory'
'VirtualMachine.Config.RemoveDisk'
'VirtualMachine.Config.Rename'
'VirtualMachine.Config.ResetGuestInfo'
'VirtualMachine.Config.Resource'
'VirtualMachine.Config.Settings'
'VirtualMachine.Config.UpgradeVirtualHardware'
'VirtualMachine.Interact.GuestControl'
'VirtualMachine.Interact.PowerOff'
'VirtualMachine.Interact.PowerOn'
'VirtualMachine.Interact.Reset'
'VirtualMachine.Interact.ConsoleInteract'
'VirtualMachine.Inventory.Create'
'VirtualMachine.Inventory.CreateFromExisting'
'VirtualMachine.Inventory.Delete'
'VirtualMachine.Provisioning.Clone'
'VirtualMachine.Provisioning.MarkAsTemplate'
'VirtualMachine.Provisioning.DeployTemplate'
)
$OpenShiftInstallRole = New-VIRole -Name 'OpenShift' -Privilege (Get-VIPrivilege -Id $OpenShiftInstallPrivilege) | Out-Null
Write-Host "Creating vCenter role $OpenShiftInstallRole" -ForegroundColor Green
# Disconnecting from the vCenter Server
Disconnect-VIServer -Confirm:$false
Write-Host "Disconnected from your vCenter Server $vCenterServer" -ForegroundColor Green
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment