Issue with vmware_guest_snapshot module

585 views
Skip to first unread message

ameri...@optonline.net

unread,
May 16, 2017, 9:19:06 AM5/16/17
to Ansible Project
Hi all,

I have been having an issue with trying to get this module working correctly. I believe it is the way I am laying out the code. I have seen some solutions from Kai and he seems to have a very good handle on it so hoping he will view this one.

here is my code I am running ansible 2.3.0 and Python 2.7.5 PyVmomi, ESX6.2 

---
   - hosts: all
     tasks:
     - name: Create Snapshot
       vmware_guest_snapshot:
         datacenter: development
         hostname: vmwprtvcnp01.gartner.com
         username: joedoe 
         password: xxxxxxxx
         name: "{{ ansible_hostname }}"
         uuid: "{{ ansible_product_uuid }}"
         state: present
         snapshot_name: test1
         description: patch_snapshot
         validate_certs: no
       delegate_to: localhost

This is my output from the script
TASK [Create Snapshot] **************************************************************************************************************************************
  sk path: /opt/app/ansible/takesnapshot.yml:4
â–½ng module file /usr/lib/python2.7/site-packages/ansible/modules/cloud/vmware/vmware_guest_snapshot.py
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: root
<localhost> EXEC /bin/sh -c 'echo ~ && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1494940355.72-199873804086186 `" && echo ansible-tmp-1494940355.72-199873804086186="` echo /root/.ansible/tmp/ansible-tmp-1494940355.72-199873804086186 `" ) && sleep 0'
<localhost> PUT /tmp/tmpGpeLXa TO /root/.ansible/tmp/ansible-tmp-1494940355.72-199873804086186/vmware_guest_snapshot.py
<localhost> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1494940355.72-199873804086186/ /root/.ansible/tmp/ansible-tmp-1494940355.72-199873804086186/vmware_guest_snapshot.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python2 /root/.ansible/tmp/ansible-tmp-1494940355.72-199873804086186/vmware_guest_snapshot.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1494940355.72-199873804086186/" > /dev/null 2>&1 && sleep 0'
fatal: [crmdvtsrch01.gartner.com -> localhost]: FAILED! => {
    "changed": false, 
    "failed": true, 
    "invocation": {
        "module_args": {
            "datacenter": "development", 
            "description": "patch_snapshot", 
            "folder": "/vm", 
            "hostname": "vmwprtvcnp01.gartner.com", 
            "name": "crmdvtsrch01", 
            "name_match": "first", 
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", 
            "snapshot_name": "test1", 
            "state": "present", 
            "username": "gartner\\rgarrow-admin", 
            "uuid": "4232D73D-4FAC-38C0-2F29-75A2B1A478B8", 
            "validate_certs": false
        }
    }
}

MSG:

Unable to manage snapshots for non-existing VM crmdvtsrch01

        to retry, use: --limit @/opt/app/ansible/takesnapshot.retry

PLAY RECAP **************************************************************************************************************************************************
crmdvtsrch01.gartner.com   : ok=1    changed=0    unreachable=0    failed=1  

ameri...@optonline.net

unread,
May 16, 2017, 3:04:08 PM5/16/17
to Ansible Project
I have an update I ran this code through http://www.yamllint.com/ which verifies the code so here is the code 
--- 
  hosts: localhost
  tasks: 
    - 
      delegate_to: localhost
      name: "Create Snapshot"
      vmware_guest_snapshot: 
        datacenter: development
        description: patch_snapshot
        folder: default
        hostname: vmdatacenter.companyname.com
        name: "{{ ansible_hostname }}"
        password: xxxxxxx
        snapshot_name: test1
        state: present
        username: valid user to connect to the virtual center
        uuid: "{{ ansible_product_uuid }}"
        validate_certs: false

And I still get unable to manage snapshots for non-existing vm servername

Kai Stian Olstad

