VMware Cloud Community
BaluVirigineni
Enthusiast
Enthusiast
Jump to solution

While trying to deploy Linux VM from template using PowerCLI , during customization it giving error as "you must not provide dns when you create NIC mapping for customization with type "Linux"

While trying to deploy Linux VM from template using PowerCLI , during customization it giving error as "you must not provide dns when you create NIC mapping for customization with type "Linux" 

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

See my answer to the other thread where you posted the same question.


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

View solution in original post

Reply
0 Kudos
23 Replies
nielse
Expert
Expert
Jump to solution

DNS is only required on Windows servers, this is not needed for Linux deployments as the DNS servers are defined within the template under /etc/resolv.conf.

@nielsengelen - http://foonet.be - VCP4/5
BaluVirigineni
Enthusiast
Enthusiast
Jump to solution

Hi Nielse,

Thanks for your response..I have removed the DNS entry part from the PowerCLI Script and ran the script still its giving the below error .. the script should take IP Address DG details from the excel file but somehow its failing.. please chcek the same.

Below is my PCLI Script:

$vms = Import-CSV C:\Users\sg0217865\Desktop\NewVMs.csv

foreach ($vm in $vms){

      $Template = Get-Template $vm.template

      $VMHost = Get-VMHost $vm.host

      $Datastore = Get-Datastore $vm.datastore

      $OSCustomization = Get-OSCustomizationSpec LinuxTemplateforPCLI | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $_.IP Address -SubnetMask $_.Subnet -DefaultGateway $_.Gateway

      New-VM -Name $vm.name -OSCustomizationSpec $OSCustomization `

        -Template $Template -VMHost $VMHost -Datastore $Datastore -RunAsync

}

Error1.png

Reply
0 Kudos
nielse
Expert
Expert
Jump to solution

Is that the correct screenshot? As it complains about DNS but I can't see it in your code.

@nielsengelen - http://foonet.be - VCP4/5
Reply
0 Kudos
BaluVirigineni
Enthusiast
Enthusiast
Jump to solution

Yes Nielse.. its the correct screenshot..I didnt understand why its giving DNS error eventhough the dns entry is removed from the Script.

Reply
0 Kudos
nielse
Expert
Expert
Jump to solution

Did you close the old connection to the vCenter and ran the script again? The customization should work without a problem

@nielsengelen - http://foonet.be - VCP4/5
Reply
0 Kudos
BaluVirigineni
Enthusiast
Enthusiast
Jump to solution

I closed the old connection and ran the script on new Window..still issue appears.

Can you give me a new script for deploying VMs from Template, and I want the script to take input from Excel file also the Customization for NIC shud be static.

Reply
0 Kudos
drivera01
Enthusiast
Enthusiast
Jump to solution

Try something like this?

I had a hard time with this piece for setting up my provisioning script.. it took some time but I finally got it. I have been using it for a while now.

Mine also is for provisioning linux vm's.

hope it helps

David

Get-OSCustomizationSpec -Name temp | Remove-OSCustomizationSpec -Confirm:$false

     Get-OSCustomizationSpec -Name custemple |  New-OSCustomizationSpec -Name temp -Type NonPersistent

        Get-OSCustomizationSpec -Name temp | Set-OSCustomizationSpec -Name temp  -DnsServer $dns -DnsSuffix $dnsSuffix -Domain $domainname

    Get-OSCustomizationSpec -Name temp | Get-OSCustomizationNicMapping |Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $ip -SubnetMask $subnet -DefaultGateway $gw

Reply
0 Kudos
nielse
Expert
Expert
Jump to solution

Can you try the following (not tested, based on old script i have)

$vms = Import-CSV C:\Users\sg0217865\Desktop\NewVMs.csv

foreach ($vm in $vms){

    $Template = Get-Template $vm.template

    $VMHost = Get-VMHost $vm.host

    $Datastore = Get-Datastore $vm.datastore

    Get-OSCustomizationSpec LinuxTemplateforPCLI | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIp -IpAddress $_.IP Address -SubnetMask $_.Subnet -DefaultGateway $_.Gateway | Out-Null

    New-VM -Name $vm.name -Template $Template -Datastore $Datastore -VMHost $VMHost -DiskStorageFormat Thin | Set-VM -OSCustomizationSpec $OSCustomization -Confirm:$false

}

@nielsengelen - http://foonet.be - VCP4/5
Reply
0 Kudos
BaluVirigineni
Enthusiast
Enthusiast
Jump to solution

Ok will try the above script and let u know status..But I dont see any difference between mine and the above script..

Reply
0 Kudos
BaluVirigineni
Enthusiast
Enthusiast
Jump to solution

Not worked it still giving the same error..David Shall I use the above portion in Guest Customization Part..?

Reply
0 Kudos
BaluVirigineni
Enthusiast
Enthusiast
Jump to solution

David can you give me the complte script to deploy VMs from template..

Reply
0 Kudos
drivera01
Enthusiast
Enthusiast
Jump to solution

This is the core of my script..for making the vms from a template.. My whole provisioning script does alot of other things exclusive to my environment.. So this is the piece I can share...

I

please use only as a template on making your script work...  if you chose.

I am by far not a powercli guru like all the others who help out in this forum.. Thanks to great people in this forum, I was able to build exactly what I needed for my environment.

you should be able to understand the variables by the names..

hope it helps...

David

HINT: notice "custemple"  I created this PERSISTENT spec on vcenter. It is a one time creation that I just reference in order to build my non-persistent spec called "temp"...

"temp" is the meat and potatoes of it all...

Get-OSCustomizationSpec -Name temp | Remove-OSCustomizationSpec -Confirm:$false

     Get-OSCustomizationSpec -Name custemple |  New-OSCustomizationSpec -Name temp -Type NonPersistent

        Get-OSCustomizationSpec -Name temp | Set-OSCustomizationSpec -Name temp  -DnsServer $dns -DnsSuffix $dnsSuffix -Domain $domainname

    Get-OSCustomizationSpec -Name temp | Get-OSCustomizationNicMapping |Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $ip -SubnetMask $subnet -DefaultGateway $gw

New-VM -Name $displayname  -OSCustomizationSpec temp -Template ( Get-template $template ) -VMHost $ESXHost -Datastore $datastore

Get-VM -name $displayname  | Get-NetworkAdapter | where { $_.Name -eq "Network Adapter 1" } | Set-NetworkAdapter -NetworkName $network  -Confirm:$false

      Get-vm -Name $displayname | Set-VM  -MemoryGB $mem  -Confirm:$false

       $vm = Get-VM -Name $displayname

          $vm | Set-VM -NumCpu ( $cpu ) -Confirm:$false

           $vm | New-HardDisk -CapacityGB $HDD1

            if ($HDD2 -ne 0) {

             $vm | New-HardDisk -CapacityGB $HDD2

                             }

          $vm | Set-VM -Notes $Note  -Confirm:$false

                     Move-VM -VM $displayname -Destination (Get-Folder -Name $folder) -Confirm:$false

                  Start-VM -VM $displayname

Reply
0 Kudos
BaluVirigineni
Enthusiast
Enthusiast
Jump to solution

My bad the above one too not working in my Env..

Reply
0 Kudos
nielse
Expert
Expert
Jump to solution

Can you give the complete script you use as well as the error?

@nielsengelen - http://foonet.be - VCP4/5
Reply
0 Kudos
BaluVirigineni
Enthusiast
Enthusiast
Jump to solution

When I use the below PowerCLI script to deploy VMs from Template I am getting the below error.

pastedImage_0.png

Here is the PowerCLI script:

Import-Csv "C:\Users\sg0217865\Desktop\NewVMs.csv" -UseCulture | %{

    Get-OSCustomizationSpec $_.Customization | Get-OSCustomizationNicMapping | `

    Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $_.ip `

        -SubnetMask $_.Subnet -DefaultGateway $_.gw

    $vm=New-VM -Name $_.Name -Template $_.Template -Host $_.Host `

        -Datastore $_.Datastore -Confirm:$false -RunAsync | Set-OSCustomizationSpec -OSCustomizationSpec $_.Customization

}

