Automation Scripts

Reply
Highlighted
Accepted Solution

Script fails when changing hostname on Cisco router

Authority
Posts: 31
2467     0

When I run a CCS script to configure a router, the script fails when the hostname is changed. I've tried using a Trigger as follows, but now it exits before even trying the config. The prompt changes from "Router1" to the value entered for $SITE_ROUTER_NAME. What am I doing wrong?

 

Script-Variables:
    $SITE_NUMBER word "FIXME SITE NUMBER"
    $SITE_NAME word "FIXME SITE NAME"
    $SITE_ADDRESS word "FIXME SITE ADDRESS"
    $SITE_CIR integer 100000
    $SITE_ROUTER_NAME word "FIXME-ROUTER-NAME"
    $SITE_SWITCH_NAME word "FIXME-SWITCH-NAME"
    $SITE_SWITCH_PORT word "FIXME SWITCH PORT"
    $TrigVar word "IFTHEN"

 

Trigger: Configure Router

 

Trigger-Filter:

 

$TrigVar eq "IFTHEN"

 

Trigger-Prompt: /(Router1.*) | ($SITE_ROUTER_NAME.*)/

 

Trigger-Commands:

config terminal
version 15.4
hostname $SITE_ROUTER_NAME

etc., etc.

Re: Script fails when changing hostname on Cisco router

Expert
Posts: 228
2468     0

Did you only include part of your actual script?  What you show has no Action section so there's nothing to call the Trigger.

Re: Script fails when changing hostname on Cisco router

Authority
Posts: 31
2468     0

I only included part of it. Here's the whole script. Note that with the Trigger section, nothing happens at all. Without it, it hangs after the hostname command.

 

 

#-----------------------------------------------------------------------
# The Script-Filter is used to indicate that the entire script
# should only be executed for Cisco IOS devices.
#-----------------------------------------------------------------------
Script-Filter:
$Vendor eq "Cisco" and $sysDescr like /IOS/

#-----------------------------------------------------------------------
# Script-Variables are defined to allow the user to provide input
# to the script. In this example, the user will be prompted to
# enter a username and password prior to script execution. The
# username is defined as type "word", which means any string
# without whitespace can be entered. The password is defined as
# type "password", which means any string can be entered, however
# only stars will be displayed.
#
# The "UserName" and "Password" fields define the GUI prompts
# to be displayed to the user when the script is executed.
#-----------------------------------------------------------------------
Script-Variables:
$SITE_NUMBER word "FIXME SITE NUMBER"
$SITE_NAME word "FIXME SITE NAME"
$SITE_ADDRESS word "FIXME SITE ADDRESS"
$SITE_CIR integer 100000
$SITE_ROUTER_NAME word "FIXME-ROUTER-NAME"
$SITE_SWITCH_NAME word "FIXME-SWITCH-NAME"
$SITE_SWITCH_PORT word "FIXME SWITCH PORT"
$TrigVar word "IFTHEN"


########################################################################
Action:
Set ASE-NoD specific values from list "ase nod list".

Action-Description:
This action is executed once for every device that matches the
Script-Filter defined above.

Action-Commands:

SET: $INNER_VLAN_1 = getListValue(ASE NoD Site Parameters,SITE_NUMBER,$SITE_NUMBER,INNER_VLAN_1,NOT_FOUND)
SET: $INNER_VLAN_2 = getListValue(ASE NoD Site Parameters,SITE_NUMBER,$SITE_NUMBER,INNER_VLAN_2,NOT_FOUND)
SET: $OUTER_VLAN = getListValue(ASE NoD Site Parameters,SITE_NUMBER,$SITE_NUMBER,OUTER_VLAN,NOT_FOUND)
SET: $HOST_IP_1 = getListValue(ASE NoD Site Parameters,SITE_NUMBER,$SITE_NUMBER,HOST_IP_1,NOT_FOUND)
SET: $REMOTE_IP_1 = getListValue(ASE NoD Site Parameters,SITE_NUMBER,$SITE_NUMBER,REMOTE_IP_1,NOT_FOUND)
SET: $HOST_IP_2 = getListValue(ASE NoD Site Parameters,SITE_NUMBER,$SITE_NUMBER,HOST_IP_2,NOT_FOUND)
SET: $REMOTE_IP_2 = getListValue(ASE NoD Site Parameters,SITE_NUMBER,$SITE_NUMBER,REMOTE_IP_2,NOT_FOUND)
SET: $PREFERRED_NEIGHBOR = getListValue(ASE NoD Site Parameters,SITE_NUMBER,$SITE_NUMBER,PREFERRED_NEIGHBOR,NOT_FOUND)
expr: $SHAPE_AVERAGE = $SITE_CIR * 1000

 

