community.general.proxmox_snap module – Snapshot management of instances in Proxmox VE cluster

Note

This module is part of the community.general collection (version 9.5.1).

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.general. You need further requirements to be able to use this module, see Requirements for details.

To use it in a playbook, specify: community.general.proxmox_snap.

New in community.general 2.0.0

Synopsis

  • Allows you to create/delete/restore snapshots from instances in Proxmox VE cluster.

  • Supports both KVM and LXC, OpenVZ has not been tested, as it is no longer supported on Proxmox VE.

Requirements

The below requirements are needed on the host that executes this module.

  • proxmoxer

  • requests

Parameters

Parameter

Comments

api_host

string / required

Specify the target host of the Proxmox VE cluster.

api_password

string

Specify the password to authenticate with.

You can use PROXMOX_PASSWORD environment variable.

api_port

integer

added in community.general 9.1.0

Specify the target port of the Proxmox VE cluster.

Uses the PROXMOX_PORT environment variable if not specified.

api_token_id

string

added in community.general 1.3.0

Specify the token ID.

Requires proxmoxer>=1.1.0 to work.

api_token_secret

string

added in community.general 1.3.0

Specify the token secret.

Requires proxmoxer>=1.1.0 to work.

api_user

string / required

Specify the user to authenticate with.

description

string

Specify the description for the snapshot. Only used on the configuration web interface.

This is saved as a comment inside the configuration file.

force

boolean

For removal from config file, even if removing disk snapshot fails.

Choices:

  • false ← (default)

  • true

hostname

string

The instance name.

retention

integer

added in community.general 7.1.0

Remove old snapshots if there are more than retention snapshots.

If retention is set to 0, all snapshots will be kept.

This is only used when state=present and when an actual snapshot is created. If no snapshot is created, all existing snapshots will be kept.

Default: 0

snapname

string

Name of the snapshot that has to be created/deleted/restored.

Default: "ansible_snap"

state

string

Indicate desired state of the instance snapshot.

The rollback value was added in community.general 4.8.0.

Choices:

  • "present" ← (default)

  • "absent"

  • "rollback"

timeout

integer

Timeout for operations.

Default: 30

unbind

boolean

added in community.general 5.7.0

This option only applies to LXC containers.

Allows to snapshot a container even if it has configured mountpoints.

Temporarily disables all configured mountpoints, takes snapshot, and finally restores original configuration.

If running, the container will be stopped and restarted to apply config changes.

Due to restrictions in the Proxmox API this option can only be used authenticating as root@pam with api_password, API tokens do not work either.

See https://pve.proxmox.com/pve-docs/api-viewer/#/nodes/{node}/lxc/{vmid}/config (PUT tab) for more details.

Choices:

  • false ← (default)

  • true

validate_certs

boolean

If false, SSL certificates will not be validated.

This should only be used on personally controlled sites using self-signed certificates.

Choices:

  • false ← (default)

  • true

vmid

string

The instance id.

If not set, will be fetched from PromoxAPI based on the hostname.

vmstate

boolean

Snapshot includes RAM.

Choices:

  • false ← (default)

  • true

Attributes

Attribute

Support

Description

action_group

Action group: community.general.proxmox

added in community.general 9.0.0

Use group/community.general.proxmox in module_defaults to set defaults for this module.

check_mode

Support: full

Can run in check_mode and return changed status prediction without modifying target.

diff_mode

Support: none

Will return details on what has changed (or possibly needs changing in check_mode), when in diff mode.

Notes

Note

  • Requires proxmoxer and requests modules on host. These modules can be installed with pip.

Examples

- name: Create new container snapshot
  community.general.proxmox_snap:
    api_user: root@pam
    api_password: 1q2w3e
    api_host: node1
    vmid: 100
    state: present
    snapname: pre-updates

- name: Create new container snapshot and keep only the 2 newest snapshots
  community.general.proxmox_snap:
    api_user: root@pam
    api_password: 1q2w3e
    api_host: node1
    vmid: 100
    state: present
    snapname: snapshot-42
    retention: 2

- name: Create new snapshot for a container with configured mountpoints
  community.general.proxmox_snap:
    api_user: root@pam
    api_password: 1q2w3e
    api_host: node1
    vmid: 100
    state: present
    unbind: true # requires root@pam+password auth, API tokens are not supported
    snapname: pre-updates

- name: Remove container snapshot
  community.general.proxmox_snap:
    api_user: root@pam
    api_password: 1q2w3e
    api_host: node1
    vmid: 100
    state: absent
    snapname: pre-updates

- name: Rollback container snapshot
  community.general.proxmox_snap:
    api_user: root@pam
    api_password: 1q2w3e
    api_host: node1
    vmid: 100
    state: rollback
    snapname: pre-updates

Authors

  • Jeffrey van Pelt (@Thulium-Drake)