Run commands on a guest

Matteo Calorio

Renowned Member
Jun 30, 2017
35
0
71
53
Hi everyone, what's the best way to run commands from an host on a guest (Linux) that can also be on a different host?

Something like:
  • qm guest exec 100 --node node01 -- apt update -y, or:
  • pvesh set /nodes/node01/qemu/100/agent/exec -command "apt update"?
M.
 
Hi,

qm can control only vms on the node, it is running on.
I would use pvesh and also use it to look up on which node the vm is running on. Something like this (requires jq installed):
Bash:
TARGET=100
NODE=$(pvesh get /cluster/resources --output-format json | \
        jq -r --argjson TARGETVM $TARGET '.[] | select(.vmid==$TARGETVM) | .node')
pvesh create /nodes/${NODE}/qemu/${TARGET}/agent/exec -command "apt" -command "update"

Aside of that: There are better ways for infrastructure tasks like using Ansible, Foreman or for simplicity Cockpit.
 
Last edited:
  • Like
Reactions: carles89 and UdoB