Hi Mark,

I think you are getting pretty close.

I can see a couple of issues in your playbook which might unstick you...

First the with_items needs to go right at the end of all of the parameters 
for the vsphere guest module - at the moment you have the exsi parameter 
after the with_items.

Also there's a missing double quote at the end of the with items line:

with_items: "{{ serverlist }}

should probably be:

with_items: "{{ serverlist }}"


The other thing is actually getting your file containing the serverlist 
variable loaded into Ansible.  There's at least a couple of ways of doing 
this - either do an include_vars: file_containing_vars.yml at the top of 
your playbook, or you can pass in the contents of a yaml file on the 
command line using -e @/path/to/yaml/file.yml.  Not sure what is going to 
suit your usage best 

Hope this is enough to get you unstuck.

Jon

On Friday, 11 March 2016 13:23:19 UTC, Mark Matthews wrote:
>
> Hi Jon
>
> Thanks so much for the response.
>
> I was looking at that and have ried a few things without success.
>
> Are you able to see if im on the right track here?
> I have create 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:
>
> ---
> serverlist:
>   - server1
>   - server2
>
> I have then added the 'with_items' and variable 'serverlist'. But i think 
> I may be getting a bit confused through?
> Im I completely off track here?
>
>
> 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"
>        with_items: "{{ serverlist }}
>         
>         esxi:
>           datacenter: UK
>           hostname: "{{ esxhost }}"
>
>
>
>
> 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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/b8613054-4ff1-48dc-ae69-cfa619531043%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to