Trigger: Configure Router

Trigger-Filter:

$TrigVar eq "IFTHEN"

Trigger-Prompt: /(Router1.*) | ($SITE_ROUTER_NAME.*)/

Trigger-Commands:

config terminal
version 15.4
hostname $SITE_ROUTER_NAME
service timestamps debug datetime msec localtime show-timezone year
service timestamps log datetime msec localtime show-timezone year

end
write memory
########################################################################

 

Re: Script fails when changing hostname on Cisco router

Expert
Posts: 228
2468     0

I see a couple issues with this as posted.  First, the metacharacter for word "\w" is defined as [A-Za-z0-9_].  Notice that does not include a hyphen or white space.  Yet some of your script variables have each of those.  I think you need to declare them as type "string".

 

Second, the Action does not have a Output-Trigger section so there will be no call to your trigger.  Maybe that exists but you didn't copy/paste it into your post?

 

To see what's happening during the execution, what's in the Process logic flow for the pattern matches and substitution?  And the session log?  Is the initial router prompt actually "Router1"?

 

Suggestion: to display the values of variables, use the DEBUG directive with something like:

    DEBUG SET: $my_dummy_var = $MY_VAR

Re: Script fails when changing hostname on Cisco router

Authority
Posts: 31
2468     0

I'm starting to wonder now if changing the hostname causes an issue with ssh. The final error is "

*** ERROR: Timeout waiting for device ***".

 

In any case, I declared the variables as string and added the Output-Trigger. Now the trigger is being run, but the script still hangs after the hostname command.

 

The initial prompt is indeed Router1. It changes to $SITE_ROUTER_NAME after the hostname command. See Session Log and Output Log below:

 

Warning: Permanently added '192.168.20.40' (RSA) to the list of known hosts.

 

Password:

Router1#

Router1#enable

Router1#

Router1#terminal no monitor

Router1#terminal no editing

Router1#terminal length 0

Router1#config terminal

Enter configuration commands, one per line. End with CNTL/Z.

Router1(config)#version 15.4

Router1(config)#hostname 1805VerRd1A-r

1805VerRd1A-r(config)#exit

1805VerRd1A-r#

 

*** Job Failed [1] ***

 

 

Here's the Output Log:

 

+++ Looking up device information ...................................... OK
+++ Looking up device information ...................................... OK
+++ Looking up job specification information ........................... OK
+++ Loading ccs file ................................................... OK

