01-20-2025 06:16 AM
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
Solved! Go to Solution.
01-20-2025 06:28 AM
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
01-20-2025 06:28 AM
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
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide