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.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/641c7b20-4ad9-4bb6-b70d-4466cf92fa3c%40googlegroups.com.

Reply via email to