How to clone a VM from snapshot with Ansible

Latest response

I need to automate the following task:

  1. Create a VM snapshot
  2. Clone a VM from the snapshot
  3. On new new VM, bring NIC down
  4. Start the new VM

Step 2 seems to be doable manually only. Is there a way to automate it?

The reason for this task is verifying virtual machines, there is a long story behind it.

Thank you,


I am looking for the same. To clone a VM from a snapshot using ansible. Let me know if you figured out a way. Thanks.

Hi Ilya Palagin and Naga Naveen Vaddi,

When you say VM here, I do not know if you mean Red Hat Enterprise Virtualization, or "Kernel Virtual Machine" (KVM is a poor name for generic virtualization method) or Oracle's Virtual Box, or (shudder) perhaps Microsoft's hyper-v.

If you happen to be using ESX (VMware) here's some documentation direct from Ansible on an Ansible module for snapshots. I'd certainly verify the version of Ansible you are using to make sure the expectation of using the latest version of Ansible is valid in your own environment.

Let us know how it goes, you'll have to read through the Ansible module and compose a recipe in terms of a playbook to do this. I've personally never done an Ansible playbook for a snapshot as you say using this Ansible Module. There is an example at that link, but I'd recommend not taking it at face value and scrutinize it and change it as needed for sanity for your environment and intentions.



Thanks for the response Hinton! Yes i am talking about ESX(VMware). The module vmware_guest_snapshot helps us to create a snapshot but i was looking for cloning a VM. You can find the manual steps here:

In case anyone is still looking for this functionality here in 2021, the Ansible vmware_guest module provides this functionality as of Ansible 2.4. Note that the vmware_guest module was moved to the community.vmware collection in or around Ansible 2.10

You'll want to pass the 'snapshot_src' parameter populated by the name of the snapshot from which you want to clone. An example playbook or data snippet might be something like:

template: golden_image
snapshot_src: pre-upgrade

This would deploy a clone based on the machine "golden_image" from the snapshot called "pre-upgrade" (names must match exactly, including casing).

Strangely, I've never seen this exposed to users via the VMware UI either. Go figure.