community.vmware.vmware_guest_snapshot (4.2.0) — module

Manages virtual machines snapshots in vCenter

Authors: Loic Blot (@nerzhul) <loic.blot@unix-experience.fr>

Install collection

Install with ansible-galaxy collection install community.vmware:==4.2.0


Add to requirements.yml

  collections:
    - name: community.vmware
      version: 4.2.0

Description

This module can be used to create, delete and update snapshot(s) of the given virtual machine.

All parameters and VMware object names are case sensitive.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
  - name: Create a snapshot
    community.vmware.vmware_guest_snapshot:
      hostname: "{{ vcenter_hostname }}"
      username: "{{ vcenter_username }}"
      password: "{{ vcenter_password }}"
      datacenter: "{{ datacenter_name }}"
      folder: "/{{ datacenter_name }}/vm/"
      name: "{{ guest_name }}"
      state: present
      snapshot_name: snap1
      description: snap1_description
    delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
  - name: Remove a snapshot
    community.vmware.vmware_guest_snapshot:
      hostname: "{{ vcenter_hostname }}"
      username: "{{ vcenter_username }}"
      password: "{{ vcenter_password }}"
      datacenter: "{{ datacenter_name }}"
      folder: "/{{ datacenter_name }}/vm/"
      name: "{{ guest_name }}"
      state: absent
      snapshot_name: snap1
    delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
  - name: Revert to a snapshot
    community.vmware.vmware_guest_snapshot:
      hostname: "{{ vcenter_hostname }}"
      username: "{{ vcenter_username }}"
      password: "{{ vcenter_password }}"
      datacenter: "{{ datacenter_name }}"
      folder: "/{{ datacenter_name }}/vm/"
      name: "{{ guest_name }}"
      state: revert
      snapshot_name: snap1
    delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
  - name: Remove all snapshots of a VM
    community.vmware.vmware_guest_snapshot:
      hostname: "{{ vcenter_hostname }}"
      username: "{{ vcenter_username }}"
      password: "{{ vcenter_password }}"
      datacenter: "{{ datacenter_name }}"
      folder: "/{{ datacenter_name }}/vm/"
      name: "{{ guest_name }}"
      state: remove_all
    delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
  - name: Remove all snapshots of a VM using MoID
    community.vmware.vmware_guest_snapshot:
      hostname: "{{ vcenter_hostname }}"
      username: "{{ vcenter_username }}"
      password: "{{ vcenter_password }}"
      datacenter: "{{ datacenter_name }}"
      folder: "/{{ datacenter_name }}/vm/"
      moid: vm-42
      state: remove_all
    delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
  - name: Take snapshot of a VM using quiesce and memory flag on
    community.vmware.vmware_guest_snapshot:
      hostname: "{{ vcenter_hostname }}"
      username: "{{ vcenter_username }}"
      password: "{{ vcenter_password }}"
      datacenter: "{{ datacenter_name }}"
      folder: "/{{ datacenter_name }}/vm/"
      name: "{{ guest_name }}"
      state: present
      snapshot_name: dummy_vm_snap_0001
      quiesce: true
      memory_dump: true
    delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
  - name: Remove a snapshot and snapshot subtree
    community.vmware.vmware_guest_snapshot:
      hostname: "{{ vcenter_hostname }}"
      username: "{{ vcenter_username }}"
      password: "{{ vcenter_password }}"
      datacenter: "{{ datacenter_name }}"
      folder: "/{{ datacenter_name }}/vm/"
      name: "{{ guest_name }}"
      state: absent
      remove_children: true
      snapshot_name: snap1
    delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
  - name: Remove a snapshot with a snapshot id
    community.vmware.vmware_guest_snapshot:
      hostname: "{{ vcenter_hostname }}"
      username: "{{ vcenter_username }}"
      password: "{{ vcenter_password }}"
      datacenter: "{{ datacenter_name }}"
      folder: "/{{ datacenter_name }}/vm/"
      name: "{{ guest_name }}"
      snapshot_id: 10
      state: absent
    delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
  - name: Rename a snapshot
    community.vmware.vmware_guest_snapshot:
      hostname: "{{ vcenter_hostname }}"
      username: "{{ vcenter_username }}"
      password: "{{ vcenter_password }}"
      datacenter: "{{ datacenter_name }}"
      folder: "/{{ datacenter_name }}/vm/"
      name: "{{ guest_name }}"
      state: present
      snapshot_name: current_snap_name
      new_snapshot_name: im_renamed
      new_description: "{{ new_snapshot_description }}"
    delegate_to: localhost

Inputs

    
moid:
    description:
    - Managed Object ID of the instance to manage if known, this is a unique identifier
      only within a single vCenter instance.
    - This is required if O(name) or O(uuid) is not supplied.
    type: str

name:
    description:
    - Name of the virtual machine to work with.
    - This is required parameter, if O(uuid) or O(moid) is not supplied.
    type: str

port:
    default: 443
    description:
    - The port number of the vSphere vCenter or ESXi server.
    - If the value is not specified in the task, the value of environment variable E(VMWARE_PORT)
      will be used instead.
    type: int

uuid:
    description:
    - UUID of the instance to manage if known, this is VMware's BIOS UUID by default.
    - This is required if O(name) or O(moid) parameter is not supplied.
    type: str