unread,
May 17, 2017, 1:39:52 PM5/17/17
to ansible...@googlegroups.com
On 16. mai 2017 15:19, ameri...@optonline.net wrote:
> Hi all,
>
> I have been having an issue with trying to get this module working
> correctly. I believe it is the way I am laying out the code. I have seen
> some solutions from Kai and he seems to have a very good handle on it so
> hoping he will view this one.
>
> here is my code I am running ansible 2.3.0 and Python 2.7.5 PyVmomi, ESX6.2
>
> ---
> - hosts: all
> tasks:
> - name: Create Snapshot
> vmware_guest_snapshot:
> datacenter: development
> hostname: vmwprtvcnp01.gartner.com
> username: joedoe
> password: xxxxxxxx
> name: "{{ ansible_hostname }}"
> uuid: "{{ ansible_product_uuid }}"
> state: present
> snapshot_name: test1
> description: patch_snapshot
> validate_certs: no
> delegate_to: localhost
>

<snip>

> fatal: [crmdvtsrch01.gartner.com -> localhost]: FAILED! => {
> "changed": false,
> "failed": true,
> "invocation": {
> "module_args": {
> "datacenter": "development",
> "description": "patch_snapshot",
> "folder": "/vm",
> "hostname": "vmwprtvcnp01.gartner.com",
> "name": "crmdvtsrch01",
> "name_match": "first",
> "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
> "snapshot_name": "test1",
> "state": "present",
> "username": "gartner\\rgarrow-admin",
> "uuid": "4232D73D-4FAC-38C0-2F29-75A2B1A478B8",
> "validate_certs": false
> }
> }
> }
>
> MSG:
>
> Unable to manage snapshots for non-existing VM crmdvtsrch01
>
> to retry, use: --limit @/opt/app/ansible/takesnapshot.retry

It's nothing wrong with your Ansible syntax.
The code runs and it clearly say it can't find the VM "crmdvtsrch01",
does it exist?

--
Kai Stian Olstad

ameri...@optonline.net

unread,
May 17, 2017, 2:25:36 PM5/17/17
to Ansible Project
Hi Kai,

First thanks for taking the time to have a look at my issue.

Yes the server does exist I have tried various servers which are all located on the esx servers but they all give the same results..
Richg


On Tuesday, May 16, 2017 at 9:19:06 AM UTC-4, ameri...@optonline.net wrote:

ameri...@optonline.net

unread,
May 17, 2017, 4:57:11 PM5/17/17
to Ansible Project
Hi Kai,

Just to followup I have now tried different Datacenters, different Virtual Centers, and different users and I still get the same result. But vmware_vm_facts works fine. I trying the vmware mods to see if I can figure it out. Any suggestions or help would be really appreciated. thanks,

I am at a total loss.. could it be a network or firewall or port issue. I can validate via ping to each VM Guest. But 

Kai Stian Olstad

unread,
May 18, 2017, 4:10:10 AM5/18/17
to ansible...@googlegroups.com
On 17.05.2017 22:57, ameri...@optonline.net wrote:
> Hi Kai,
>
> Just to followup I have now tried different Datacenters, different
> Virtual
> Centers, and different users and I still get the same result. But
> vmware_vm_facts works fine. I trying the vmware mods to see if I can
> figure
> it out. Any suggestions or help would be really appreciated. thanks,
>
> I am at a total loss.. could it be a network or firewall or port issue.
> I
> can validate via ping to each VM Guest. But

It's most likely a wrong combination of datacenter:, name: and uuid:
since it can't find the VM.

Is {{ ansible_hostname }} the same name it's called in Vmware? Is the
UUID correct?

Vmware is case sensitive, is the case correct in datacenter:, name: and
uuid: ?

--
Kai Stian Olstad

ameri...@optonline.net

unread,
May 18, 2017, 9:11:21 AM5/18/17
to Ansible Project, ansible-pr...@olstad.com
Hi Kai,

