2

Looking through the documentation for Arista EOS - the configuration replace command was only introduced in 4.14, leaving <4.14 without any form of replacing configurations (versus simply merging).

Short of using manual commands, what is the preferred way to load a configuration from file on EOS <=4.13 which will replace the running configuration entirely.

Here's an example,

running-config

! device: arista-test (DCS-7124S, EOS-4.13.10M)
!
! boot system flash:EOS.swi
!
transceiver qsfp default-mode 4x10G
!
hostname arista-test
ip name-server vrf default 8.8.8.8

new-config

! device: arista-test (DCS-7124S, EOS-4.13.10M)
!
! boot system flash:EOS.swi
!
transceiver qsfp default-mode 4x10G
!
hostname arista-test-new

Then run copy flash:new-config running-config and the output will be,

! device: arista-test (DCS-7124S, EOS-4.13.10M)
!
! boot system flash:EOS.swi
!
transceiver qsfp default-mode 4x10G
!
hostname arista-test-new
ip name-server vrf default 8.8.8.8

Whereas the desired output would be,

! device: arista-test (DCS-7124S, EOS-4.13.10M)
!
! boot system flash:EOS.swi
!
transceiver qsfp default-mode 4x10G
!
hostname arista-test-new
1

I wrote up a small bash script to automate this process using an Arista alias to call it.

Create the directory /mnt/flash/bin and within it create the following file,

config-replace

#!/bin/bash

APPLY_CHANGES=1

ARCHIVE_RETENTION=30
CONFIG_ARCHIVE="/mnt/flash/config"
TMP_DIR="/var/tmp"

NEW_CONFIG="$1"
RUNNING_CONFIG="/mnt/flash/config/.running-config"
TMP_CONFIG="/var/tmp/new-config"

function error()
{
    echo "$@"
    exit 0
}

function cli()
{
    FastCli -p15 -c "$@"
}

function cleanup()
{
    [ -f "$TMP_CONFIG" ] && rm $TMP_CONFIG
}

trap cleanup EXIT

[ -z "$NEW_CONFIG" ] && error "Configuration file must be set"
[ ! -f "$NEW_CONFIG" ] && error "Configuration file ($NEW_CONFIG) doesn't exist"
[ ! -d "$CONFIG_ARCHIVE" ] && mkdir -p $CONFIG_ARCHIVE

# Backup existing configuration to a file
[ ! -f "/mnt/flash/config/.running-config" ] && UPDATE_RUNNING_CONFIG=1
[ -n "$UPDATE_RUNNING_CONFIG" ] && cli "copy running-config file:/mnt/flash/config/.running-config"

DIFF_PRINT=$(diff -up -I 'last modified at' $RUNNING_CONFIG $NEW_CONFIG)
[ $(echo "$DIFF_PRINT" | wc -l) -le 1 ] && error "Configuration is the same, no changes made"

# Show the existing differences
echo "$DIFF_PRINT"
echo "---"
read -p "Do you want to apply the changes? [y/N]: " APPLY

[[ ! "$APPLY" == "y" ]] && error "Aborted"

diff -I 'last modified at' \
--new-line-format='%l
' \
--old-line-format='no %l
' \
--unchanged-line-format='%l
' \
$RUNNING_CONFIG $NEW_CONFIG | \
sed -E '/^no !$/d; /^$/d; s/^no\s{3}/   no/g' > $TMP_CONFIG

NEGATE_LINE=
while IFS='' read LINE; do
    if [[ "$LINE" == "no"* ]]; then
        NEGATE_LINE=1
    elif [ -n "$NEGATE_LINE" ] && [[ "$LINE" == "   "* ]]; then
        continue
    else
        NEGATE_LINE=
    fi
    echo "$LINE"
done < $TMP_CONFIG > $TMP_CONFIG.tmp
mv $TMP_CONFIG{.tmp,}

if [ -n "$APPLY_CHANGES" ]; then

    cli "copy file:$TMP_CONFIG running-config"

    # Backup and rotate configurations
    while read FILE; do
        IFS='.' read -ra FILE_PARTS <<< "$FILE"
        NEW_FILE="/mnt/flash/config/arista.conf.$(( ${FILE_PARTS[2]} + 1 )).gz"
        mv $FILE $NEW_FILE
        [ -z "$LAST_FILE" ] && LAST_FILE=$NEW_FILE
    done < <(find /mnt/flash/config -type f -name "*.gz" | sort -Vr)
    [ -f "$LAST_FILE" ] && rm $LAST_FILE
    gzip -c /mnt/flash/config/.running-config > $CONFIG_ARCHIVE/arista.conf.0.gz

    find /mnt/flash/config -type f -name "*.gz" | tail -n+${ARCHIVE_RETENTION} | xargs rm
    rm /mnt/flash/config/.running-config

fi

exit
alias load "bash /mnt/flash/bin/config-replace %1"

Then from the CLI interface - add the alias

enable
conf term
alias load "bash /mnt/flash/bin/config-replace %1"
write
end

Then to use the new command, just upload a new configuration file to a location of your choosing - and from the run environment just call the load command.

Eg.

arista-test# load /mnt/flash/startup-config

Copy completed successfully.
--- /mnt/flash/config/.running-config   2016-04-06 16:46:09.000000000 +0100
+++ /mnt/flash/startup-config   2016-04-06 16:43:46.000000000 +0100
@@ -1,13 +1,13 @@
-! device: arista-sw1 (DCS-7124S, EOS-4.13.10M)
+! Startup-config last modified at  Wed Apr  6 16:06:56 2016 by admin
+! device: arista-test (DCS-7124S, EOS-4.13.10M)
 !
 ! boot system flash:EOS.swi
 !
-hostname arista-test
-ip name-server vrf default 8.8.8.8
+hostname arista-test-new
---
Do you want to apply the changes? [y/N]:

Then if you press y - it will apply the differentiated changes (including negating the respective commands) - and create a configuration backup in /mnt/flash/config for up to $ARCHIVE_RETENTION versions.

This is inspired from the JunOS approach, so its likely I'll write a rollback alias too.

Its a shame Arista is lacking these basic configuration management tools.


Find the script here, https://gist.github.com/anonymous/51d86cb90e51683ee417317aee86f306

1
  • You should accept your answer so that the question doesn't keep popping up forever, looking for an answer.
    – Ron Maupin
    Aug 4 '16 at 17:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.