PackeTsar / freeztp

An Open-Source Zero-Touch Provisioning System for Cisco IOS.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

local_timestamp issue

skippybossx opened this issue · comments

when i write Installed ({{ epoch_timestamp }}) in template it gives me just nothing, installation goes trought, but its empty indise ( )

same thing with {{ local_timestamp }}, i tried also local_year, local_month, local_day, local_hour, local_minute, local_second and its the same

The point is i would like to have installation date inside there, but i don't know why is it not working? or how to use it properly

Agreed. Time is not being passed to the Jinja2 engine. Tried the following variations in a dummy template:

Test: ! {{ now() }}
Result: jinja2.exceptions.UndefinedError: 'now' is undefined

Test: ! {{ time.strftime("%H:%M:%S", time.localtime()) }}
Result: jinja2.exceptions.UndefinedError: 'time' is undefined

Test Line 1: ! {% set t=time.strftime("%H:%M:%S", time.localtime()) %}
Test Line 2: ! {{ t }}
Result: jinja2.exceptions.UndefinedError: 'time' is undefined

A merge test shows that there are no time variables in the variable set (see below). Attempting to hack a time variable in using a GLOBAL keystore (e.g. ztp set keystore GLOBAL time "time.time()") results in a literal string being inserted as a variable, not a calculated value.

root@ztp:/home/ztpadmin# ztp request merge-test STACK1 
2021-03-29 01:17:14:   cfact.get_keystore_id: Checking Keystores and IDArrays for (STACK1)
2021-03-29 01:17:14:   cfact.get_keystore_id: Checking Keystore names for (STACK1)
2021-03-29 01:17:14:   cfact.get_keystore_id: ID (STACK1) resolved directly to a keystore
2021-03-29 01:17:14:   cfact.get_template: Looking up association for identity (STACK1)
2021-03-29 01:17:14:   cfact.get_template: Found associated template (SHORT_TEMPLATE)
2021-03-29 01:17:14:   cfact.get_template: Template (SHORT_TEMPLATE) exists in local config. Returning
Some variables in jinja template do not exist in keystore:
        -time
2021-03-29 01:17:14:   cfact.pull_keystore_values: Inserting IDArray keys
2021-03-29 01:17:14:   cfact._global_lookup: Checking if a global-keystore is configured and ready...
2021-03-29 01:17:14:   cfact._global_lookup: A global-keystore is configured (GLOBAL), checking if it exists in local config
2021-03-29 01:17:14:   cfact._global_lookup: Global keystore exists in local config. Adding and returning
2021-03-29 01:17:14:   cfact.merge_test: Merging with values:
{
    "vl1_netmask": "255.255.255.0", 
    "idarray_1": "SERIAL1", 
    "snmpinfo": {
        "WS_C3850_SERIAL_NUMBER": "WS_C3850_SERIAL_NUMBER_FAKESERIAL", 
        "WS_C2960_SERIAL_NUMBER": "WS_C2960_SERIAL_NUMBER_FAKESERIAL", 
        "matched": "FAKEMATCHEDSERIAL"
    }, 
    "idarray_2": "SERIAL2", 
    "idarray_3": "SERIAL3", 
    "vl1_ip_address": "10.0.0.200", 
    "hostname": "CORESWITCH", 
    "idarray": [
        "SERIAL1", 
        "SERIAL2", 
        "SERIAL3"
    ], 
    "GLOBAL": {
        "c9k_ver": "16.12.4", 
        "ztp_ip_addr": "192.168.1.194", 
        "c9300_ver": "16.12.4", 
        "c9200_image": "cat9k_iosxe_lite.16.12.04.SPA.bin", 
        "c9k_image": "cat9k_iosxe.16.12.04.SPA.bin", 
        "c9300_image": "cat9k_iosxe.16.12.04.SPA.bin", 
        "c9200_ver": "16.12.4"
    }
}

Let's post this as a feature request.

PSC