pvesh exit codes are not consistent

kayson

New Member
Feb 13, 2024
11
1
3
I'm trying to write some ansible modules for configuring PVE via pvesh. It's important for ansible to know whether an operation has made a change or not versus an error happening. My plan was to use a pvesh get command to determine if something exists already. In some cases, it seems pvesh exits 2 if the item doesn't exist. In others, though, it exits 255. Unfortunately it also exits 255 if the api path supplied is wrong. In other cases, it exits 0! Are there some rules I'm missing for how the exit code is determined? Or is there a better way to know if something is already created before I create it?

Examples:

pvesh get /access/domains/inn; echo $?
domain 'inn' does not exist
2

pvesh get /access/groups/inn; echo $?
group 'inn' does not exist
255

pvesh get /nodes/asdf/apt/versions; echo $?
hostname lookup 'asdf' failed - failed to get address info for: asdf: Name or service not known
255

pvesh get /nodes/asdf/apt; echo $?
┌──────────────┐
│ id │
╞══════════════╡
│ changelog │
├──────────────┤
│ repositories │
├──────────────┤
│ update │
├──────────────┤
│ versions │
└──────────────┘
0
 
You may want to take a look at : https://bugzilla.proxmox.com/show_bug.cgi?id=3931

In summary, API returns success regardless of the end-result of actual API execution. Unless, of course, you receive an HTTP error. You have to find and examine the actual task.

Good luck


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
Thanks. This feels like a bad practice. I can sort of understand for something like a post/create that requires a task, but for a get, it makes no sense. For now I've resorted to parsing the error message, which is really fragile. I'm not sure what else I can do though.
 
Why reinvent the wheel? https://docs.ansible.com/ansible/latest/collections/community/general/proxmox_module.html

There is also Proxmoxer Python library that gives a better view into the API than the shell wrapper and you could probably convert that easily into Ansible roles. I believe pvesh is just a wrapper into the API through Perl. I found Proxmoxer to be much easier to work with.
That module only supports manipulation of instances; I want to do host configuration. I did look at proxmoxer and while I may still use it, it's just running pvesh commands via subprocess popen/run calls (when you use the local backend). It doesn't currently give you the exit code, though the dev is adding it, and obviously given the above it's not that useful. Adding a dependency just doesn't seem necessary for the simple operations these modules would need to do.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!