VCF 4.0 on VxRail 7.0.000 – rename cluster components with Ansible and PowerShell.

In this post, which is third of a number of posts on VCF 4 on VxRail, we wil rename default VxRail cluster components names before VCF bring-up. Once the VxRail cluster is installed and configured, a default names are assigned to the Datacenter, cluster, vDS, portgroups and vSAN Datastore in the vCenter Server inventory.

Once you try to validate VCF data provided in the configuration file you will get error i.e. like this: ‘No matching cluster found with prefix clusterName in vCenter’

Of course it’s possible to change these names to meet your standard (naming convention), BUT you should do that BEFORE VCF installation!!!

I think all vars should be clear and obvious so let switch to script. As this post tittle suggests, we will use PowerShell script (renameVxrailClusterObjects.ps1) to rename above components.

	[Parameter(Mandatory=$true)] $vcenterServer,
	[Parameter(Mandatory=$true)] $vcenterUser,
	[Parameter(Mandatory=$true)] $vcenterPassword,
	[Parameter(Mandatory=$true)] $NewDatacenterName,
	[Parameter(Mandatory=$true)] $NewClusterName,
	[Parameter(Mandatory=$true)] $NewVdsName,
	[Parameter(Mandatory=$true)] $NewVsanName
Import-Module VMware.PowerCLI -Force

#Ignore certificate errors
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false

#Connect to vCenter Server
Connect-VIServer $vcenterServer -User $vcenterUser -Password $vcenterPassword -Force

# Set Cluster Name
$defaultClusterName = (Get-Cluster).name
$clusterId = (Get-Cluster -name "$defaultClusterName").id
$setClusterName = "$NewClusterName"
$newClusterName = Get-View -Id "$clusterId"

#Set Datacenter Name
$defaultDatacentername = (Get-Datacenter).name
$DatacenterId = (Get-Datacenter -name "$defaultDatacentername").id
$setDatacenterName = "$NewDatacenterName"
$newDatacenterName = Get-View -Id "$DatacenterId"

#Set VDS Name
$defaultVdsName = (Get-VDSwitch).name
$VdsId = (Get-VDSwitch -name "$defaultVdsName").id
$setVdsName = "$NewVdsName"
$newVdsName = Get-View -Id "$VdsId"

#Set vSAN Datastore Name
$defaultVsanDatastoreName = get-datastore -name "VxRail-Virtual-SAN-Datastore*"
$vsanId = $
$setVsanName = "$NewVsanName"
$NewVsanName = Get-View -Id "$vsanId"

and of course Ansible task to trigger our PS script:

- name: Rename VxRail cluster components 
  command: pwsh "{{ role_path }}"/files/renameVxrailClusterObjects.ps1 -vcenterServer "{{ vCenterHostname }}" -vcenterUser "{{ vCenterUsername }}" -vcenterPassword "{{ vCenterPassword }}" -NewDatacenterName "{{ newDatacenterName }}" -NewClusterName "{{ newClusterName }}" -NewVdsName "{{ newVdsName }}" -NewVsanName "{{ newVsanDatastoreName }}"
  changed_when: false
  register: psResult1

And that’s it:) Any questions? suggestions? just ping me.