AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

Delete a VMware Virtual Machine Snapshot - Ansible module vmware_guest_snapshot — Video Tutorial

How to automate the delete of snapshot named “Ansible Managed Snapshot” in a VMware Virtual Machine “myvm” Ansible Playbook and vmware_guest_snapshot module.

Watch on YouTube · Read the written article

Tutorial summary

What you'll learn

  • How to Delete a VMware Virtual Machine Snapshot with Ansible?
  • Ansible Delete a VMware Virtual Machine Snapshot
  • Parameters
  • Links
  • code
  • execution
  • idempotency
  • before execution
  • after execution
  • Conclusion
How to Delete a VMware Virtual Machine Snapshot with Ansible? Ansible Delete a VMware Virtual Machine Snapshot - `community.vmware.vmware_guest_snapshot` - Manages virtual machines snapshots in vCenter Let's talk about the Ansible module `vmware_guest_snapshot`. The full name is `community.vmware.vmware_guest_snapshot`, which means that is part of the collection of modules to interact with VMware, community-supported. It manages virtual machine snapshots in vCenter. Parameters - hostname string / username string / password string / datacenter string / validate_certs boolean - connection details - state string - present / absent / revert / remove_all - remove_children boolean - no/yes - snapshot_name string description string - Name/description of the virtual machine to work with The following parameters are useful in order to Take a VMware Virtual Machine Snapshot using the module `vmware_guest_snapshot`. First of all, we need to establish the connection with VMware vSphere or VMware vCenter using a plethora of self-explicative parameters: `hostname`, `username`, `password`, `datacenter`, and `validate_certs`. Once the connection is successfully established you could specify the desired snapshot state, in this case, "absent" to delete a snapshot. You could also manage a snapshot with the same Ansible module. If you want to remove a snapshot you could also remove all the dependent snapshots using the parameter `remove_children`. You need to specify the exact snapshot name that you would like to remove in the `snapshot_name` parameter. Links - [community.vmware.vmware_guest_snapshot](https://docs.ansible.com/ansible/latest/collections/community/vmware/vmware_guest_snapshot_module.html) ## Playbook How to Delete a VMware Virtual Machine Snapshot with Ansible. code - vm_snapshot_remove.yml ```yaml --- - name: vm snapshot Playbook hosts: localhost become: false gather_facts: false collections: - community.vmware pre_tasks: - include_vars: vars.yml tasks: - name: remove snapshot vmware_guest_snapshot: hostname: "{{ vcenter_hostname }}" username: "{{ vcenter_username }}" password: "{{ vcenter_password }}" datacenter: "{{ vcenter_datacenter }}" validate_certs: "{{ vcenter_validate_certs }}" name: "{{ vm_name }}" folder: "{{ vm_folder }}" snapshot_name: "Ansible Managed Snapshot" state: absent ``` - vars.yml ```yaml --- vcenter_hostname: "vmware.example.com" vcenter_datacenter: "vmwaredatacenter" vcenter_validate_certs: false vcenter_username: "username@vsphere.local" vcenter_password: "MySecretPassword123" vm_name: "myvm" vm_template: "mytemplate" vm_folder: "myvm" ``` - inventory ```ini localhost ``` execution ```bash $ ansible-playbook vm_snapshot_remove.yml [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' PLAY [vm snapshot Playbook] **********************

About this tutorial

  • Author: Luca Berton
  • Difficulty: Beginner
  • Read time: 3 min
  • Category: troubleshooting

Topics covered

Related video tutorials