vSpehere与terraform VM自定义失败,网络未连接

时间:2018-05-23 07:26:14

标签: vmware terraform

当我尝试自定义Windows VM的网络接口后,发生terraform错误时,VM仍在运行,没有连接任何NIC。

版本 Terraform = v0.11.7 vSphere版本= 6.7.0,8169922 Windows 2012 R2的机器克隆

到目前为止的调查; 在vCenter和VM设置中,“网络适配器1”未标记为在加电时启动。就好像在定制过程中这种设置丢失一样,导致VM缺乏通信。如果我关闭服务器电源,则选中该框以在启动时连接NIC,然后当服务器重新联机时,其网络配置正确,如定制部分中所定义。我还将自定义调整到最低限度,但仍然会遇到同样的错误。

terraform控制台输出

Error dumps below.

    Error: Error applying plan:


    1 error(s) occurred:


    * vsphere_virtual_machine.Clone: 1 error(s) occurred:


    * vsphere_virtual_machine.Clone:
    Virtual machine customization failed on "/Data Center/vm/AIS1EM-SAMSON":


    An error occurred while customizing VM AIS1EM-SAMSON. For details reference the log file C:/Windows/TEMP/vmware-imc/guestcust.log in the guest OS.

来自VM的自定义文件日志

    [2018-05-22T17:35:13:                              :   INFO] GuestCustUtil invoked.
[2018-05-22T17:35:13:                              :   INFO] Params: customize -sealparam "/quiet /generalize /oobe /reboot" -nics 4000 -schedulenativeunobfusc
[2018-05-22T17:35:13:                              :  DEBUG] Registry value 'CustomRescheduleFlags' is not set. Returning default value: 0
[2018-05-22T17:35:13:                              :   INFO] Checking for Windows Sysprep Respecialize operation.
[2018-05-22T17:35:13:                              :  DEBUG] Sysprep process is not running.
[2018-05-22T17:35:13:                              :   INFO] Windows Sysprep Respecialize operation was not detected.
[2018-05-22T17:35:13:                 GuestCustUtil:  DEBUG] Deleting status marker file C:/Windows/.post-gc-status
[2018-05-22T17:35:13:                 GuestCustUtil:  DEBUG] Status marker file C:/Windows/.post-gc-status doesn't exist
[2018-05-22T17:35:13:                              :   INFO] Extended customization is not enabled!
[2018-05-22T17:35:13:                              :  DEBUG] HandleCustomizationStarted
[2018-05-22T17:35:13:                              :  DEBUG] Customization in progress set to 1 at 2018-May-22 17:35:13
[2018-05-22T17:35:13:                              :  DEBUG] GOScPostRebootStatus feature is enabled
[2018-05-22T17:35:13:                 GuestCustUtil:  DEBUG] SetVmxProperty: key-'guestinfo.gc.notification', value-'Started'
[2018-05-22T17:35:13:     WindowsOsAbstractionLayer:   INFO] VMware tools installation path=C:\Program Files\VMware\VMware Tools\
[2018-05-22T17:35:13:     WindowsOsAbstractionLayer:   INFO] Executing command: '"C:\Program Files\VMware\VMware Tools\vmtoolsd.exe" --cmd "info-set guestinfo.gc.notification Started"'
[2018-05-22T17:35:13:     WindowsOsAbstractionLayer:   INFO] Command execution succeeded, output: '

'
[2018-05-22T17:35:13:                              :  DEBUG] Rpci: Sending request='deployPkg.update.state 4 0 C:/Windows/TEMP/vmware-imc/guestcust.log'

[2018-05-22T17:35:13:                              :  DEBUG] Rpci: Sent request='deployPkg.update.state 4 0 C:/Windows/TEMP/vmware-imc/guestcust.log', reply='', len=0, status=1

