Hi Mark,

There are two as-yet-not-merged Pull Requests that tackle renaming windows 
hosts:

https://github.com/ansible/ansible-modules-extras/pull/213 and 
https://github.com/ansible/ansible-modules-extras/pull/33

Would you able to test them out and see what works and make most sense to 
use?

Changing hostnames obviously has an effect on inventory so, depending on 
what you need to do to a machine created from a template before you rename 
it, you may or may not need to have a sort 'new machines' inventory so you 
can run ansible modules against the newly-created-but-not-yet renamed vms.

I would test myself but I am waiting for a vsphere upgrade before I can get 
as far as you have done.

I don't know if you are planning on putting your created-from-template VMs 
onto a domain but I have some prototype code which can use Active Directory 
as a source of dynamic inventory.  If you are interested let me know and 
I'll share the code.  I haven't created a PR yet as I haven't worked out a 
really good way to secure the credentials needed for querying the domain 
controller, but that may or may not matter depending on your security 
requirements.

All the best,

Jon

On Friday, July 1, 2016 at 4:21:09 PM UTC+1, Mark Matthews wrote:
>
> 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" 
>
> $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
>
>  
>
>  
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/1a19c99e-569e-4fd2-b664-3c3e32cbe83d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to