# \[ansible project\] VM snapshot capture using VMware

**URL:** <https://forum.ansible.com/t/ansible-project-vm-snapshot-capture-using-vmware/38657>\
**Category:** Ansible Project\
**Tags:** vmware\
**Created:** [January 19, 2024, 1:16am UTC](https://forum.ansible.com/t/ansible-project-vm-snapshot-capture-using-vmware/38657 "2024-01-19T01:16:37Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prady\_A](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/prady_a/32/4792_2.png) [@Prady\_A](https://forum.ansible.com/u/Prady_A)\
**Post date:** [January 19, 2024, 1:16am UTC](https://forum.ansible.com/t/ansible-project-vm-snapshot-capture-using-vmware/38657/1 "2024-01-19T01:16:37Z")

</div>

Hi experts,

We are doing automation to update RHEL7-\> RHEL8 .  
Before we upgrade we take the snapshot.  
The issue is whenever there is an upgrade failure we revert the server to its previous state. But it seems when we revert it the machine is in power off state…  
it seems when we take automatic snapshot it happens like that… Any pointers pls

Regards  
PD

---

<div class="post-metadata">

**Author:** ![Rilindo\_Foster1](https://avatars.discourse-cdn.com/v4/letter/r/8e8cbc/32.png) [@Rilindo\_Foster1](https://forum.ansible.com/u/Rilindo_Foster1)\
**Post date:** [January 19, 2024, 1:18am UTC](https://forum.ansible.com/t/ansible-project-vm-snapshot-capture-using-vmware/38657/2 "2024-01-19T01:18:52Z")

</div>

Hi!

It is not clear how this is an Ansible issue. Can you provide the playbook or role code you use to accomplish this?

- Rilindo

---

<div class="post-metadata">

**Author:** ![Nico\_Kadel-Garcia](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/nico_kadel-garcia/32/9998_2.png) [@Nico\_Kadel-Garcia](https://forum.ansible.com/u/Nico_Kadel-Garcia)\
**Post date:** [January 20, 2024, 10:15pm UTC](https://forum.ansible.com/t/ansible-project-vm-snapshot-capture-using-vmware/38657/3 "2024-01-20T22:15:16Z")

</div>

That's a RHEL problem. It's not an operation supported by RHEL.  
Updating the critical system libraries, such as glibc and the python  
on which RPM is based, and RPM itself, is likely to trip over a \*lot\*  
of problems without quite a lot of research and debugging. From  
decades of experience with Red Hat based operating systems, I  
recommend very strongly against this approach.

If I may suggest, take a disk image of the old system and build a new  
system, with content copied as needed to configure the new system.

---

<div class="post-metadata">

**Author:** ![Prady\_A](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/prady_a/32/4792_2.png) [@Prady\_A](https://forum.ansible.com/u/Prady_A)\
**Post date:** [January 22, 2024, 3:12am UTC](https://forum.ansible.com/t/ansible-project-vm-snapshot-capture-using-vmware/38657/4 "2024-01-22T03:12:57Z")

</div>

Hi,

Thank you both of you for your kind suggestions.  
We are using leap-upgrade tool to upgrade. In upgrade there is no issue. We have a health checkup also post upgrade.

The issue is in VMware but not sure when creating manually the “ **Snapshot the virtual machine memory** ” is set to Yes but when I am creating the snapshot through ansible automatically it is setting as No. This is something with VMware maybe…

- Name: Create VM snapshot  
Uri:  
URL: [https://api.xyz/virtualization/snapshot/snow](https://api.xyz/virtualization/snapshot/snow)  
User: “ {{ snapshot\_user }}”  
Password: “{{ snapshot\_Password }}“  
force\_basic\_auth: true  
Method: post  
Body\_format: json  
Body: |-  
{  
“Hostname”: “{{ vm\_hostname }}”,  
“Task”: “ create”,  
“Snapshot\_name”: “upgrade-{{vm\_hostname}} “  
}  
Status code: 202  
Register: snapshot\_result

Regards  
PD

---

<div class="post-metadata">

**Author:** ![Rilindo\_Foster1](https://avatars.discourse-cdn.com/v4/letter/r/8e8cbc/32.png) [@Rilindo\_Foster1](https://forum.ansible.com/u/Rilindo_Foster1)\
**Post date:** [January 22, 2024, 4:49am UTC](https://forum.ansible.com/t/ansible-project-vm-snapshot-capture-using-vmware/38657/5 "2024-01-22T04:49:59Z")

</div>

Is that a space before snapshot (right where it says “Task” in the JSON request)? Was that part of the request or did you insert that by mistake when you copied it into the email?

- Rilindo

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [January 22, 2024, 7:51am UTC](https://forum.ansible.com/t/ansible-project-vm-snapshot-capture-using-vmware/38657/6 "2024-01-22T07:51:29Z")

</div>

Just as “Snapshot\_name”: “upgrade-{{vm\_hostname}} “ has a trailing space…

---

<div class="post-metadata">

**Author:** ![Prady\_A](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/prady_a/32/4792_2.png) [@Prady\_A](https://forum.ansible.com/u/Prady_A)\
**Post date:** [January 22, 2024, 8:36am UTC](https://forum.ansible.com/t/ansible-project-vm-snapshot-capture-using-vmware/38657/7 "2024-01-22T08:36:09Z")

</div>

Hi Rilindo,

Thanks for your reply. That was typo error . I fixed the issue, in the REST api i need to pass memory flag which by default is false. This memory flag retains the machine power status also.

Thank you for your all support.

PD

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [January 22, 2024, 12:22pm UTC](https://forum.ansible.com/t/ansible-project-vm-snapshot-capture-using-vmware/38657/8 "2024-01-22T12:22:50Z")

</div>

We have these playbooks we use to create a snapshot and to revert a snapshot. The go into an ansible automation platform workflow. The esx-vars.yml has a dictionary you will need to modify for your environment. The dictionary key is a vcenter ID you create. We pass in an extravar for datacenter that provides the value of that key to look up at run time. We have an east and west vCenter and a sandbox we call “vCloud”. You will see vc\_east, vc\_west, vc\_vcloud keys in the esx\_vars.yml dictionary.

The esx-create-snapshot.yml gets info about the existing machine, powers it down, creates the snapshot, then powers it back up ONLY if it was powered on when we started (state: “{{ snapvm.instance.hw\_power\_status | lower }}” at line 74 comes from the guest info we get at line 31). At the bottom of esx-snapshot-create.yml we use set\_stats to artifacts so they can be used downstream in the AAP workflow by ex-snapshot-revert.yml including its powered on status.

Even if you don’t use these playbooks they may help you craft your own.

Walter

> **(attachments)**
>
> [esx-snapshot-create.yml](https://forum.ansible.com/uploads/short-url/ejz0TCGLE7EhjJ68qrG3slmBR0.yml) (3.26 KB)  
> [esx-snapshot-revert.yml](https://forum.ansible.com/uploads/short-url/cUWAOCckmIShlW4dK1fQe9VIy1u.yml) (2.31 KB)  
> [esx-vars.yml](https://forum.ansible.com/uploads/short-url/gx1UvzbhXwG18M6ATvijKNHnEZ6.yml) (296 Bytes)

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [January 22, 2024, 2:29pm UTC](https://forum.ansible.com/t/ansible-project-vm-snapshot-capture-using-vmware/38657/9 "2024-01-22T14:29:32Z")

</div>

Adding to my earlier message … we use these playbooks in a patching workflow. Snapshot, Patch, if patching fails, revert snapshot.

Walter

---

<div class="post-metadata">

**Author:** ![Prady\_A](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/prady_a/32/4792_2.png) [@Prady\_A](https://forum.ansible.com/u/Prady_A)\
**Post date:** [January 23, 2024, 1:52pm UTC](https://forum.ansible.com/t/ansible-project-vm-snapshot-capture-using-vmware/38657/10 "2024-01-23T13:52:02Z")

</div>

Thank you so much Walter that will definitely help…