Reply
0 Kudos
BaluVirigineni
Enthusiast
Enthusiast
Jump to solution

When I use the below PowerCLI script to deploy VMs from Template I am getting the below error.

29078_29078.pngpastedImage_0.png

Here is the Complete PowerCLI script:

Import-Csv "C:\Users\sg0217865\Desktop\NewVMs.csv" -UseCulture | %{

    Get-OSCustomizationSpec $_.Customization | Get-OSCustomizationNicMapping | `

    Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $_.ip `

        -SubnetMask $_.Subnet -DefaultGateway $_.gw

    $vm=New-VM -Name $_.Name -Template $_.Template -Host $_.Host `

        -Datastore $_.Datastore -Confirm:$false -RunAsync | Set-OSCustomizationSpec -OSCustomizationSpec $_.Customization

}

Reply
0 Kudos
nielse
Expert
Expert
Jump to solution

Can you change the following line:

$vm=New-VM -Name $_.Name -Template $_.Template -Host $_.Host `

        -Datastore $_.Datastore -Confirm:$false -RunAsync | Set-OSCustomizationSpec -OSCustomizationSpec $_.Customization

into:

$vm=New-VM -Name $_.Name -Template $_.Template -Host $_.Host `

        -Datastore $_.Datastore -Confirm:$false -RunAsync | Set-VM -OSCustomizationSpec $_.Customization

@nielsengelen - http://foonet.be - VCP4/5
LucD
Leadership
Leadership
Jump to solution

See my answer to the other thread where you posted the same question.


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

Reply
0 Kudos
AROS77
Contributor
Contributor
Jump to solution

The fact that DNS is not mandatory is not an answer. Through the WEB interface you can set the DNS of Customization Specs. Here is about what you CAN or CANNOT do. And it would be nice to be able to do the same things either through CLI or WEB interface.

Reply
0 Kudos