Skip to content

Instantly share code, notes, and snippets.

@johnsimcall
Last active April 30, 2024 06:32
Show Gist options
  • Save johnsimcall/69e7e7de04130c59c9bd51adbf9d9a2a to your computer and use it in GitHub Desktop.
Save johnsimcall/69e7e7de04130c59c9bd51adbf9d9a2a to your computer and use it in GitHub Desktop.
PowerShell script to create required vSphere roles/permissions for OpenShift 4 installer
# Commands to install VMware PowerCLI and allow PowerShell to run scripts, if you're using a Desktop version of Windows (e.g. not Windows Server)
PS> Install-Module VMware.PowerCLI -Scope CurrentUser
PS> #Install-Module VMware.PowerCLI -Scope CurrentUser -SkipPublisherCheck -AllowClobber -Force
# The second Install-Module command can be used if you get an error regarding the authenticode signature
# PackageManagement\Install-Package : The module 'VMware.VimAutomation.Sdk' cannot be installed or updated because the
# authenticode signature of the file 'VMware.VimAutomation.Sdk.cat' is not valid.
PS> Get-Module -Name VMware.PowerCLI -ListAvailable
PS> Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser
PS> .\Create_vCenter_OpenShift_Install_Roles.ps1
<#
.SYNOPSIS
Create_vCenter_OpenShift_Install_Roles.ps1 - PowerShell Script to create a new vCenter Roles algined with the prereqs for the OpenShift Container Platform Install.
Originally created by https://github.com/saintdle/PowerCLI
Reformated by https://github.com/ecwpz91/PowerCLI
.DESCRIPTION
This script is used to create new roles on your vCenter server.
The newly created roles 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/latest/installing/installing_vsphere/installing-vsphere-installer-provisioned.html#installation-vsphere-installer-infra-requirements_installing-vsphere-installer-provisioned
After the roles are created, they need to be manually associated with a username/serviceaccount and a vSphere object (like a Folder, Cluster, Datacenter, etc...)
.OUTPUTS
Results are printed to the console.
.NOTES
Author Dean Lewis, https://vEducate.co.uk, Twitter: @saintdle
Author John Call, jcall@redhat.com
Change Log V1.00, 07/11/2020 - Initial version
Change Log V2.00, 01/04/2021 - Updated for openshift release 4.9
Change Log V20220531, 05/31/2022 - Updated for openshift release 4.10, added ResourcePool role
.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 address, username and password as PSCredential
$vCenterServer = Read-Host "Enter vCenter Server host name (DNS with FQDN or IP address)"
$vCenterUser = Read-Host "Enter your user name (DOMAIN\User or user@domain.com)"
$vCenterUserPassword = Read-Host "Enter your password (this will be converted to a secure string)" -AsSecureString:$true
$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
$OpenShift_vCenter = @(
'Cns.Searchable',
'InventoryService.Tagging.AttachTag',
'InventoryService.Tagging.CreateCategory',
'InventoryService.Tagging.CreateTag',
'InventoryService.Tagging.DeleteCategory',
'InventoryService.Tagging.DeleteTag',
'InventoryService.Tagging.EditCategory',
'InventoryService.Tagging.EditTag',
'Sessions.ValidateSession',
'StorageProfile.Update',
'StorageProfile.View'
)
$OpenShiftInstallRole = New-VIRole -Name 'OpenShift-vCenter' -Privilege (Get-VIPrivilege -Id $OpenShift_vCenter)
Write-Host "Created vCenter role $OpenShiftInstallRole" -ForegroundColor Green
$OpenShift_Cluster = @(
'Host.Config.Storage',
'Resource.AssignVMToPool',
'VApp.AssignResourcePool',
'VApp.Import',
'VirtualMachine.Config.AddNewDisk'
)
$OpenShiftInstallRole = New-VIRole -Name 'OpenShift-Cluster-propagate' -Privilege (Get-VIPrivilege -Id $OpenShift_Cluster)
Write-Host "Created vCenter role $OpenShiftInstallRole" -ForegroundColor Green
$OpenShift_ResourcePool = @(
'Host.Config.Storage',
'Resource.AssignVMToPool',
'VApp.AssignResourcePool',
'VApp.Import',
'VirtualMachine.Config.AddNewDisk'
)
$OpenShiftInstallRole = New-VIRole -Name 'OpenShift-ResourcePool-propagate' -Privilege (Get-VIPrivilege -Id $OpenShift_Cluster)
Write-Host "Created vCenter role $OpenShiftInstallRole" -ForegroundColor Green
$OpenShift_Datastore = @(
'Datastore.AllocateSpace',
'Datastore.Browse',
'Datastore.FileManagement',
'InventoryService.Tagging.ObjectAttachable'
)
$OpenShiftInstallRole = New-VIRole -Name 'OpenShift-Datastore' -Privilege (Get-VIPrivilege -Id $OpenShift_Datastore)
Write-Host "Created vCenter role $OpenShiftInstallRole" -ForegroundColor Green
$OpenShift_PortGroup = @(
'Network.Assign'
)
$OpenShiftInstallRole = New-VIRole -Name 'OpenShift-PortGroup' -Privilege (Get-VIPrivilege -Id $OpenShift_PortGroup)
Write-Host "Created vCenter role $OpenShiftInstallRole" -ForegroundColor Green
$OpenShift_VMFolder = @(
'InventoryService.Tagging.ObjectAttachable',
'Resource.AssignVMToPool',
'VApp.Import',
'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.Inventory.Create',
'VirtualMachine.Inventory.CreateFromExisting',
'VirtualMachine.Inventory.Delete',
'VirtualMachine.Provisioning.Clone',
'VirtualMachine.Provisioning.DeployTemplate',
'VirtualMachine.Provisioning.MarkAsTemplate'
)
$OpenShiftInstallRole = New-VIRole -Name 'OpenShift-VMFolder-propagate' -Privilege (Get-VIPrivilege -Id $OpenShift_VMFolder)
Write-Host "Created vCenter role $OpenShiftInstallRole" -ForegroundColor Green
$OpenShift_Datacenter = @(
'InventoryService.Tagging.ObjectAttachable',
'Resource.AssignVMToPool',
'VApp.Import',
'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.Inventory.Create',
'VirtualMachine.Inventory.CreateFromExisting',
'VirtualMachine.Inventory.Delete',
'VirtualMachine.Provisioning.Clone',
'VirtualMachine.Provisioning.DeployTemplate',
'VirtualMachine.Provisioning.MarkAsTemplate',
'Folder.Create',
'Folder.Delete'
)
$OpenShiftInstallRole = New-VIRole -Name 'OpenShift-Datacenter-propagate' -Privilege (Get-VIPrivilege -Id $OpenShift_Datacenter)
Write-Host "Created vCenter role $OpenShiftInstallRole" -ForegroundColor Green
# Disconnecting from the vCenter Server
Disconnect-VIServer -Confirm:$false
Write-Host "Disconnected from your vCenter Server $vCenterServer" -ForegroundColor Green
<#
.SYNOPSIS
Remove_vCenter_OpenShift_Install_Roles.ps1 - PowerShell Script to delete vCenter Roles created by Create_vCenter_OpenShift_Install_Roles.ps1
.DESCRIPTION
This script is used to delete roles previously created on your vCenter server.
.OUTPUTS
Results are printed to the console.
.NOTES
Author John Call, jcall@redhat.com
Change Log V1.00, 08/24/2022 - 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 address, username and password as PSCredential
$vCenterServer = Read-Host "Enter vCenter Server host name (DNS with FQDN or IP address)"
$vCenterUser = Read-Host "Enter your user name (DOMAIN\User or user@domain.com)"
$vCenterUserPassword = Read-Host "Enter your password (this will be converted to a secure string)" -AsSecureString:$true
$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
# Removing roles
Remove-VIRole -Role 'OpenShift-vCenter' -Confirm:$false -Verbose
Remove-VIRole -Role 'OpenShift-Cluster-propagate' -Confirm:$false -Verbose
Remove-VIRole -Role 'OpenShift-ResourcePool-propagate' -Confirm:$false -Verbose
Remove-VIRole -Role 'OpenShift-Datastore' -Confirm:$false -Verbose
Remove-VIRole -Role 'OpenShift-PortGroup' -Confirm:$false -Verbose
Remove-VIRole -Role 'OpenShift-VMFolder-propagate' -Confirm:$false -Verbose
Remove-VIRole -Role 'OpenShift-Datacenter-propagate' -Confirm:$false -Verbose
# Disconnecting from the vCenter Server
Disconnect-VIServer -Confirm:$false
Write-Host "Disconnected from your vCenter Server $vCenterServer" -ForegroundColor Green
@johnsimcall
Copy link
Author

johnsimcall commented Jan 6, 2022

The list of required permissions is documented in the Installation Guide

Please note: You can apply either the OpenShift-Datacenter-propagate role if openshift-install is allowed to create a new folder for the VMs (default behavior.) Or, if openshift-install will create VMs in a specific folder, apply the OpenShift-VMFolder-propagate role on the folder and apply a ReadOnly permission on the target Datacenter (and remember to manually update your install-config.yaml with the folder path.

platform:
  vsphere:
    failureDomains:
      topology:
        folder: /MyDatacenterName/vm/MyFolderName

Update Oct 11, 2023: Changed the install-config.yaml snippet that instructs openshift-install to create VMs in a specific, manually created, folder.

@WuTangDangie
Copy link

Installing worker nodes on version 4.12.32 required Read-Only permission to the Distributed Virtual Switch.

Error:
6m22s Warning FailedCreate machine/<worker_name> <worker_name>: reconciler failed to Create machine: error getting network specs: unable to create new ethernet card backing info for network "<network_name>": failed to create EthernetCardBackingInfo for DistributedVirtualPortgroup:dvportgroup-2485984: System.Read privilege required for config.distributedVirtualSwitch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment