Errors regarding the API when trying to create vm from qcow2

Mr_Flibble

New Member
Dec 7, 2024
2
0
1
I have a large Ansible script that I won't post in full here because its nested, and just too much extra stuff to read across multiple files for most users to care. In short, it should create a new VM based off a small configuration file that contains basic info like VMid, and which qcow2 image to use to build, and then the major lifting is covered in DRY Ansible code.

Some things you may need to know. `optimus` is a large local ssd zfs store on the server called proxmox01. The Ansible script downloads new cloudinit-images, converts them to qcow2, and stores them there. I can use this storage to create images from the GUI. I use `optimus` as it is the largest drive on proxmox01. If I put the images on root, I become dangerously low on space.

The issue I am having, is buiding the VMs because every time I try to execute the script, it fails at the build with one of two errors (see below) reading the qcow2 images off of the local disk.

In case you are wondering, it is based off of this blog post and youtube video:
https://www.techtutorials.tv/sections/promox/automate-vm-creation-on-proxmox-with-ansible/

The particular part of the code I am having issues with is in two parts below, You can see a number of comments as I have been trying to work through this issue:

YAML:
# Create VMs
- name: Create VMs
  proxmox_kvm:
    api_user: '{{api_user}}'
    api_token_id: '{{api_token_id}}'
    api_token_secret: '{{api_token_secret}}'
    api_host: '{{api_host}}'
    node: '{{item.node}}'
    name: '{{item.name}}'
    vmid: '{{item.vmid}}'
    vga: serial0
    tags: '{{item.tags}}'
    net: '{"net0":"virtio,bridge={{linux_bridge}},tag={{item.vlan}},firewall=1"}'
    serial: '{"serial0":"socket"}'
    scsihw: virtio-scsi-single
# This is probably where the drive is breaking on creation drive_storage should be replaced with a variable
# that references optimus for node 1 so change drive_storage to a var like optimus_storage
# from vars:
# image_storage: local
# image_true_path: '/var/lib/vz/images/0/'
    scsi:
      scsi0: '{{drive_storage}}:0,import-from={{image_true_path}}{{item.image_file}},format={{drive_format}},iothread=1'
#      scsi0: '{{drive_storage}}:0,import-from={{image_true_path}}{{item.image_file}},format={{drive_format}},iothread=1'
    ide:
      ide2: '{{drive_storage}}:cloudinit'
    ostype: 'l26'
# Remaining Redacted for readability


The variables file I have been modifying contains the following:
YAML:
api_host: '{{inventory_hostname}}'
drive_storage: freenas
#drive_storage: optimus
drive_format: qcow2
snippets_storage: local
snippets_path: '/var/lib/vz/snippets/'
image_storage: local
#image_true_path: '/var/lib/vz/images/0/'
#image_true_path: 'local:/var/lib/vz/images/0/'
# below probably optimus, not local?
#image_true_path: '/optimus/lib/vz/images/0/'
image_true_path: 'local:/optimus/lib/vz/images/0/'
linux_bridge: vmbr20

The problem with the main script is that when the script tries to use the `image_true_path` if it resolves to `local:/optimus/lib/vz/images/0/` Then I get the following error - and I have 4 different qcow2 images in the directory, but they all fail in this same way:

failed: [proxmox01] (item={'name': 'Rockman', 'vmid': 112, 'node': 'proxmox01', 'image_file': 'Rocky-8-GenericCloud-Base.latest.x86_64.qcow2', 'cores': 2, 'memory': 1024, 'vlan': 20, 'ipv4mode': 'static', 'ipv4_address': '10.20.0.112/23', 'ipv4_gateway': '192.168.1.1', 'state': 'new', 'tags': ['rocky_linux', 'ansible_generated', 'vlan20']}) => {"ansible_loop_var": "item", "changed": false, "item": {"cores": 2, "image_file": "Rocky-8-GenericCloud-Base.latest.x86_64.qcow2", "ipv4_address": "10.20.0.112/23", "ipv4_gateway": "192.168.1.1", "ipv4mode": "static", "memory": 1024, "name": "Rockman", "node": "proxmox01", "state": "new", "tags": ["rocky_linux", "ansible_generated", "vlan20"], "vlan": 20, "vmid": 112}, "msg": "creation of qemu VM Rockman with vmid 112 failed with exception=500 Internal Server Error: unable to parse directory volume name '/optimus/lib/vz/images/0/Rocky-8-GenericCloud-Base.latest.x86_64.qcow2'", "vmid": 112}

When on the server itself if I do an ls:
root@proxmox01:~# ls -alh /optimus/lib/vz/images/0/Rocky-8-GenericCloud-Base.latest.x86_64.qcow2
-rw-r--r-- 1 root root 2.0G Nov 12 08:55 /optimus/lib/vz/images/0/Rocky-8-GenericCloud-Base.latest.x86_64.qcow2

Whereas, if I change the `image_true_path` to resolve to `/optimus/lib/vz/images/0/` I instead get the following error:

failed: [proxmox01] (item={'name': 'Rockman', 'vmid': 112, 'node': 'proxmox01', 'image_file': 'Rocky-8-GenericCloud-Base.latest.x86_64.qcow2', 'cores': 2, 'memory': 1024, 'vlan': 20, 'ipv4mode': 'static', 'ipv4_address': '10.20.0.112/23', 'ipv4_gateway': '192.168.1.1', 'state': 'new', 'tags': ['rocky_linux', 'ansible_generated', 'vlan20']}) => {"ansible_loop_var": "item", "changed": false, "item": {"cores": 2, "image_file": "Rocky-8-GenericCloud-Base.latest.x86_64.qcow2", "ipv4_address": "10.20.0.112/23", "ipv4_gateway": "192.168.1.1", "ipv4mode": "static", "memory": 1024, "name": "Rockman", "node": "proxmox01", "state": "new", "tags": ["rocky_linux", "ansible_generated", "vlan20"], "vlan": 20, "vmid": 112}, "msg": "creation of qemu VM Rockman with vmid 112 failed with exception=500 Internal Server Error: Only root can pass arbitrary filesystem paths. at /usr/share/perl5/PVE/Storage.pm line 651.", "vmid": 112}

I have googled this extensively, and come up with some posts on this very forum, but none seem to really explain why this is failing. I checked the API key, and I should have full permissions to this with the API key, and yet it still fails.

Relevant threads:

 
PVE does not permit/support subdirectories in well-defined paths, such as "images".
Try to either move your images up, removing "0", or symlink them above 0. You should end up with images here:
'local:/optimus/lib/vz/images'

You should also be able to list/see images when doing : pvesm list local

You can work out your API call with PVESH or curl, then map it to your Ansible.


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
Last edited: