# Help with "vmware\_guest\_snapshot"

**URL:** <https://forum.ansible.com/t/help-with-vmware-guest-snapshot/32091>\
**Category:** Ansible Project\
**Created:** [January 29, 2020, 8:29pm UTC](https://forum.ansible.com/t/help-with-vmware-guest-snapshot/32091 "2020-01-29T20:29:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![KJoubert1966](https://avatars.discourse-cdn.com/v4/letter/k/aca169/32.png) [@KJoubert1966](https://forum.ansible.com/u/KJoubert1966)\
**Post date:** [January 29, 2020, 8:29pm UTC](https://forum.ansible.com/t/help-with-vmware-guest-snapshot/32091/1 "2020-01-29T20:29:23Z")

</div>

I am not a programmer and very new to Ansible, but I have written a playbook that allows me to create snapshots of all the VMs on a Vcenter…

```auto
---
- name: prepare for snapshots
  hosts: PROD_local_vmware_vcenter
  gather_facts: false
  vars_prompt:
  - name: "vcname"
    prompt: "Enter VCenter hostname"
    private: no
  - name: "vcuser"
    prompt: "Enter VCenter username"
    private: no
  - name: "vcpass"
    prompt: "Enter VCenter password"
    private: yes
  - name: "snapname"
    prompt: "What snapshot name to use?"
    private: no
  tasks:
    - name: list virtual machines
      vmware_vm_facts:
        hostname: "{{ vcname }}"
        username: "{{ vcuser }}"
        password: "{{ vcpass }}"
        validate_certs: False
      delegate_to: localhost
      register: vmfacts
    - name: create daily snapshot
      vmware_guest_snapshot:
        hostname: "{{ vcname }}"
        username: "{{ vcuser }}"
        password: "{{ vcpass }}"
        validate_certs: False
        datacenter: ha_datacenter
        folder: "/ha_datacenter/vm/"
        name: "{{ item.guest_name }}"
        state: present
        snapshot_name: "{{ snapname }}"
        description: manual ansible snap
      with_items: "{{ vmfacts.virtual_machines }}"
      delegate_to: localhost

```

1. I feel like a 5 year old and this is my macaroni art. Be nice to me. 🙂
2. any suggestions on a more efficient way to accomplish the same thing, are very welcome
3. I would like to be able to execute something similar, but for a subset of VM’s. Any suggestions on how to pass a list of VMs or filter the list for a subset?

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![KJoubert1966](https://avatars.discourse-cdn.com/v4/letter/k/aca169/32.png) [@KJoubert1966](https://forum.ansible.com/u/KJoubert1966)\
**Post date:** [January 29, 2020, 9:48pm UTC](https://forum.ansible.com/t/help-with-vmware-guest-snapshot/32091/2 "2020-01-29T21:48:35Z")

</div>

Is there by any chance a way to reference an Inventory group from /etc/ansible/hosts and pass that to a variable that “vmware\_guest\_snapshot” can use?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [January 30, 2020, 7:21am UTC](https://forum.ansible.com/t/help-with-vmware-guest-snapshot/32091/3 "2020-01-30T07:21:43Z")

</div>

You mean something like groups['mygroup'] which is a list of all hosts in the group mygroup?

[https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_variables.html#accessing-information-about-other-hosts-with-magic-variables](https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#accessing-information-about-other-hosts-with-magic-variables)
