I would put that code in vm_create.yml

and then you can:

- name: Create VMs
  include_tasks: vm_create.yml
  loop:
    - VM1
    - VM2
  loop_control:
    loop_var: vm_name


Then inside your vm_create.yml you will use "{{ vm_name }}" as the name of the VM.

Best Regards,
Strahil Nikolov

On Sun, Nov 28, 2021 at 16:42, Sina Owolabi
<notify.sina@gmail.com> wrote:
Amazing.

Thanks! Works!
No to figure out how to create multiple vms at a time!

On Sun, Nov 28, 2021 at 2:32 PM Gianluca Cecchi
<gianluca.cecchi@gmail.com> wrote:
>
> On Sun, Nov 28, 2021 at 3:44 AM Sina Owolabi <notify.sina@gmail.com> wrote:
>>
>>
>>    - name: Print vm attributes
>>      ovirt.ovirt.ovirt_vm_info:
>>        auth: "{{ ovirt_auth }}"
>>        pattern: name="{{ vm_fqdn }}"
>>      register: vm_info
>>    - debug:
>>        msg: "{{ vm_info.ovirt_vms[0] }}"
>>
>
> here above you get an empty disk_attachments field.
> You have to add fetch_nested: true to traverse and get the disk attachments values
>
> Eg:
>    - name: Print vm attributes
>      ovirt.ovirt.ovirt_vm_info:
>        auth: "{{ ovirt_auth }}"
>        pattern: name="{{ vm_fqdn }}"
>        fetch_nested: true
>      register: vm_info
>    - debug:
>        msg: "{{ vm_info.ovirt_vms[0] }}"
>
>>
>>    - name: Rename disk
>>      ovirt.ovirt.ovirt_disk:
>>        auth: "{{ ovirt_auth }}"
>>        id: "{{ vm_info.ovirt_vms[0].id }}"
>>        storage_domain: lrg0-ovirt-mydom-internal-Local
>>        name: "{{ vm_fqdn }}-osdisk0"
>>        vm_name: "{{ vm_fqdn }}"
>>
>
> Here, supposing from pattern filter above you get only 1 VM so you can use index 0 and you get only 1 disk inside the VM and you can use index 0 also for disk, you can use:
> See also "ansible-doc ovirt_vm_info" help page, where you can filter the nested_attributes...
> Then the rename disk task would become
>
>    - name: Rename disk
>      ovirt.ovirt.ovirt_disk:
>        auth: "{{ ovirt_auth }}"
>        id: "{{ vm_info.ovirt_vms[0].disk_attachments[0].id }}"
>        storage_domain: lrg0-ovirt-mydom-internal-Local
>        name: "{{ vm_fqdn }}-osdisk0"
>        vm_name: "{{ vm_fqdn }}"
>
> This works for me in a 4.4.7 test environment
>
> HIH,
> Gianluca
>
>
>


--

cordially yours,

Sina Owolabi

+2348176469061

_______________________________________________
Users mailing list -- users@ovirt.org
To unsubscribe send an email to users-leave@ovirt.org
Privacy Statement: https://www.ovirt.org/privacy-policy.html
oVirt Code of Conduct: https://www.ovirt.org/community/about/community-guidelines/
List Archives:
https://lists.ovirt.org/archives/list/users@ovirt.org/message/XNBRIBAOLD4GK5LKVUJNJPACCNPZ7K66/