-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathveeam_backup_list_to_csvs.yml
107 lines (91 loc) · 3.59 KB
/
veeam_backup_list_to_csvs.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
---
- name: Get info on VEEAM backup tags from vSphere and save to CSV
hosts: localhost
vars_files:
- ../../group_vars/vsphere/vault.yml
- ../../group_vars/vsphere/{{ runtime_env | default('staging') }}.yml
tasks:
- name: Gather info from vSphere on VMs, tags, and storage
community.vmware.vmware_vm_info:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: false
show_tag: true
show_allocated: true
vm_type: vm
register: vms_and_tags
- name: Find all unique tags
ansible.builtin.set_fact:
unique_tags: "{{ vms_and_tags.virtual_machines | map(attribute='tags') | flatten | map(attribute='name') | unique }}"
- name: Create CSV file for tags
copy:
dest: "/var/www/html/esxi/incoming/tags_report.csv"
content: "Tag\n"
delegate_to: localhost
- name: Append tags to CSV
lineinfile:
path: "/var/www/html/esxi/incoming/tags_report.csv"
line: "{{ item }}"
create: yes
state: present
loop: "{{ unique_tags }}"
delegate_to: localhost
- name: Append report date and time to tags CSV
lineinfile:
path: "/var/www/html/esxi/incoming/tags_report.csv"
line: "Report Date/Time {{ lookup('pipe', \"date '+%m.%d.%Y %H:%M'\") }}"
create: yes
state: present
delegate_to: localhost
- name: Find VMs without tags
ansible.builtin.set_fact:
untagged_vms: "{{ vms_and_tags.virtual_machines | rejectattr('tags') | map(attribute='guest_name') }}"
- name: Create CSV file for VMs without tags
copy:
dest: "/var/www/html/esxi/incoming/untagged_vms_report.csv"
content: "VM Name\n"
delegate_to: localhost
- name: Append untagged VMs to CSV
lineinfile:
path: "/var/www/html/esxi/incoming/untagged_vms_report.csv"
line: "{{ item }}"
create: yes
state: present
loop: "{{ untagged_vms }}"
delegate_to: localhost
- name: Append report date and time to untagged VMs CSV
lineinfile:
path: "/var/www/html/esxi/incoming/untagged_vms_report.csv"
line: "Report Date/Time {{ lookup('pipe', \"date '+%m.%d.%Y %H:%M'\") }}"
create: yes
state: present
delegate_to: localhost
- name: Find VMs with tags
ansible.builtin.set_fact:
tagged_vms: "{{ vms_and_tags | community.general.json_query(not_null) }}"
vars:
not_null: "virtual_machines[?not_null(tags)]"
- name: Create a dict of fields we want from tagged VMs
ansible.builtin.set_fact:
slim_tagged_vms: "{{ tagged_vms | community.general.json_query('[*].{Tag_name: tags[0].name, VM_name: guest_name, Disk_size: allocated.storage}') }}"
- name: Create CSV file for VMs with tags
copy:
dest: "/var/www/html/esxi/incoming/tagged_vms_report.csv"
content: "Tag Name,VM Name,Disk Size in Bytes\n"
delegate_to: localhost
- name: Append tagged VMs to CSV
lineinfile:
path: "/var/www/html/esxi/incoming/tagged_vms_report.csv"
line: "{{ item.Tag_name }},{{ item.VM_name }},{{ item.Disk_size }}"
create: yes
state: present
loop: "{{ slim_tagged_vms }}"
delegate_to: localhost
- name: Append report date and time to tagged VMs CSV
lineinfile:
path: "/var/www/html/esxi/incoming/tagged_vms_report.csv"
line: "Report Date/Time {{ lookup('pipe', \"date '+%m.%d.%Y %H:%M'\") }}"
create: yes
state: present
delegate_to: localhost