Hi
I have a playbook that creates multiple VM’s in VMware (see below).
When the VM’s have all been created they have the same server name as the template. So I have 20 new VM’s all with the same OS name.
I want the OS server name to be changed to the same name as the Vm host name that the Ansible playbook gives it when it runs. Is there any way of doing this? It’s obviously pointless creating multiple servers all with the same name.
I can easily do this using VMware PowerCLI and associating a VMware Customization Spec to the VM template:
$esxName = "172.22.22.22"
$template = "WIN2012R2-TEMPLATE"
$datastore = "IE-VMFS5-32"
$newVmList = "DR-EA05", "DR-EA06"
$custSpec = "Spectest"
$location = "Alphanew"
$taskTab = @{}
# Create all the VMs specified in $newVmList
foreach($Name in $newVmList) {
$taskTab[(New-VM -Name $Name -VMHost (Get-VMHost -Name $esxName) -Template $template -Datastore $datastore -OSCustomizationSpec $custSpec -Location $location -RunAsync).Id] = $Name
}
Is there anyway of adding a VMware Customization spec to the Ansible playbook? Or any other way than you can think of that I can use to set the new VM’s server name?
Playbook:
---
- hosts: 127.0.0.1
connection: local
user: root
sudo: false
gather_facts: false
serial: 1
vars:
vcenter_hostname: UK-VC01.company.local
esxhost: 172.22.22.22
datastore: UK-ESX36
username: markm
password: 11111111111
vmtemplate: WIN2K12R2-TEMPLATE
network: Web Servers
vmcluster: UK-CLUSTER
folder: Utilities
notes: Created by Ansible
tasks:
- name: Create VM from template
vsphere_guest:
vcenter_hostname: "{{ vcenter_hostname }}"
username: "{{ username }}"
password: "{{ password }}"
guest: "{{ item }}"
vm_extra_config:
notes: "{{ notes }}"
folder: "{{ folder }}"
from_template: yes
template_src: "{{ vmtemplate }}"
cluster: "{{ vmcluster }}"
resource_pool: "/Resources"
esxi:
datacenter: UK
hostname: "{{ esxhost }}"
with_items:
- ans_testserver01
- ans_testserver02
Hi
I have a playbook that creates multiple VM’s in VMware (see below).
When the VM’s have all been created they have the same server name as the template. So I have 20 new VM’s all with the same OS name.
I want the OS server name to be changed to the same name as the Vm host name that the Ansible playbook gives it when it runs. Is there any way of doing this? It’s obviously pointless creating multiple servers all with the same name.
I can easily do this using VMware PowerCLI and associating a VMware Customization Spec to the VM template:
$esxName = "172.22.22.22"
$template = "WIN2012R2-MTEMPLATE"