[2018-05-22T17:35:13:                              :  DEBUG] Temporary sysprep dir path: C:\sysprep
[2018-05-22T17:35:13:                              :  DEBUG] Copying file/directory from 'sysprep' to 'C:\sysprep'
[2018-05-22T17:35:13:                              :   INFO] Sysprep File is C:\Windows\Panther\unattend.xml
[2018-05-22T17:35:13:                              :   INFO] Password unobfuscation in progress
[2018-05-22T17:35:13:                              :  DEBUG] Decrypting passwords
[2018-05-22T17:35:13:                              :  DEBUG] Password found and decrypted for <AdministratorPassword><EncryptedValue>
[2018-05-22T17:35:13:                              :  DEBUG] preTag <Credentials> not found
[2018-05-22T17:35:13:                              :  DEBUG] preTag <Password> not found
[2018-05-22T17:35:13:                              :  DEBUG] Tag  -de  not found after <RunSynchronousCommand
[2018-05-22T17:35:13:                              :   INFO] Password unobfuscation successful
[2018-05-22T17:35:14:                              :  DEBUG] select * from win32_networkadapter where Manufacturer != 'Microsoft' and ServiceName != 'VMnetAdapter' and  manufacturer is not null and MACAddress is not null
[2018-05-22T17:35:14:                              :  DEBUG] Found 0 objects. Pointer 0. return code -2147217398(0x8004100a)
[2018-05-22T17:35:14:                              :  ERROR] WinMgmt : 
[2018-05-22T17:35:14:                              :  DEBUG] HandleCustomizationFailed
[2018-05-22T17:35:14:                              :  DEBUG] Customization in progress set to 0 at 2018-May-22 17:35:14
[2018-05-22T17:35:14:                              :   INFO] Cleaning up obfuscation details from registry
[2018-05-22T17:35:14:                 GuestCustUtil:  DEBUG] Status marker file C:/Windows/.post-gc-status doesn't exist
[2018-05-22T17:35:14:                              :  DEBUG] GOScPostRebootStatus feature is enabled
[2018-05-22T17:35:14:                 GuestCustUtil:  DEBUG] SetVmxProperty: key-'guestinfo.gc.notification', value-'WinMgmt : '
[2018-05-22T17:35:14:     WindowsOsAbstractionLayer:   INFO] VMware tools installation path=C:\Program Files\VMware\VMware Tools\
[2018-05-22T17:35:14:     WindowsOsAbstractionLayer:   INFO] Executing command: '"C:\Program Files\VMware\VMware Tools\vmtoolsd.exe" --cmd "info-set guestinfo.gc.notification WinMgmt : "'
[2018-05-22T17:35:14:     WindowsOsAbstractionLayer:   INFO] Command execution succeeded, output: '

'
[2018-05-22T17:35:14:                              :  DEBUG] Rpci: Sending request='deployPkg.update.state 4 100 C:/Windows/TEMP/vmware-imc/guestcust.log@WinMgmt : '

[2018-05-22T17:35:14:                              :  DEBUG] Rpci: Sent request='deployPkg.update.state 4 100 C:/Windows/TEMP/vmware-imc/guestcust.log@WinMgmt : ', reply='', len=0, status=1

[2018-05-22T17:35:14:                              :   INFO] GuestCustUtil exiting.

[2018-05-22T17:35:23:                              :   INFO] GuestCustUtil invoked.
[2018-05-22T17:35:23:                              :   INFO] Params: restoreMountedDevices 
[2018-05-22T17:35:23:                              :  DEBUG] Registry value 'CustomRescheduleFlags' is not set. Returning default value: 0
[2018-05-22T17:35:23:                              :   INFO] Checking for Windows Sysprep Respecialize operation.
[2018-05-22T17:35:23:                              :  DEBUG] Sysprep process is not running.
[2018-05-22T17:35:23:                              :   INFO] Windows Sysprep Respecialize operation was not detected.
[2018-05-22T17:35:23: SysprepDriveLettersWorkaround:  DEBUG] Restoring HKLM MountedDevices to fix sysprep issue
[2018-05-22T17:35:23:                              :  DEBUG] Enabling SE_RESTORE_NAME privilege
[2018-05-22T17:35:23:                              :  DEBUG] Retrieving process access token for SeRestorePrivilege
[2018-05-22T17:35:23:                              :  DEBUG] Getting LUID
[2018-05-22T17:35:23:                              :  DEBUG] Adjusting privileges
[2018-05-22T17:35:23:                              :  DEBUG] Restoring SYSTEM\MountedDevices from C:\sysprep\MountedDevicesBackup
[2018-05-22T17:35:23: SysprepDriveLettersWorkaround:   WARN] Failed to restore MountedDevices: The system cannot find the file specified.

