[rancid] Re: using RANCID for mass configuration changes

Eric Cables ecables at gmail.com
Tue Sep 16 17:32:35 UTC 2008


I wrote a very dirty script to do this a while back.  I'm sure there
is something better out there, but this suits my needs.

You'll need a small framework in place for this to work, namely:
 - Create a directory called "device-lists" in the rancid homedir (or
wherever you'd like, just update the script VAR)
 - Create a directory called "change-scripts" in the rancid homedir
(or wherever you'd like, just update the script VAR)

Once you've done the above, simply put a file with a list of devices
(one per line) you'd like to make changes to into the device-lists
folder "syslog-changes.dl" for example, and place a file with the
changes you want to make (as you'd type them on the router) in the
change-scripts folder "syslog-changes.cs" for example.

-- Begin 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/home/rancid/bin/clogin"
CREDENTIALS="/usr/home/rancid/.cloginrc"
DEVICELISTPATH="/usr/home/rancid/device-lists/"
CHANGESCRIPTPATH="/usr/home/rancid/change-scripts/"
CHANGELOG="/usr/home/rancid/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
-- end config-push.sh --

--
Eric Cables



On Tue, Sep 16, 2008 at 9:32 AM, Daniel Medina <daniel.medina at gmail.com> wrote:
> On Tue, Sep 16, 2008 at 10:29:03AM +0400, Smirnoff Alexander wrote:
>> I want to use RANCID for mass configuration changing on routers, like
>> set snmp or syslog server address.
>>
>> What best place in RANCID scripts for this commands ?
>
>  You could just use clogin.
>
>  As a one-liner:
>
>    $ clogin -c 'conf t; snmp-server host 1.1.1.1 public; end; wr mem' router1 router2 router3
>
>  Or put the commands in a file:
>
>    $ cat /tmp/commands
>    conf t
>    snmp-server host 1.1.1.1 public
>    end
>    wr mem
>
>    $ clogin -x /tmp/commands route1 router2 router3
>
>  Caveats apply (beware of commands which may prompt you back, for example).
>
> --
> Dan
> _______________________________________________
> Rancid-discuss mailing list
> Rancid-discuss at shrubbery.net
> http://www.shrubbery.net/mailman/listinfo.cgi/rancid-discuss
>


More information about the Rancid-discuss mailing list