state:
    choices:
    - present
    - absent
    - revert
    - remove_all
    default: present
    description:
    - Manage snapshot(s) attached to a specific virtual machine.
    - If set to V(present) and snapshot absent, then will create a new snapshot with the
      given name.
    - If set to V(present) and snapshot present, then no changes are made.
    - If set to V(absent) and snapshot present, then snapshot with the given name is removed.
    - If set to V(absent) and snapshot absent, then no changes are made.
    - If set to V(revert) and snapshot present, then virtual machine state is reverted
      to the given snapshot.
    - If set to V(revert) and snapshot absent, then no changes are made.
    - If set to V(remove_all) and snapshot(s) present, then all snapshot(s) will be removed.
    - If set to V(remove_all) and snapshot(s) absent, then no changes are made.
    type: str

folder:
    description:
    - Destination folder, absolute or relative path to find an existing guest.
    - This is required parameter, if O(name) is supplied.
    - The folder should include the datacenter. ESX's datacenter is ha-datacenter.
    - 'Examples:'
    - '   folder: /ha-datacenter/vm'
    - '   folder: ha-datacenter/vm'
    - '   folder: /datacenter1/vm'
    - '   folder: datacenter1/vm'
    - '   folder: /datacenter1/vm/folder1'
    - '   folder: datacenter1/vm/folder1'
    - '   folder: /folder1/datacenter1/vm'
    - '   folder: folder1/datacenter1/vm'
    - '   folder: /folder1/datacenter1/vm/folder2'
    type: str

quiesce:
    default: false
    description:
    - If set to V(true) and virtual machine is powered on, it will quiesce the file system
      in virtual machine.
    - Note that VMware Tools are required for this flag.
    - If virtual machine is powered off or VMware Tools are not available, then this flag
      is set to V(false).
    - If virtual machine does not provide capability to take quiesce snapshot, then this
      flag is set to V(false).
    required: false
    type: bool

hostname:
    description:
    - The hostname or IP address of the vSphere vCenter or ESXi server.
    - If the value is not specified in the task, the value of environment variable E(VMWARE_HOST)
      will be used instead.
    type: str

password:
    aliases:
    - pass
    - pwd
    description:
    - The password of the vSphere vCenter or ESXi server.
    - If the value is not specified in the task, the value of environment variable E(VMWARE_PASSWORD)
      will be used instead.
    type: str

username:
    aliases:
    - admin
    - user
    description:
    - The username of the vSphere vCenter or ESXi server.
    - If the value is not specified in the task, the value of environment variable E(VMWARE_USER)
      will be used instead.
    type: str

datacenter:
    description:
    - Destination datacenter for the deploy operation.
    required: true
    type: str

name_match:
    choices:
    - first
    - last
    default: first
    description:
    - If multiple VMs matching the name, use the first or last found.
    type: str

proxy_host:
    description:
    - Address of a proxy that will receive all HTTPS requests and relay them.
    - The format is a hostname or a IP.
    - If the value is not specified in the task, the value of environment variable E(VMWARE_PROXY_HOST)
      will be used instead.
    required: false
    type: str

proxy_port:
    description:
    - Port of the HTTP proxy that will receive all HTTPS requests and relay them.
    - If the value is not specified in the task, the value of environment variable E(VMWARE_PROXY_PORT)
      will be used instead.
    required: false
    type: int

description:
    default: ''
    description:
    - Define an arbitrary description to attach to snapshot.
    type: str

memory_dump:
    default: false
    description:
    - If set to V(true), memory dump of virtual machine is also included in snapshot.
    - Note that memory snapshots take time and resources, this will take longer time to
      create.
    - If virtual machine does not provide capability to take memory snapshot, then this
      flag is set to V(false).
    required: false
    type: bool

snapshot_id:
    description:
    - Sets the snapshot id to manage.
    - This param is available when O(state=absent).
    type: int
    version_added: 3.10.0
    version_added_collection: community.vmware

snapshot_name:
    description:
    - Sets the snapshot name to manage.
    - This param or O(snapshot_id) is required only if O(state) is not C(remove_all)
    type: str

validate_certs:
    default: true
    description:
    - Allows connection when SSL certificates are not valid. Set to V(false) when certificates
      are not trusted.
    - If the value is not specified in the task, the value of environment variable E(VMWARE_VALIDATE_CERTS)
      will be used instead.
    type: bool

new_description:
    description:
    - Value to change the description of an existing snapshot to.
    type: str

remove_children:
    default: false
    description:
    - If set to V(true) and O(state=absent), then entire snapshot subtree is set for removal.
    required: false
    type: bool

new_snapshot_name:
    description:
    - Value to rename the existing snapshot to.
    type: str

use_instance_uuid:
    default: false
    description:
    - Whether to use the VMware instance UUID rather than the BIOS UUID.
    type: bool

Outputs

snapshot_results:
  description: metadata about the virtual machine snapshots
  returned: always
  sample:
    current_snapshot:
      creation_time: '2019-04-09T14:40:26.617427+00:00'
      description: Snapshot 4 example
      id: 4
      name: snapshot4
      state: poweredOff
    snapshots:
    - creation_time: '2019-04-09T14:38:24.667543+00:00'
      description: Snapshot 3 example
      id: 3
      name: snapshot3
      state: poweredOff
    - creation_time: '2019-04-09T14:40:26.617427+00:00'
      description: Snapshot 4 example
      id: 4
      name: snapshot4
      state: poweredOff
  type: dict