. Ignoring
[2018-05-22T17:35:23:                              :   INFO] GuestCustUtil exiting.

[2018-05-22T17:35:23:                              :   INFO] GuestCustUtil invoked.
[2018-05-22T17:35:23:                              :   INFO] Params: flagComplete 
[2018-05-22T17:35:23:                              :  DEBUG] Registry value 'CustomRescheduleFlags' is not set. Returning default value: 0
[2018-05-22T17:35:23:                              :   INFO] Checking for Windows Sysprep Respecialize operation.
[2018-05-22T17:35:23:                              :  DEBUG] Sysprep process is not running.
[2018-05-22T17:35:23:                              :   INFO] Windows Sysprep Respecialize operation was not detected.
[2018-05-22T17:35:23:                 GuestCustUtil:  DEBUG] Status marker file C:/Windows/.post-gc-status doesn't exist
[2018-05-22T17:35:23:     WindowsOsAbstractionLayer:   INFO] Executing command: 'C:\Windows\system32\schtasks.exe /query /tn "VMware Guest OS Customization Task"'
[2018-05-22T17:35:23:     WindowsOsAbstractionLayer:   WARN] Command execution failed with exit code: 1, output: 'ERROR: The system cannot find the file specified.


'
[2018-05-22T17:35:23:                 GuestCustUtil:  DEBUG] SchedulePostCustomizationActivity: Run Command-'HandleCustomizationCompleted<\|/>'
[2018-05-22T17:35:23:                 GuestCustUtil:   INFO] Scheduling post-customization activity to run after reboot...
[2018-05-22T17:35:23:     WindowsOsAbstractionLayer:   INFO] Executing command: 'C:\Windows\system32\schtasks.exe /query /tn "VMware Guest OS Customization Task"'
[2018-05-22T17:35:23:     WindowsOsAbstractionLayer:   WARN] Command execution failed with exit code: 1, output: 'ERROR: The system cannot find the file specified.


'
[2018-05-22T17:35:23:                 GuestCustUtil:   INFO] Task 'VMware Guest OS Customization Task' exists and will be deleted: false
[2018-05-22T17:35:23:                 GuestCustUtil:  DEBUG] Artifact full path: C:\sysprep\libeay32.dll
[2018-05-22T17:35:23:                 GuestCustUtil:   INFO] Copying C:\sysprep\libeay32.dll to C:\Windows\TEMP\vmw857B.tmp.
[2018-05-22T17:35:23:                              :  DEBUG] Copying file/directory from 'C:\sysprep\libeay32.dll' to 'C:\Windows\TEMP\vmw857B.tmp'
[2018-05-22T17:35:23:                 GuestCustUtil:  DEBUG] Artifact full path: C:\sysprep\ssleay32.dll
[2018-05-22T17:35:23:                 GuestCustUtil:   INFO] Copying C:\sysprep\ssleay32.dll to C:\Windows\TEMP\vmw857B.tmp.
[2018-05-22T17:35:23:                              :  DEBUG] Copying file/directory from 'C:\sysprep\ssleay32.dll' to 'C:\Windows\TEMP\vmw857B.tmp'
[2018-05-22T17:35:23:                 GuestCustUtil:  DEBUG] Artifact full path: C:\sysprep\guestcustutil.exe
[2018-05-22T17:35:23:                 GuestCustUtil:   INFO] Copying C:\sysprep\guestcustutil.exe to C:\Windows\TEMP\vmw857B.tmp.
[2018-05-22T17:35:23:                              :  DEBUG] Copying file/directory from 'C:\sysprep\guestcustutil.exe' to 'C:\Windows\TEMP\vmw857B.tmp'
[2018-05-22T17:35:23:                 GuestCustUtil:  DEBUG] Schedule command: 'C:\Windows\TEMP\vmw857B.tmp\guestcustutil.exe post-run HandleCustomizationCompleted<\|/>'
[2018-05-22T17:35:23:                              :   INFO] Scheduling 'VMware Guest OS Customization Task'
[2018-05-22T17:35:23:                              :  DEBUG] Executing command C:\Windows\system32\schtasks.exe /create /sc ONSTART /rl HIGHEST /np /z /v1 /ru SYSTEM /tr "C:\Windows\TEMP\vmw857B.tmp\guestcustutil.exe post-run HandleCustomizationCompleted<\|/>" /tn "VMware Guest OS Customization Task"
[2018-05-22T17:35:23:                 GuestCustUtil:   INFO] Post-customization activity successfully scheduled.
[2018-05-22T17:35:23:                              :   INFO] GuestCustUtil exiting.

