cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
252
Views
0
Helpful
1
Replies

Substring a system variable in Jinja template

saschakruszka
Level 1
Level 1

Hello,

I'm currently building some DayN Templates to configure non fabric Catalyst 9k2 switches.
Therfore I'm using the system variable __device.hostname to get the name of the current device. Within this name I've got some information I'd like to use, e.g. the hostname contains the device location. So I try to substring this information with the following Jinja code:

{% set device_location = __device.hostname[2:5] %}

Nothing special, i thought but... I realized I was not able to commit the template, because of the following error appears in the Template Editor of the Catalyst Center for the line of code I did provide here.

The error message: "Target unreachable, base expression '. hostname' resolved to null"

Within the simulation this code works as it should do, but this error prevent to commit the template.

If I use the __device.hostname variable without the [2:5] subtring filter, there is no error, but the error persist, when I'm using the string within a non system variable with the substring filter like this:

{% set device_name = __device.hostname %}

{% set device_location = device_name[2:5] %}

Example string/hostname = yyxxx001

Catalyst Center Version 2.3.7.6

Doese anyone know what I'm doing wrong? Anyone experiencing the same behaviour of the Catalyst Center Template Editor?

BR

Sascha

 

1 Accepted Solution

Accepted Solutions

saschakruszka
Level 1
Level 1

Okay,


This was a variable type issue. After posting this issue I was thinking about it and was trying the following:

{% set device_name = __device.hostname|string %}
{% set device_location = device_name[2:5] %}

Converting __device.hostname to a string with the |string filter works.

Hope this helps somebody else.

BR

Sascha

View solution in original post

1 Reply 1

saschakruszka
Level 1
Level 1

Okay,


This was a variable type issue. After posting this issue I was thinking about it and was trying the following:

{% set device_name = __device.hostname|string %}
{% set device_location = device_name[2:5] %}

Converting __device.hostname to a string with the |string filter works.

Hope this helps somebody else.

BR

Sascha

Review Cisco Networking for a $25 gift card