This repository has been archived by the owner on Oct 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
puppet-ls
executable file
·103 lines (82 loc) · 2.48 KB
/
puppet-ls
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
#!/bin/bash
# tested on 0.25 and 3.8.4
usage () {
cat<<EOU
$appname - Copyright (c) 2011 Dean Wilson - Licensed under the GPLv2
$appname lists files that puppet is currently managing in the given
directory. Without arguments $appname shows the files in the current
working directory.
The directory to check should always be the last argument.
Usage: $appname [-r] [-R] [-i] [directory]
-i
Invert the check and show files that puppet isn't managing.
-r
Show all puppet managed files in the given directory and subdirectories
-R
Show all puppet managed files in the given directory and subdirectories,
following symbolic links
-h
This help and usage information.
Usage: $appname
Examples:
# show all puppet managed files in the /etc/mcollective directory.
$appname /etc/mcollective
# show all unmanaged files in /etc/nagios and any subdirectories
$appname -r -i /etc/nagios/
EOU
exit 0
}
#################################################################
appname=$(basename "$0")
comm='comm -12'
while getopts 'irRh' option
do
case $option in
i ) comm='comm -13' ;;
r ) recursive=1 ;;
R ) follow_links=1 ;;
h ) usage ;;
* ) usage
esac
done
# grab the non-getopts option
shift $((OPTIND - 1))
target="${1-$(pwd)}"
target="${target%/}"
if [ -n "$follow_links" ];then
lister="find -L $target"
elif [ -n "$recursive" ];then
lister="find $target"
else
lister="ls -d1 $target/*"
fi
# Tests which puppet, if any is in use
if [ -d /var/opt/lib/pe-puppet ]; then
# Puppet Enterprise, pre 4.x
vardir='/var/opt/lib/pe-puppet'
elif [ -d /var/lib/puppet ]; then
# Puppet pre 4.x
vardir='/var/lib/puppet'
elif [ -d /opt/puppetlabs/puppet/cache ]; then
# Puppet 4.x
vardir='/opt/puppetlabs/puppet/cache'
else
# Not running puppet?
echo "Cannot find a puppet agent state in the standard places."
exit 1
fi
if [ ! -r ${vardir}/state/state.yaml ]; then
echo "Cannot read puppet agent state. Try sudo?"
exit 1
fi
catalog_filelist=$(mktemp -q "/tmp/$appname.XXXXXX")
lister_filelist=$(mktemp -q "/tmp/$appname.XXXXXX")
# better clean up
trap "rm -f $catalog_filelist $lister_filelist" 0 1 2 15
# get files puppet knows about - you might not need both of these.
(
grep -h "title: /" "$vardir/state/last_run_report.yaml" | awk '{ print $NF }' ;
sed -e '/File\[/!d' -e 's/File\[//' -e 's/\]://' -e 's/ //g' < ${vardir}/state/state.yaml
) | sort > "$catalog_filelist"
$lister | sort > "$lister_filelist"
$comm "$catalog_filelist" "$lister_filelist"