-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathuclalib_vmware_snapshot_report.yml
74 lines (65 loc) · 2.45 KB
/
uclalib_vmware_snapshot_report.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
---
###############################################################################
# Playbook for VMware Guest Snapshot Reporting
# --------------------------------------------
#
# This playbook will list all snapshots
#
###############################################################################
- name: uclalib_vmware_snapshot_report.yml
hosts: "{{ rhel_inventory_host_group | default('unattended_yum_update') }}"
gather_facts: false
vars:
vcenter_hostname: vc.library.ucla.edu
vsphere_datacenter: "Library Information Technology"
vsphere_domain: "ad.library.ucla.edu"
vsphere_username: "{{ vmware_user }}@{{ vsphere_domain }}"
vsphere_password: "{{ vmware_password }}"
vsphere_folder: "/"
# for python3
# date_format_snapshot: "%Y-%m-%dT%H:%M:%S.%f%z"
# for python2, assuming UTC
date_format_snapshot: "%Y-%m-%dT%H:%M:%S.%f+00:00"
date_format_display: "%Y-%m-%d %H:%M"
report_pathname: '/tmp/snaps.txt'
tasks:
- name: Gathering Facts
setup:
fact_path: omit
gather_subset: "!all,virtual"
- name: Use standard python
set_fact:
ansible_python_interpreter: /usr/libexec/platform-python
- name: Get Snapshots
vmware_guest_snapshot_info:
datacenter: "{{ vsphere_datacenter }}"
folder: "{{ vsphere_folder }}"
hostname: "{{ vcenter_hostname }}"
password: "{{ vsphere_password }}"
name: "{{ ansible_hostname }}"
username: "{{ vsphere_username }}"
validate_certs: false
connection: local
register: snapshots
changed_when: snapshots.guest_snapshots.snapshots is defined
notify: Save Report
when:
- ansible_virtualization_type == "VMware"
handlers:
- name: Save Report
lineinfile:
line: '{{ inventory_hostname }}: ({{ (item.creation_time | to_datetime(date_format_snapshot)).strftime(date_format_display) }}) {{ item.name }}'
# Python3 will be able to convert to the local timezone
#msg: '{{ inventory_hostname }}: ({{ (item.creation_time | to_datetime(date_format_snapshot)).astimezone().strftime(date_format_display) }}) {{ item.name }}'
path: '{{ report_pathname }}'
create: true
state: present
connection: local
notify: Print Report
loop: '{{ snapshots.guest_snapshots.snapshots }}'
- name: Print Report
debug:
msg: '{{ item }}'
with_file:
- '{{ report_pathname }}'
run_once: true