|
#!/bin/bash
|
|
# ------------------------------------------------------------
|
|
# script: limpia-puppet
|
|
# Author: Esteban M. Navas Martín
|
|
# Date: 21-06-2012
|
|
# Ver: 21-06-2012
|
|
# Requisito: Tener instalado puppetlast
|
|
#
|
|
# Purpose: This program cleans the following puppet node info: facts, node and certificate
|
|
#
|
|
# Copyright (c) 2012 Esteban M. Navas Martín <adminies.valledeljerte@edu.juntaextremadura.net>. All rights reserved.
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
# (at your option) any later version.
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
# Comprobamos si se han introducido la antiguedad como parámetro
|
|
if [ $# -lt 1 ]; then
|
|
ANTIGUEDADMAX="100"
|
|
else
|
|
ANTIGUEDADMAX=$1
|
|
fi
|
|
|
|
/usr/local/sbin/puppetlast > /tmp/puppetlast.tmp
|
|
|
|
while read LINEA; do
|
|
LINEACOMPLETA=$LINEA
|
|
set -- $LINEACOMPLETA
|
|
ANTIGUEDAD=$2
|
|
DIAS=$3
|
|
HOST=$5
|
|
ARCHIVO=$HOST".yaml"
|
|
|
|
if [ "$ANTIGUEDAD" -ge "$ANTIGUEDADMAX" ] && [ "$DIAS"="days" ]; then
|
|
echo $DIAS
|
|
echo "Borrando certificado puppet $ARCHIVO"
|
|
puppetca --clean $HOST
|
|
if [ -f /var/lib/puppet/yaml/facts/$ARCHIVO ]; then
|
|
rm /var/lib/puppet/yaml/facts/$ARCHIVO
|
|
echo "Borrando /var/lib/puppet/yaml/facts/$ARCHIVO con $ANTIGUEDAD días de antiguedad."
|
|
fi
|
|
if [ -f /var/lib/puppet/yaml/node/$ARCHIVO ]; then
|
|
rm /var/lib/puppet/yaml/node/$ARCHIVO
|
|
echo "Borrando /var/lib/puppet/yaml/node/$ARCHIVO con $ANTIGUEDAD días de antiguedad."
|
|
fi
|
|
fi
|
|
done < /tmp/puppetlast.tmp
|
|
|
|
rm -f /tmp/puppetlast.tmp
|