-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinventory
More file actions
executable file
·73 lines (62 loc) · 1.72 KB
/
inventory
File metadata and controls
executable file
·73 lines (62 loc) · 1.72 KB
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
#!/bin/bash
#
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-d|--debian)
DEBIAN='true'
shift
;;
-r|--remote)
REMOTE='true'
shift
;;
-o|--other)
OTHER='true'
shift
;;
*)
;;
esac
shift
done
if [ -z $REMOTE ]; then
# Get VM and container proxmox IDs
PVE_VM_IDs=$(qm list | grep running | awk '{print $1}')
PVE_CT_IDs=$(pct list | grep running | awk '{print $1}')
# Get VM names
VMs=$(for PVE_VM_ID in $PVE_VM_IDs; do
qm status $PVE_VM_ID -verbose \
| grep 'name: ' \
| awk '{print $2}' \
| tr '[:upper:]' '[:lower:]';
done)
# Get container names
CTs=$(for PVE_CT_ID in $PVE_CT_IDs; do
pct status $PVE_CT_ID -verbose \
| grep 'name: ' \
| awk '{print $2}' \
| tr '[:upper:]' '[:lower:]';
done)
# Get proxmox hostname
HOST=$(echo "${HOSTNAME}" | tr '[:upper:]' '[:lower:]')
fi
# Get remote computer names
REMOTE_COMPUTERS=$(grep ^host ~/.ssh/config | awk '{print $NF}')
# Build unique sorted list of all computers
ALL_COMPUTERS=$(echo -e "${VMs}\n${CTs}\n${HOST}\n${REMOTE_COMPUTERS}" | sort -u)
# Debian distro names used in lsb_release command
DEBIAN_DISTROS='debian|ubuntu|elementary|deepin'
if [ "${DEBIAN}" == "true" ]; then
# Build Debian list
ALL_COMPUTERS=$(echo -e ${ALL_COMPUTERS} | pdsh -w - "lsb_release -i" 2>&1 | egrep -i "${DEBIAN_DISTROS}" | awk -F':' '{print $1}')
elif [ "${REMOTE}" == "true" ]; then
# Build remote list
ALL_COMPUTERS=$REMOTE_COMPUTERS
elif [ "${OTHER}" == "true" ]; then
# Build other list
ALL_COMPUTERS=$(echo -e "${ALL_COMPUTERS}" | pdsh -w - "lsb_release -i" 2>&1 | egrep -vi "${DEBIAN_DISTROS}" | awk -F':' '{print $1}')
fi
# Finally output the list of computers
echo -e "${ALL_COMPUTERS}"