Attach existing disk to proxmox vm

Hello!

I created a VM in Proxmox and imported a disk from a image. It is visible as “Unused Disk 0” in Proxmox.

How can I attach it as scsi0?

I tried:

    - name: Import root disk (2)
      delegate_to: pve1
      community.general.proxmox_disk:
        vmid: "{{ vm_metadata.vmid }}"
        disk: unused0
        size: "8" # Same error, if its used or not
        backup: true
        cache: "writethrough"
        discard: true
        iothread: true 
        state: present

Failure message:

fatal: [OPNsense -> pve1(172.29.40.2)]: FAILED! => {"changed": false, "msg": "Unable to create/update disk unused0 in VM 254: 'size'", "vmid": 254}

Thanks a lot!

Thomas

Hi there!

I tried to read the code of the module, but from what I make up from it, the module doesn’t support it (yet). Reading the docs would suggest that you’d need to have the target_disk parameter and a state attached or (present), but the target_disk only works when you move the disk.

Which prompts me to, can you try something like this:

    - name: Import root disk (2)
      delegate_to: pve1
      community.general.proxmox_disk:
        vmid: "{{ vm_metadata.vmid }}"
        target_vmid: "{{ vm_metadata.vmid }}"
        disk: unused0
        target_disk: scsi0
        state: moved

If it works, we’ll need to add an example to the module describing this (it currently only describes the detaching part). If it doesn’t, I think we’ll need to engineer a way to have the present state also use the target_disk parameter, but only if disk is ‘unused’.

Would you agree?

1 Like

Unfortunately, this does not work:

TASK [prox_create_vm : Import root disk (2)] ***************************************************************************
fatal: [OPNsense -> pve1(172.29.40.2)]: FAILED! => {"changed": false, "msg": "Failed to move disk unused0 in VM 254 with exception: 400 Bad Request: Parameter verification failed."}


But I found a workaround for the moment:

- name: Import root disk (2)
  delegate_to: pve1
  ansible.builtin.command:
    cmd: qm set {{ vm_metadata.vmid }} --scsi0 VM-Volumes:vm-254-disk-0,size=8

Would be nice, if the ansible module could support this directly :slight_smile:

Anyway, @Thulium-Drake Thanks for your help!

1 Like

@DengelFred Hello! Your use case was not in the scope when this module was developed. You can import image as <bus><number> skipping that "unused" state using proxmox_disk module, but action attaching disk that was detached is not implemented yet.

@Thulium-Drake I think it will be useful to add a "attached" state (since "detached" already exists), which will connect existing disk to some controller. But I’m afraid this can be done only when proxmox collection will finish migration to its own repository.

3 Likes

@castorsky I agree, let’s first tie up the loose ends in community.general before taking on new ones :wink:

When we’re up and running with the new collection, I’ll try to take a stab at it :slight_smile:

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.