# Attach existing disk to proxmox vm

**URL:** <https://forum.ansible.com/t/attach-existing-disk-to-proxmox-vm/4291>\
**Category:** Get Help\
**Tags:** proxmox\
**Created:** [March 9, 2024, 11:15pm UTC](https://forum.ansible.com/t/attach-existing-disk-to-proxmox-vm/4291 "2024-03-09T23:15:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![DengelFred](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@DengelFred](https://forum.ansible.com/u/DengelFred)\
**Post date:** [March 9, 2024, 11:15pm UTC](https://forum.ansible.com/t/attach-existing-disk-to-proxmox-vm/4291/1 "2024-03-09T23:15:52Z")

</div>

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:

```auto
    - 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:

```auto
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

---

<div class="post-metadata">

**Author:** ![Thulium-Drake](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/thulium-drake/32/833_2.png) [@Thulium-Drake](https://forum.ansible.com/u/Thulium-Drake)\
**Post date:** [March 10, 2024, 11:11am UTC](https://forum.ansible.com/t/attach-existing-disk-to-proxmox-vm/4291/2 "2024-03-10T11:11:04Z")

</div>

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:

```auto
    - 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?

---

<div class="post-metadata">

**Author:** ![DengelFred](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@DengelFred](https://forum.ansible.com/u/DengelFred)\
**Post date:** [March 10, 2024, 11:19am UTC](https://forum.ansible.com/t/attach-existing-disk-to-proxmox-vm/4291/3 "2024-03-10T11:19:49Z")

</div>

Unfortunately, this does not work:

```auto
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."}

```

---

<div class="post-metadata">

**Author:** ![DengelFred](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@DengelFred](https://forum.ansible.com/u/DengelFred)\
**Post date:** [March 10, 2024, 11:30am UTC](https://forum.ansible.com/t/attach-existing-disk-to-proxmox-vm/4291/4 "2024-03-10T11:30:52Z")

</div>

But I found a workaround for the moment:

```auto
- 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 🙂

Anyway, @Thulium-Drake Thanks for your help!

---

<div class="post-metadata">

**Author:** ![castorsky](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/castorsky/32/2401_2.png) [@castorsky](https://forum.ansible.com/u/castorsky)\
**Post date:** [March 10, 2024, 11:50am UTC](https://forum.ansible.com/t/attach-existing-disk-to-proxmox-vm/4291/5 "2024-03-10T11:50:48Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![Thulium-Drake](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/thulium-drake/32/833_2.png) [@Thulium-Drake](https://forum.ansible.com/u/Thulium-Drake)\
**Post date:** [March 10, 2024, 12:50pm UTC](https://forum.ansible.com/t/attach-existing-disk-to-proxmox-vm/4291/6 "2024-03-10T12:50:34Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [April 9, 2024, 12:51pm UTC](https://forum.ansible.com/t/attach-existing-disk-to-proxmox-vm/4291/7 "2024-04-09T12:51:24Z")

</div>

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