Hi Jon 

I am still really battling with this...

I have changed the playbook to the following:

Playbook:
---
 - hosts: 127.0.0.1
   connection: local
   user: root
   sudo: false
   gather_facts: false
   serial: 1
   vars:
     vcenter_hostname: UK.server.local
     esxhost: xxx.xxx.xxx.xxx
     datastore: UK1
     network: Web
     vmcluster: UKCLUSTER
     serverlist: files/hostnames 
     folder: Utilities
     notes: Created by Ansible

   tasks:
    - name: Create VM from template
      vsphere_guest:
        vcenter_hostname: "{{ vcenter_hostname }}"
        username: "{{ username }}"
        password: "{{ password }}"
        guest: "{{ list }}"
        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: "{{ serverlist }}"


As I mentioned, I have created a file called 'hostnames' which is located 
in a sub directory (files) where the playbook is, and have included the vm 
names in that file.

As you can see I have said that the variable {{ serverlist }} needs to look 
at the file path files/hostnames. Is that correct.

And in that hostnames file is the list of servers.
I have then put the variable "{{ list }}" for the guest option, but how 
does Ansible know to create multiple VM's with those servers names?

Im starting to think that this insnt possible and Ansible is not able to do 
this without having to repeat the playbook over and over again for as many 
VM's as you want?

Cheers
Mark


On Thursday, March 10, 2016 at 5:00:18 PM UTC, Mark Matthews wrote:
>
> Hi
>
> Is it at all possible to create multiple VMware VM's using an Ansible 
> playbook? Giving each VM a unique name (server1, server2, server3, server4)?
>
> I can see anyway of doing this using the following playbooks, as it keeps 
> failing?
>
> ---
>  - hosts: 127.0.0.1
>    connection: local
>    user: root
>    sudo: false
>    gather_facts: false
>    serial: 1
>    vars:
>      vcenter_hostname: UK.server.local
>      esxhost: xxx.xxx.xxx.xxx
>      datastore: UK1
>      network: Web
>      vmcluster: UKCLUSTER
>      guest_name: server1, server2, server3, server4 
>      folder: Utilities
>      notes: Created by Ansible
>
>    tasks:
>     - name: Create VM from template
>       vsphere_guest:
>         vcenter_hostname: "{{ vcenter_hostname }}"
>         username: "{{ username }}"
>         password: "{{ password }}"
>         guest: "{{ guest_name }}"
>         vm_extra_config:
>           notes: "{{ notes }}"
>           folder: "{{ folder }}"
>         from_template: yes
>         template_src: "{{ vmtemplate }}"
>         cluster: "{{ vmcluster  }}"
>         resource_pool: "/Resources"
>         
>         esxi:
>           datacenter: UK
>           hostname: "{{ esxhost }}"
>
> Any ideas or suggestions would be really appreciated.
>
> Cheers
>
>

-- 
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/5e6ea70a-62c6-4cbb-91ec-5d06bf83e91b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to