ovirt-ansible-collection icon indicating copy to clipboard operation
ovirt-ansible-collection copied to clipboard

Cannot attach/detach DirectLUN disk from/to VM with ansible module "ovirt_disk"

Open Woocki opened this issue 1 year ago • 1 comments

Problem with detaching and attaching LUN disks from/to VM with ansible modules "ovirt_disk" (via GUI all works as expected). The module at some point tries to check a storage_profile of the disk, but because the disk is an LUN type, it does not have such propertise (details about vdisk you will find below). We've tested collections ovirt.ovirt in ver.3.0.0 and 2.3.1.

Module fails with message: The full traceback is: Traceback (most recent call last): File "/tmp/ansible_ovirt_disk_payload_dhv02mk9/ansible_ovirt_disk_payload.zip/ansible_collections/ovirt/ovirt/plugins/modules/ovirt_disk.py", line 901, in main File "/tmp/ansible_ovirt_disk_payload_dhv02mk9/ansible_ovirt_disk_payload.zip/ansible_collections/ovirt/ovirt/plugins/module_utils/ovirt.py", line 644, in create if not self.update_check(entity): File "/tmp/ansible_ovirt_disk_payload_dhv02mk9/ansible_ovirt_disk_payload.zip/ansible_collections/ovirt/ovirt/plugins/modules/ovirt_disk.py", line 738, in update_check AttributeError: 'NoneType' object has no attribute 'name' We tried to add other keys like logical_unit(id) or profile, but without success. The only way which we ware able to run it correctly was commenting out line: # equal(self.param('profile'), follow_link(self._connection, entity.disk_profile).name) from update_check() method from module ovirt_disk.py.

Ansible/python version: ansible-playbook --version ansible-playbook [core 2.12.2] config file = /etc/ansible/ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.8/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /usr/bin/ansible-playbook python version = 3.8.12 (default, Apr 5 2022, 08:07:47) [GCC 8.5.0 20210514 (Red Hat 8.5.0-10.0.1)] jinja version = 2.10.3 libyaml = True

Disk details: "ovirt_disks": [ { "alias": "os-edfstore01.gr7_data-edfstore_backup-template-DO-NOT-DELETE.img.qcow2", "content_type": "data", "description": "0000", "disk_snapshots": [], "href": "/ovirt-engine/api/disks/c1e98497-5049-4e0f-98a3-b1ff2175abc9", "id": "c1e98497-5049-4e0f-98a3-b1ff2175abc9", "lun_storage": { "id": "3600c0ff00050c878b225c96301000000", "logical_units": [ { "discard_max_size": 1073741824, "discard_zeroes_data": false, "disk_id": "c1e98497-5049-4e0f-98a3-b1ff2175abc9", "id": "3600c0ff00050c878b225c96301000000", "lun_mapping": 13, "paths": 0, "product_id": "MSA 2050 SAN", "serial": "SHPE_MSA_2050_SAN_00c0ff50c8780000b225c96301000000", "size": 0, "vendor_id": "HPE" } ] }, "name": "os-edfstore01.gr7_data-edfstore_backup-template-DO-NOT-DELETE.img.qcow2", "permissions": [], "propagate_errors": false, "shareable": false, "statistics": [], "storage_type": "lun", "wipe_after_delete": false } ]

We execute the module with following keys: `

  • name: Detach disks from {{ vm }} VM ovirt_disk: auth: "{{ ovirt_auth }}" name: "{{ disk }}" vm_name: "{{ vm }}" state: "detached"
  • name: "Attaching LUN" ovirt_disk: auth: "{{ ovirt_auth }}" name: "{{ vm }}some_disk" vm_name: "{{ vm }}" host: "{{ vars[environment_name+''+zone+'_import_host'][side] }}" activate: True logical_unit: id: "3600c0ff00050c878b225c96301000000" interface: virtio state: "attached" `

Woocki avatar Jan 26 '23 08:01 Woocki

We have the same issue. We need to use a direct API call in the ansible scripts as attaching the direct LUNs do not work.

I will post our workaround here (just in case someone want to do something similar).

  • name: Attaching LUN... uri: url: "{{ ovirt_url }}/vms/{{ ovirt_vm.id }}/diskattachments" user: "{{ ovirt_username }}" password: "{{ ovirt_password }}" method: POST body_format: raw body: ' <disk_attachment> false <pass_discard>true</pass_discard> virtio_scsi true </disk_attachment>' validate_certs: false headers: Content-Type: application/xml Version: 4 Accept: application/xml status_code: 201

freshpr avatar Apr 16 '23 18:04 freshpr