[2018-05-22T17:35:23:                              :   INFO] GuestCustUtil invoked.
[2018-05-22T17:35:23:                              :   INFO] Params: deleteContainingFolder 
[2018-05-22T17:35:23:                              :  DEBUG] Registry value 'CustomRescheduleFlags' is not set. Returning default value: 0
[2018-05-22T17:35:23:                              :   INFO] Checking for Windows Sysprep Respecialize operation.
[2018-05-22T17:35:23:                              :  DEBUG] Sysprep process is not running.
[2018-05-22T17:35:23:                              :   INFO] Windows Sysprep Respecialize operation was not detected.
[2018-05-22T17:35:23:                              :  DEBUG] Deleting "C:\sysprep" ...
[2018-05-22T17:35:23:                              :  DEBUG] Deleted folder "C:\sysprep" .
[2018-05-22T17:35:23:                              :   INFO] GuestCustUtil exiting.

[2018-05-22T17:35:47:                              :   INFO] GuestCustUtil invoked.
[2018-05-22T17:35:47:                              :   INFO] Params: post-run HandleCustomizationCompleted<\|/>
[2018-05-22T17:35:47:                              :  DEBUG] Registry value 'CustomRescheduleFlags' is not set. Returning default value: 0
[2018-05-22T17:35:47:                              :   INFO] Checking for Windows Sysprep Respecialize operation.
[2018-05-22T17:35:47:                              :  DEBUG] Sysprep process is not running.
[2018-05-22T17:35:47:                              :   INFO] Windows Sysprep Respecialize operation was not detected.
[2018-05-22T17:35:47:                              :   INFO] Post-customization run operation: script 'HandleCustomizationCompleted<\|/>'
[2018-05-22T17:35:47:                              :   INFO] post-run HandleCustomizationCompleted
[2018-05-22T17:35:47:                              :   INFO] Deleting post-customization task to avoid re-execution
[2018-05-22T17:35:47:     WindowsOsAbstractionLayer:   INFO] Executing command: 'C:\Windows\system32\schtasks.exe /query /tn "VMware Guest OS Customization Task"'
[2018-05-22T17:35:48:     WindowsOsAbstractionLayer:   INFO] Command execution succeeded, output: '

Folder: \

TaskName                                 Next Run Time          Status         

======================================== ====================== ===============

VMware Guest OS Customization Task       N/A                    Running        

'
[2018-05-22T17:35:48:                 GuestCustUtil:   INFO] Task 'VMware Guest OS Customization Task' exists and will be deleted: true
[2018-05-22T17:35:48:                              :   INFO] Deleting 'VMware Guest OS Customization Task'
[2018-05-22T17:35:48:                              :  DEBUG] Executing command C:\Windows\system32\schtasks.exe /delete /f /tn "VMware Guest OS Customization Task"
[2018-05-22T17:35:48:                              :  DEBUG] HandleCustomizationCompleted
[2018-05-22T17:35:48:                              :  DEBUG] Customization status previously reported, nothing to do
[2018-05-22T17:35:48:                              :  DEBUG] Deleting "C:\Windows\TEMP\vmw857B.tmp" ...
[2018-05-22T17:35:48:                              :  DEBUG] Deleted folder "C:\Windows\TEMP\vmw857B.tmp" .
[2018-05-22T17:35:48:                              :   INFO] GuestCustUtil exiting.

