VMware Cloud Community
Sivaramsharmar
Enthusiast
Enthusiast

Clone Template to Multiple Clusters in Multiple DataCenters

Hi All,

We have multiple DataCenter with atleast 5 Clusters each.

When ever we are updating templates with security patches etc., we need to clone the same template across all the clusters.

We have some naming structure, before cloning we need to cross check with naming convention and initiate the clone and which is a tedious task.

Ex:

Datacenter1 -> Cluster1

                     -> Cluster2

                     -> Cluster3

                     -> Cluster4

                     -> Cluster5

                     -> Cluster6

Cluster1 -> Win_Tmpl_V1 -> Patches and other stuff is updated in this template located in cluster1

Now we would like to deploy the same template across all the clusters as below.

Cluster2 -> Win_TMPL_V1_1

Cluster3 -> Win_TMPL_V1_2

Cluster4 -> Win_TMPL_V1_3

Cluster5 -> Win_TMPL_V1_4

Cluster6 -> Win_TMPL_V1_5

So before cloning it has to check whether this template is available or not and accordingly it has to increment the number and clone for entire clusters across datacenters.

Please do let us know is there any way to automate this thing.

Regards,

RAM

Reply
0 Kudos
7 Replies
T180985
Expert
Expert

It doesn't directly answer your question BUT.... If the template is exactly the same on every cluster with the only difference being the name, why not just use Content libraries accessible to all clusters so you only have to update the file once without having to manually clone it every time?

Please mark helpful or correct if my answer resolved your issue. How to post effectively on VMTN https://communities.vmware.com/people/daphnissov/blog/2018/12/05/how-to-ask-for-help-on-tech-forums
Reply
0 Kudos
Sivaramsharmar
Enthusiast
Enthusiast

It has been already proposed to customer, but customer wants to go through the process as I mentioned.

Reply
0 Kudos
LucD
Leadership
Leadership

Yes, that can be automated.
But a few questions first.

  • I assume that the patched Template name is provided to script?
  • Does the Template need to replicated to a specific set of clusters or all clusters?
  • Is the suffix on the Template a sequential number?
  • Is the suffix number linked to the Cluster number in any way? Or does the replication need to happen in Clustername alphabetical order?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Sivaramsharmar
Enthusiast
Enthusiast

1) Template name is provided in the Script

2) Template should be replicated to all Clusters across the Datacenters in a single vCenter

3) Win_TMPL_V1 will be the template name, While cloning to other clusters it has to be Win_TMPL_V1_1. It means only the last number should be added up and it should not be like Win_TMPL_V2

4) Suffix number is not linked to cluster any way. We need to ensure same template is rolled out in all the clusters. There is no specific requirement that the replication has to be in alphabetical sequential.

Reply
0 Kudos
LucD
Leadership
Leadership

One more question, a Template is not linked to a Cluster but to a Datacenter.

To make sure, you want multiple Templates in a Datacenter, one for each Cluster in that Datacenter?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Sivaramsharmar
Enthusiast
Enthusiast

Yes Luc, Correct

Reply
0 Kudos
LucD
Leadership
Leadership

There is a known issue with the New-Template cmdlet, that's why I reverted to the API method.

Try something like this

$srcName = 'Win_TMPL_V1_1'

$template = Get-Template -Name $srcName

$index = 1

Get-Datacenter -PipelineVariable dc | Get-Cluster -PipelineVariable cluster |

ForEach-Object -Process {

    $spec = New-Object VMware.Vim.VirtualMachineCloneSpec

    $spec.Location = New-Object VMware.Vim.VirtualMachineRelocateSpec

    $spec.Location.Datastore = (Get-Datastore -RelatedObject $cluster |

        where{$_.ExtensionData.Summary.MultipleHostAccess} | Get-Random).ExtensionData.MoRef

    $spec.Location.Folder = $dc.ExtensionData.VmFolder

    $spec.Location.Host = $cluster.ExtensionData.Host | Get-Random

    $spec.Location.Pool = $cluster.ExtensionData.ResourcePool


    $template.ExtensionData.CloneVM($dc.ExtensionData.VMFolder, "$($srcName)_$($index)", $spec)


    $index++

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos