vmware / PowerCLI-Example-Scripts

http://blogs.vmware.com/powercli
Other
764 stars 608 forks source link

Non-persistent OS customization spec for Linux does not copy extension data - customization fails #623

Closed davdmrgn closed 1 year ago

davdmrgn commented 1 year ago

Describe the bug

Deploying a VM where a static IP is required while using an OS customization specification requires a copy of an existing OS customization spec, typically non-persistent as it is only used to deploy that virtual machine.

When creating a new OS customization spec from an existing one, data stored for Linux servers (time zone, scripts, etc) are buried under extensiondata in a separate, non-writable object and is not copied to the new non-persistent OS customization spec.

Work-around

Create a persistent customization spec for your deployment, and manually delete it afterwards. Creating a new persistent customization spec from an existing one copies the extension data required for Linux customization.

Reproduction steps

  1. Create a persistent Linux OS customization specification, with data in the script field
  2. Copy that Linux OS customization specification to a non-persistent customization specification
  3. View the extension data of both
  4. The non-persistent OS customization spec does not have extension data for Linux, causing customization scripts to not run ...

Expected behavior

Creating a non-persistent OS customization spec should copy all data required for Linux.

Furthermore, there are fields available in the primary object - these data could be stored there to ensure they're copied, rather than having it buried in another object under extension data.

Additional context

Persistent OS Customization Spec

Get-OSCustomizationSpec -Name Linux -Server *** | fl
<#
Name                  : Linux
Type                  : Persistent
ServerId              : ********
Server                : ********
LastUpdate            : 9/15/2023 9:14:15 PM
DomainAdminUsername   :
DomainUsername        :
Description           :
AutoLogonCount        :
ChangeSid             :
DeleteAccounts        :
DnsServer             : ********
DnsSuffix             : ********
Domain                : ********
FullName              :
GuiRunOnce            :
NamingPrefix          :
NamingScheme          : Vm
OrgName               :
OSType                : Linux
ProductKey            :
TimeZone              :
Workgroup             :
LicenseMode           :
LicenseMaxConnections :
EncryptionKey         :
CustomizationScript   :
ExtensionData         : VMware.Vim.CustomizationSpecItem
Id                    : Linux
Uid                   : ********
AdminPassword         :
DomainAdminPassword   :
DomainPassword        :
#>

Extension Data

(Get-OSCustomizationSpec -Name Linux -Server ***).ExtensionData.Spec.Identity
<#
HostName   : VMware.Vim.CustomizationVirtualMachineName
Domain     : ********
TimeZone   : America/New_York
HwClockUTC : False
ScriptText : #!/bin/sh
             /tmp/Linux-Post.sh
#>

Non-Persistent Copy

Notice the ExtensionData field when viewing the object.

Get-OSCustomizationSpec -Name Linux -Server *** | New-OSCustomizationSpec -Type:NonPersistent
<#
Name                                         Description Type          OSType  LastUpdate           Server
----                                         ----------- ----          ------  ----------           ------
Linux                                                    NonPersistent Linux
#>

Get-OSCustomizationSpec -Name Linux -Server ***
<#
Name                                         Description Type          OSType  LastUpdate           Server
----                                         ----------- ----          ------  ----------           ------
Linux                                                    Persistent    Linux   9/15/2023 9:14:15 PM ********
Linux                                                    NonPersistent Linux
#>

Get-OSCustomizationSpec -Name Linux -Server *** -Type:NonPersistent | fl
<#
Name                  : Linux
Type                  : NonPersistent
ServerId              : /Local=/
Server                :
LastUpdate            :
DomainAdminUsername   :
DomainUsername        :
Description           :
AutoLogonCount        :
ChangeSid             :
DeleteAccounts        :
DnsServer             : ********
DnsSuffix             : ********
Domain                : ********
FullName              :
GuiRunOnce            :
NamingPrefix          :
NamingScheme          : Vm
OrgName               :
OSType                : Linux
ProductKey            :
TimeZone              :
Workgroup             :
LicenseMode           :
LicenseMaxConnections :
EncryptionKey         :
CustomizationScript   :
ExtensionData         :
Id                    : 32fa226c-f3dd-436e-abca-c16160c442b3
Uid                   : /Local=/OSCustomizationSpec=32fa226c-f3dd-436e-abca-c16160c442b3/
AdminPassword         :
DomainAdminPassword   :
DomainPassword        :
#>
kamennikolov commented 1 year ago

This looks like a potential issue in PowerCLI. This repo contains some other open-source modules, but the core PowerCLI modules are not open-source and are not located here. If you have issues with PowerCLI you should open an SR as described in the PowerCLI user's guide - https://developer.vmware.com/docs/15315/GUID-0F835722-E667-4177-A8EF-51AB15FA837E.html