Hi Werner,

I'm trying the exact same thing (Ansible 2.1) but Ansible just come back 
with an "ok" and a good return code. The VMs do not get deployed, and I see 
nothing in the vSphere alerts.

TASK [deploy_stack_vm : deploy VMs] 
********************************************
ok: [127.0.0.1] => (item=host1)
ok: [127.0.0.1] => (item=host2)
ok: [127.0.0.1] => (item=host3)

Should this procedure still be valid?

Jeff

On Sunday, May 1, 2016 at 5:44:01 AM UTC-7, Werner Dijkerman wrote:
>
> Hi,
>
> You can make use of the 'with_items' option for all the vmtasks. In the 
> example below I only placed 2 of the tasks:
>
> - name: Depoly from Template
>   vsphere_guest:
>       vcenter_hostname: domain.com
>       username: myuser
>       password: mypassword
>       guest: {{ item.hostname }}
>       from_template: yes
>       template_src: Template6.5-updated
>       cluster: my_cluster
>       validate_certs: no
>       esxi:
>         datacenter: CONNECT-Lab
>         hostname: my_esxi_name
>   with_items:
>     - hostname: host1
>       ip: 192.168.1.11
>     - hostname: host2
>       ip: 192.168.1.12
>
> - name: Power off the VM server
>   vsphere_guest:
>        vcenter_hostname: domain.com
>        username: myuser
>        password: mypassword
>        guest: {{ item.hostname }}
>        cluster: my_cluster
>        validate_certs: no
>        state: powered_off
>        esxi:
>         datacenter: CONNECT-Lab
>         hostname: my_esxi_name
>   with_items:
>     - hostname: host1
>       ip: 192.168.1.11
>     - hostname: host2
>       ip: 192.168.1.12
>
> - name: "Set correct ip"
>   local_action:
>     module: vmware_vm_shell
>     hostname: domain.com
>     username: myuser
>     password: mypassword
>     datacenter: CONNECT-Lab
>     vm_id: {{ item.hostname }}
>     vm_username: root
>     vm_password: password
>     vm_shell: ifconfig
>     vm_shell_args: " eth0 {{ item.ip }}"
>     vm_shell_env:
>       - "PATH=/bin"
>     vm_shell_cwd: "/tmp"
>   with_items:
>     - hostname: host1
>       ip: 192.168.1.11
>     - hostname: host2
>       ip: 192.168.1.12
>
>
> You'll have to update the other tasks to.
>
> The last task in above example is to set the ip to the vm. I haven't 
> tested it yet (As I have an other issue right now) but this is how I would 
> do it.
>
> Have fun! Or drop an reply if you encounter issues.
>
> Kind regards,
> Werner
>
>
> Op maandag 11 april 2016 18:44:42 UTC+2 schreef Ben:
>>
>> I am new in ansible...
>>
>> After create a guest with vsphere_guest i want to be able :
>>
>> 1. how I can create 5 VM and not just 1
>> 2. how can I give all of them IPs and Hostnames 
>>
>> Thanks Ben
>>
>>
>>
>>
>>
>>
>> my playbook:
>>
>> ---
>> - name: Depoly from Template
>>   vsphere_guest:
>>       vcenter_hostname: domain.com
>>       username: myuser
>>       password: mypassword
>>       guest: newvm001
>>       from_template: yes
>>       template_src: Template6.5-updated
>>       cluster: my_cluster
>>       validate_certs: no
>>       esxi:
>>         datacenter: CONNECT-Lab
>>         hostname: my_esxi_name
>> - name: Power off the VM server
>>   vsphere_guest:
>>        vcenter_hostname: domain.com
>>        username: myuser
>>        password: mypassword
>>        guest: newvm001
>>        cluster: my_cluster
>>        validate_certs: no
>>        state: powered_off
>>        esxi:
>>         datacenter: CONNECT-Lab
>>         hostname: my_esxi_name
>> - name: configure the VLAN , CPU and Memory
>>   vsphere_guest:
>>         vcenter_hostname: domain.com
>>         username: myuser
>>         password: mypassword
>>         guest: newvm001
>>         validate_certs: no
>>         state: reconfigured
>>         force: yes
>>         vm_extra_config:
>>           vcpu.hotadd: yes
>>           mem.hotadd:  yes
>>           notes: This is a test VM
>>         vm_disk:
>>           disk1:
>>            size_gb: 60
>>            type: thin
>>            datastore: my_datastorename
>>         vm_nic:
>>          nic1:
>>           type: VMXNET3
>>           network: my_vlan
>>           network_type: standard
>>         vm_hardware:
>>           memory_mb: 4096
>>           num_cpus: 2
>>         esxi:
>>          datacenter: CONNECT-Lab
>>          hostname: my_esxi_name
>> - name: PowerOn the VM Server
>>   vsphere_guest:
>>         vcenter_hostname: domain.com
>>         username: myuser
>>         password: mypassword
>>         guest: newvm001
>>         cluster: my_cluster
>>         validate_certs: no
>>         state: powered_on
>>         esxi:
>>           datacenter: CONNECT-Lab
>>           hostname: my_esxi_name
>>
>> - name: Getting some Facts
>>   vsphere_guest:
>>         vcenter_hostname: domain.com
>>         username: myuser
>>         password: mypassword
>>         guest: newvm001
>>         vmware_guest_facts: true
>>         validate_certs: no
>>   register: vmguest_facts
>>   tags: vmfacts
>>
>> - name: debug facts
>>   debug: msg="vmguest facts are {{ vmguest_facts }}"
>>   tags: vmfacts
>>
>> - add_host: name={{ hw_eth0.ipaddresses[0] }} groups=virtual
>>
>

-- 
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/01c491f2-868e-47f0-885c-88294648770a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to