Archive

Posts Tagged ‘config’

RANCID for mass configuration changes

April 21, 2014 Leave a comment

*This script is for RANCID only.

1) mkdir device-lists in rancid homedir.
2) create a file with list of devices (one per line), save the file as syslog-changes.dl into device-lists folder.
3) mkdir change-scripts in rancid homedir.
4) create a file with the changes (as the way you type them in switches), save the file as syslog-changes.cs into change-scripts folder.
5) create a file config-push.sh and save it into etc folder under rancid homedir.
6) copy and paste the following scripts into the file config-push.sh that you had created on step 5.
7) command to test the script, sh config-push.sh

#!/usr/local/bin/bash
#
# The purpose of this script is to automate configuration changes to a
# large number of devices. The script identifies the device list, as well
# as the change script, and then pushes the changes one by one.
#

CLOGINPATH=”/usr/local/rancid/bin/clogin” 
CREDENTIALS=”/usr/local/rancid/.cloginrc” 
DEVICELISTPATH=”/usr/local/rancid/device-lists/” 
CHANGESCRIPTPATH=”/usr/local/rancid/change-scripts/” 
CHANGELOG=”/usr/local/rancid/var/logs/changelog-`date +%m-%d-%Y`.log” 

clear 
echo “=====[ Rancid Config Push Script ]=====” 
echo “” 
echo “Please enter the proposed device list:” 
echo “`ls $DEVICELISTPATH`” 
echo “————————————–” 
echo -n “> ” 
read DEVICELIST 

if [ -f $DEVICELISTPATH$DEVICELIST ] 
then 
echo “” 
echo “Device List = \”./device-lists/$DEVICELIST\” (confirmed)” 
else 
echo “” 
echo “Device list = \”./device-lists/$DEVICELIST\” (does not exist!)” 
echo “Aborting…” 
echo “” 
exit 
fi 

echo “” 
echo “Please enter name of change script:” 
echo “`ls $CHANGESCRIPTPATH | grep -v “.sh” | grep -v “device-lists”`” 
echo “———————————–” 
echo -n “> ” 
read CHANGESCRIPT 

if [ -f $CHANGESCRIPTPATH$CHANGESCRIPT ] 
then 
echo “” 
echo “Change Script = \”./change-scripts/$CHANGESCRIPT\” (confirmed)” 
echo “” 
else 
echo “Device list = \”./change-scripts/$CHANGESCRIPT\” (does not exist!)” 
echo “Aborting…” 
echo “” 
exit 
fi 

echo “– Proposed Changes –” 
echo “`cat $CHANGESCRIPTPATH$CHANGESCRIPT`” 
echo “– Proposed Changes –” 
echo “” 
echo “Are you sure you want to proceed? If so, type \”yes\”:” 
echo -n “> ” 
read AREYOUSURE 

if [ $AREYOUSURE != “yes” ] 
then 
echo “” 
echo “Aborting…” 
echo “” 
exit 
else 
echo “” 
echo “Implementing Changes…” 
echo “” 
fi 

#for i in `cat $DEVICELISTPATH$DEVICELIST` 
# do echo “===[ $i ]===”
# $CLOGINPATH -f $CREDENTIALS -x $CHANGESCRIPTPATH$CHANGESCRIPT $i
#done 

for DEVICE in `cat $DEVICELISTPATH$DEVICELIST` 
do 
echo “===[ $DEVICE ]===” 
echo “” >> $CHANGELOG 
echo “===[ $DEVICE ]===” >> $CHANGELOG 
echo “” >> $CHANGELOG 
OUTPUT=`$CLOGINPATH -f $CREDENTIALS -x $CHANGESCRIPTPATH$CHANGESCRIPT $DEVICE` 
echo “$OUTPUT” >> $CHANGELOG 
done 

Advertisements
Categories: Cisco, Linux, Switch Tags: , ,