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
- I feel like a 5 year old and this is my macaroni art. Be nice to me.
- any suggestions on a more efficient way to accomplish the same thing, are very welcome
- 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.