On Sun, Nov 28, 2021 at 3:44 AM Sina Owolabi <notify.sina(a)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