Help with "vmware_guest_snapshot"

14 views
Skip to first unread message

KJoubert1966

unread,
Jan 29, 2020, 3:29:24 PM1/29/20
to Ansible Project

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

KJoubert1966

unread,
Jan 29, 2020, 4:48:36 PM1/29/20
to Ansible Project
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?

Kai Stian Olstad

unread,
Jan 30, 2020, 2:22:04 AM1/30/20
to ansible...@googlegroups.com
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

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages