Help with "vmware_guest_snapshot"

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…

---
- 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. :slight_smile:
  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.

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?

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