community.proxmox.proxmox_qemu_api connection – Connect to QEMU VMs via the Proxmox guest agent API
Note
This connection plugin is part of the community.proxmox collection (version 2.0.0).
You might already have this collection installed if you are using the ansible package.
It is not included in ansible-core.
To check whether it is installed, run ansible-galaxy collection list.
To install it, use: ansible-galaxy collection install community.proxmox.
You need further requirements to be able to use this connection plugin,
see Requirements for details.
To use it in a playbook, specify: community.proxmox.proxmox_qemu_api.
New in community.proxmox 2.0.0
Synopsis
Execute commands and transfer files through the Proxmox VE QEMU Guest Agent API.
Does not require SSH or network connectivity to the VM.
Requires the QEMU Guest Agent (
qemu-guest-agent) to be installed and running inside the target VM.Talks directly to the Proxmox REST API using
proxmoxer, avoiding the overhead and limitations of shelling out toqm guest execover SSH.Linux guests only. Windows guest support is not implemented.
Requirements
The below requirements are needed on the local controller node that executes this connection.
proxmoxer >= 2.3.0
requests
Parameters
Parameter |
Comments |
|---|---|
Proxmox VE API hostname or IP address. Configuration:
|
|
Password for Required when Configuration:
|
|
Proxmox VE API port. Default: Configuration:
|
|
API token ID (for example Used with Mutually exclusive with Configuration:
|
|
API token secret UUID. Required when Configuration:
|
|
Proxmox VE API user (for example Used with Mutually exclusive with Configuration:
|
|
Maximum number of seconds to wait for the guest agent to become responsive. The plugin polls the agent every 5 seconds during connection. Default: Configuration:
|
|
Shell executable for command execution on the guest. Default: Configuration:
|
|
Proxmox node name where the VM resides. Configuration:
|
|
Temporary directory on the guest for staging chunked file transfers. Must be writable by the guest agent process (typically root). Only used when transferring files larger than 45000 bytes. Default: Configuration:
|
|
Validate PVE API TLS certificates. Choices:
Configuration:
|
|
Note
Configuration entries listed above for each entry type (Ansible variable, environment variable, and so on) have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up. The entry types are also ordered by precedence from low to high priority order. For example, an ansible.cfg entry (further up in the list) is overwritten by an Ansible variable (further down in the list).
Notes
Note
The API user or token requires guest agent privileges on the target VM. On PVE 8, this is
VM.Monitor. On PVE 9+,VM.Monitorwas replaced with fine-grained privileges --VM.GuestAgent.Unrestrictedcovers command execution,VM.GuestAgent.FileReadandVM.GuestAgent.FileWritecover file transfers. Alternatively,VM.GuestAgent.Unrestrictedalone grants access to all guest agent operations.This plugin requires the QEMU Guest Agent to be installed and running inside the VM. If the agent is not responsive, the connection will fail after
connect_timeoutseconds.File transfers use the PVE guest agent file-read/file-write API, which has a per-call size limit of approximately 45000 bytes. Files larger than this are automatically split into chunks using
spliton the guest and reassembled on the controller or guest.Guest requirements:
qemu-guest-agentmust be running. File transfers additionally requirecat,split,ls, andrm(coreutils).Works with the
community.proxmox.proxmoxinventory plugin. Setansible_connection=community.proxmox.proxmox_qemu_apion discovered hosts.
Examples
- name: Static inventory example
# inventory.yml
# all:
# hosts:
# my-vm:
# ansible_connection: community.proxmox.proxmox_qemu_api
# proxmox_vmid: 100
# ansible_host: my-vm.example.com
# vars:
# proxmox_api_host: pve-1.example.com
# proxmox_api_port: 8006
# proxmox_api_token_id: automation@pve!ansible
# proxmox_api_token_secret: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
# proxmox_node: pve-1
hosts: my-vm
gather_facts: true
tasks:
- name: Install a package
ansible.builtin.apt:
name: curl
state: present
- name: Copy a configuration file
ansible.builtin.copy:
src: app.conf
dest: /etc/app/app.conf
- name: Run a command
ansible.builtin.command:
cmd: systemctl restart app