Terraform文件

    /*
    Secrets
*/
provider "vault" {
    address = "https://<removed>:8200"
    token = "<removed>"
}

data "vault_generic_secret" "terraform_secrets" {
    path = "secret/serviceaccounts/default_group"
}

provider "vsphere" {
    user           = "${data.vault_generic_secret.terraform_secrets.data["username"]}@${data.vault_generic_secret.terraform_secrets.data["domain_fqdn"]}"
    password       = "${data.vault_generic_secret.terraform_secrets.data["password"]}"
    vsphere_server = "<removed>"
}

/*
    Variables
*/

#The template to use for creation of new Virtual Machine
variable "Template" { default = "W2012R2_RELEASE" }
#The Resource Pool where the new VM should be created
variable "ResourcePool" { default = "Self-Service" }
#The folder where the new VM should be located
variable "Folder" { default = "AIS1EM" }

/*  
    VM Build
*/
data "vsphere_datacenter" "dc" {
    name = "Data Center"
}

data "vsphere_datastore" "datastore" {
    name          = "vsanDatastore"
    datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

data "vsphere_resource_pool" "pool" {
    name          = "${var.ResourcePool}"
    datacenter_id = "${data.vsphere_datacenter.dc.id}"
}


data "vsphere_distributed_virtual_switch" "dvs" {
    name = "DSwitch0"
    datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

data "vsphere_network" "network" {
    name = "DPortGroup-VM-VLAN59"
    datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

data "vsphere_virtual_machine" "template" {
    name          = "${var.Template}"
    datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

# clone from template
resource "vsphere_virtual_machine" "Clone" {
    name             = "AIS1EM-SAMSON"
    resource_pool_id = "${data.vsphere_resource_pool.pool.id}"
    datastore_id     = "${data.vsphere_datastore.datastore.id}"
    wait_for_guest_net_timeout = false
    num_cpus = 2
    memory   = 4096
    guest_id = "${data.vsphere_virtual_machine.template.guest_id}"
    scsi_type = "${data.vsphere_virtual_machine.template.scsi_type}"

    network_interface {
        network_id = "${data.vsphere_network.network.id}"
        adapter_type = "vmxnet3"
    }

    disk {
        label             = "AIS1EM-SAMSON.vmdk"
        size             = "${data.vsphere_virtual_machine.template.disks.0.size}"
        eagerly_scrub    = "${data.vsphere_virtual_machine.template.disks.0.eagerly_scrub}"
        thin_provisioned = "${data.vsphere_virtual_machine.template.disks.0.thin_provisioned}"
    }

    clone {
            template_uuid = "${data.vsphere_virtual_machine.template.id}"

        customize {

            windows_options {
                computer_name = "AIS1EM-SAMSON"
                #join_domain    = "<removed>"
                #domain_admin_user = "<removed>"
                #domain_admin_password = "<removed>"
                admin_password = "<removed>"
            }

        network_interface {
            ipv4_address = "192.168.59.50"
            ipv4_netmask = "24"
            dns_server_list = ["192.168.72.167", "192.168.72.168"]
            #dns_domain = "emisais.com"
        }

        ipv4_gateway    = "192.168.59.1"

        }

    }
}

output "ID" {
    value = "${data.vsphere_network.network.id}"
}

1 个答案:

答案 0 :(得分:0)

您可能要确保尚未对VM模板进行系统准备。

我曾经遇到过同样的问题,一旦使用了未经sysprep的模板(我相信Terraform会对其进行sysprep),网络适配器将在自定义期间的正确时间进行连接。