Thank you for taking the time to review and reply. I thought the same thing yesterday and ran through every option I could think of. the funny part about the module is it states in the documentation that UUID is not required but if I run it with out the UUID I get a different result. I will run give it another try today.  Not sure if you know much about the VC can there be a incompatibility with pyvmomi and the VC we are running 6.0 VC. I did check and pyvmomi will go back 4 version so that should be good. Sorry running through everything in my head.. 

Thanks again. I will update later today.. 
richg 

Kai Stian Olstad

unread,
May 18, 2017, 11:12:28 AM5/18/17
to ansible...@googlegroups.com
On 18. mai 2017 15:11, ameri...@optonline.net wrote:
> Hi Kai,
>
> Thank you for taking the time to review and reply. I thought the same thing
> yesterday and ran through every option I could think of. the funny part
> about the module is it states in the documentation that UUID is not
> required but if I run it with out the UUID I get a different result.

Have you read this one?

"vmware_guest_snapshot don't find vm if not folder is specified"
https://github.com/ansible/ansible/issues/22644


--
Kai Stian Olstad

ameri...@optonline.net

unread,
May 18, 2017, 1:41:21 PM5/18/17
to Ansible Project, ansible-pr...@olstad.com
Thank you sir that is the exact issue I am having. I wish folks would be more forth coming with issues with the modules it would make things a little easier. 

I am trying to understand the folder structure of the VC as when I run the PB with folder I get back vm/foldername 

ameri...@optonline.net

unread,
May 18, 2017, 3:50:48 PM5/18/17
to Ansible Project, ansible-pr...@olstad.com
Hi all here is the solution to this issue I really hope this helps the next poor person who has to bang there head for weeks trying to figure this one out.

---
   - hosts: all
     tasks:
     - name: Create Snapshot
       vmware_guest_snapshot:
         datacenter: Development
         hostname: virtual server name
         folder: /DVT-UX
         username: John doe
         password: xxxxxx
         name: "{{ ansible_hostname }}"
         uuid: "{{ ansible_product_uuid | lower }}"
         state: present
         snapshot_name: test1
         description: patch_snapshot
         validate_certs: false
       delegate_to: localhost
This does work I have confirmed it. 
I really do want to thank Kai for all his help on this I really owe you one sir.. 
I will update this later with the final playbook we are trying to patch our servers using ansible. if physical patch if virtual take snapshot then patch, reboot if needed.

Thanks.. 
Message has been deleted

Jörg Kastning

unread,
May 31, 2017, 9:03:05 AM5/31/17
to Ansible Project, ansible-pr...@olstad.com
Hi,

In your playbook you have specified:

        name: "{{ ansible_hostname }}"
        uuid: "{{ ansible_product_uuid | lower }}"

Did that mean, that you take a snapshot from all of your VMs in the specified folder?

Regards,
Joerg

richard garrow

unread,
May 31, 2017, 4:06:32 PM5/31/17
to ansible...@googlegroups.com, Ansible Project, ansible-pr...@olstad.com

Hi Joerg,

Yes if you have a list of servers in a host file then it will walk through each server and create a snap shot for you. I am using this for patching on my ESX host servers I find a folder to be a pain but have no other choice.

Let me know if you have any other issues

richg
--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/1kE0sD8L3NY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/9556f5e3-9f90-4465-9cb5-2d4992597e9b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jörg Kastning

unread,
Feb 2, 2019, 5:54:02 AM2/2/19
to Ansible Project
Hello Richard,
although this thread is somewhat old I hope you are still reading here and have some advise for me, because I'm going to accomplish the same task.

I'll have some virtual machines in my vSphere environment which I like to:
  1. Take a snapshot and if successful
  2. Run task that installs updates on guest os
  3. Reboot guest if necessary
My problem is, that my VMs are not in the same folder. They are spread across the cluster in many different folders. But because they are not too many I would be able to specify them manually by name or uuid.

Looking around for someone who has already solved this I found your post and was hoping you could give me some advise here. Do you have for any chance a working solution you could share?

Best regards,
Joerg
Reply all
Reply to author
Forward
0 new messages