+++ Script: TEST2 Cisco ASE-NoD Standard Configuration
+++ [Script-Variables]
+++ $site_number = '6'
+++ $site_name = 'Emory LaGrange Surgery Center'
+++ $site_address = '1805 Vernon Rd LaGrange Ga 30240'
+++ $site_cir = '100000'
+++ $site_router_name = '1805VerRd1A-r'
+++ $site_switch_name = '1805VerRd1A-m'
+++ $site_switch_port = 'Gi2/1'
+++ $trigvar = 'IFTHEN'
+++ Script-Filter ...................................................... MATCH
MATCH
+++ Looking up authentication information .............................. OK
+++ Opening ssh session with 192.168.20.40 ............................. OK
+++ Got password prompt, sending '********' ............................ OK
+++ Prompt detect round [1] ............................................ OK
+++ Prompt type [0] round times [1] [1] ................................ OK
+++ Prompt [Router1#] verify [Router1#] ................................ OK
+++ Sending 'enable' ................................................... MATCH
OK
+++ Enable prompt detect round [1] ..................................... OK
+++ Prompt type [0] round times [1] [1] ................................ OK
+++ Prompt [Router1#] verify [Router1#] ................................ OK
+++ Sending 'terminal no monitor' ...................................... MATCH
OK
+++ Sending 'terminal no editing' ...................................... MATCH
OK
+++ Sending 'terminal length 0' ........................................ MATCH
OK

+++ 1. Action: Set ASE-NoD specific values from list "ase nod list".
+++ 1. [Action-Commands]
+++ Looking up config list information via API ......................... OK
+++ 1. SET: $inner_vlan_1 = getListValue(ASE NoD Site Parameters,SITE_NUMBER,$site_number,INNER_VLAN_1,NOT_FOUND) [406]
+++ Looking up config list information via API ......................... OK
+++ 1. SET: $inner_vlan_2 = getListValue(ASE NoD Site Parameters,SITE_NUMBER,$site_number,INNER_VLAN_2,NOT_FOUND) [606]
+++ Looking up config list information via API ......................... OK
+++ 1. SET: $outer_vlan = getListValue(ASE NoD Site Parameters,SITE_NUMBER,$site_number,OUTER_VLAN,NOT_FOUND) [806]
+++ Looking up config list information via API ......................... OK
+++ 1. SET: $host_ip_1 = getListValue(ASE NoD Site Parameters,SITE_NUMBER,$site_number,HOST_IP_1,NOT_FOUND) [10.9.21.10]
+++ Looking up config list information via API ......................... OK
+++ 1. SET: $remote_ip_1 = getListValue(ASE NoD Site Parameters,SITE_NUMBER,$site_number,REMOTE_IP_1,NOT_FOUND) [10.9.21.11]
+++ Looking up config list information via API ......................... OK
+++ 1. SET: $host_ip_2 = getListValue(ASE NoD Site Parameters,SITE_NUMBER,$site_number,HOST_IP_2,NOT_FOUND) [10.9.22.10]
+++ Looking up config list information via API ......................... OK
+++ 1. SET: $remote_ip_2 = getListValue(ASE NoD Site Parameters,SITE_NUMBER,$site_number,REMOTE_IP_2,NOT_FOUND) [10.9.22.11]
+++ Looking up config list information via API ......................... OK
+++ 1. SET: $preferred_neighbor = getListValue(ASE NoD Site Parameters,SITE_NUMBER,$site_number,PREFERRED_NEIGHBOR,NOT_FOUND) [10.9.22.10]
+++ 1. SET: $trigvar = "IFTHEN"
+++ 1. expr: $shape_average = $site_cir * 1000

+++ 1.1. Trigger: Configure Router
+++ 1.1. Trigger-Filter ................................................ MATCH
+++ 1.1. [Trigger-Commands]
+++ 1.1. Sending 'config terminal' ..................................... MATCH
OK
MATCH
+++ 1.1. Sending 'version 15.4' ........................................ MATCH
OK
MATCH
+++ 1.1. Sending 'hostname 1805VerRd1A-r' .............................. MATCH
OK
MATCH
+++ Closing session .................................................... OK

*** ERROR: Timeout waiting for device ***

 

 

Re: Script fails when changing hostname on Cisco router

Authority
Posts: 31
2468     0

Never mind the ssh question. I just tried it from the NetMRI command line and it does not hang by changing the hostname.

Re: Script fails when changing hostname on Cisco router

Authority
Posts: 31
2468     0

I was able to get this to work with the following statement:

 

Trigger-Prompt: /(.*)/

 

Also, it looks like variables are not supported in that statement, unless my syntax is wrong.

 

Thanks for your help!

 

Steve

Showing results for 
Search instead for 
Do you mean 

Recommended for You