Variable Substitution

Learn how to use Variable Substitutions in SecuRA.

SecuRA follows Jinja2 Template engine for converting command templates into actual commands. Jinja2 Template engine provides features like:

  • Variable substitution - For substituting specific values for specific Devices.
  • Variable declaration
  • Data structures like Integer, Boolean, List, and Dictionary.
  • Loop Statements like For, While & Do While.
  • Conditional Statements like If, If Else & If Elif Else.
  • Conditional operators like =, !=, in, not in, > and >= & < and <=
Variable Substitution:

Variables are command inputs given by a user dynamically during the execution time. For example, if the user wants to change the hostname in Cisco devices, the command syntax will be as follows:

  • # hostname <New Hostname>
  • hostname is the command and <New Hostname> is the variable or input portion to hostname command.

    Through variable substitution, single template is enough to change hostname of all devices same Vendor and OS Type configured in template; else each device requires a separate template.

    To substitute a variable, follow the below steps, based on the condition applicable:

    1. Use “Double Curly Brackets” before and after the variable {{ }}, only if variable is not inside Jinja2 statements
    2.  <command prompt=”#” timeout=“5”>hostname {{Runtime.hostame}} </command >
      Runtime is a substitution object.
    3. Directly writing variable, if variable is inside Jinja2 expression statement {% %}
    4. {% if Runtime.hostname. == “router27” %}
    SecuRA Substitution Objects in Template:

    SecuRA supports the below types of substitution objects for Variable substitution within configuration template.

    1. Runtime object - Runtime object will be used in Configuration Upload and Network Diagnosis activities. Runtime object variables will be converted into user input form to get values while configuring upload task or Network Diagnosis creation.

    2. Ex: {{Runtime.hostname}}
    3. Global object - All Global parameters configured in SecuRA are available through Global object for Variable substitution.

    4. Ex: {{Global.managementIP}}
    5. Type object - Defines the field, based on the variable type specified such as Text Area, Text field, DropDown, Multi DropDown.

    6. Ex: Type.Speed=DropDown
    7. Default object - The default value for Type Object I defined here.

    8. Ex: Default.Speed=10,100,1000
    9. Remark object - Displays the Text on mouse hover on the Variable Name.

    10. Ex: Remark.Speed=enter speed of interface
    11. Optional object - If variable is declared ‘Optional’, the input for the field is not mandatory.

    12. Ex: Optional.VariableName
    13. Check object - Ensures that the Input format matches the defined format.

    14. Ex: In Textfield, it should allow only 1 to 255 ^([1-9]|[1-9][0-9]|[1-2][0-5][0-5])$
    15. LOCAL_SHELL object - LOCAL_SHELL object gets values from LOCAL_ACCOUNT profile, configured in Device credential for Variable substitution.

    16. Ex: {{LOCAL_SHELL.username}}
    17. Device object - Device object gets values from Device database of corresponding Device where command execution takes place.

    18. Ex: {{Device.IPaddress}}
    19. Interface object - Interface object gets values from Device Interface database of the corresponding Device where command execution takes place.

    20. Ex: {{}} {{Interface.description}}
    21. Job object - Job object gets values from Job Database (Upload Job) of corresponding Device where command execution takes place.

    22. Ex: {{}}
    23. Profile object - Profile object gets values from Profile Database (Configuration Profile) of corresponding Device where command execution takes place.

    24. Ex: {{Profile.user_name}}
    25. Trigger object - Trigger object gets values from Configuration Trigger Database of corresponding Trigger name used in Configuration Template.

    26. Ex: {{Trigger.triggername}} Note: A template can have more than one Trigger variable
    27. Profile object - Profile object gets values from Device Credential Database of corresponding Device (Device Credential) where command execution will take place.

    28. Ex: {{Profile.ssh_loginname}}
    29. Time object - Time object gets values from SecuRA server based on current time which is for substituting time values in a template during execution.

    30. Ex: {{}} – Time in unix epoc format {{Time.YYYYMMDD}} – Time in YYYY MM DD format {{Time.uniquestring}} – Unique string

      See how to use Conditioning & Loopingin SecuRA

      Substitution, Conditioning, Looping in Template should be in Jinja2 standard. Refer for more tutorials.
      Points to Remember:

      Always enclose the commands within {% %} for "if" and "for", "while" conditional statements.

      Always enclose the variables inside {{ }} for substitution.