Variables

Blitz uses the ‘%VARIABLES{x.y.z}’ markup to allow values in action snippets to be replaced by runtime generated values from other actions. LAMP uses ‘-s’ option in its operator commands to generate variables whose values can be substituted in other commands to generate the equivalent variable markup in Blitz.

Warning

LAMP variables support dotpath access (e.g., ‘a.b’) and dictionary-style access, similar to parameters. Blitz does not support this, which can cause issues when generating pyATS automation scripts with LAMP. To ensure compatibility, avoid using dotpaths in variables if targeting Blitz.

Why variables

Variables can be used when a command argument or include/exclude entry is dynamic and only known at runtime. Variables let you pass values from one Blitz action output to another command or entry.

Basic usage

‘^’ denotes a variable in LAMP (think: inverted ‘v’ for ‘variable’). Use ‘^{<VARIABLE_NAME>}’ to substitute a value saved from another action in: device name, command argument, or include/exclude entry; LAMP replaces it with the variable’s value and adds ‘%VARIABLES{x.y.z}’ to the autogenerated Blitz action snippet.

Example:

<command> <arg1> INCLUDE> <entry1>

becomes

<command> <^{name1}> where name1 = arg1 INCLUDE> <^{name1}> where name1 = entry1

Generating variables

Variables can be generated from the outputs of execute, parse, or api commands using the ‘-s’ option. Filters can be used to extract subsets of data from action outputs.

Command output filters

LAMP command

Output type without filter

Available filters

execute

str

regex, regex_findall

parse

dict

Dq

api

api return type

Can be Dq, regex, regex_findall (depending on api return type)

Variables can be viewed with the variable list command (or use ‘^’ as a shortcut). This prints all variables as a dictionary.

(lamp-h2) variable list
{'var_1': 20}

execute

Invoking execute -s saves the output of the command as a variable:

(lamp-h2) execute -s show ip igmp groups
2025-09-06 11:01:31: %LAMP-INFO: +..............................................................................+
2025-09-06 11:01:31: %LAMP-INFO: :                    Execute 'show ip igmp groups' on 'h2'                     :
2025-09-06 11:01:31: %LAMP-INFO: +..............................................................................+

2025-09-06 11:01:31,764: %UNICON-INFO: +++ host2(alias=h2) with via 'a': executing command 'show ip igmp groups' +++
show ip igmp groups
IGMP Connected Group Membership
Group Address    Interface                Uptime    Expires   Last Reporter   Group Accounted
224.0.1.40       Ethernet0/0              00:13:50  00:02:16  1.1.1.1
host2#
2025-09-06 11:01:31: %LAMP-INFO: +..............................................................................+
2025-09-06 11:01:31: %LAMP-INFO: :                           Collecting SAVE Entries                            :
2025-09-06 11:01:31: %LAMP-INFO: +..............................................................................+
Add SAVE filter (y/N):
Enter variable name to save: igmp_grp_out

execute outputs can be filtered using regex or regex_findall.

Example using a regex filter:

(lamp-h2) execute -s show ip mroute
2025-09-06 10:48:34: %LAMP-INFO: +..............................................................................+
2025-09-06 10:48:34: %LAMP-INFO: :                       Execute 'show ip mroute' on 'h2'                       :
2025-09-06 10:48:34: %LAMP-INFO: +..............................................................................+

2025-09-06 10:48:34,864: %UNICON-INFO: +++ host2(alias=h2) with via 'a': executing command 'show ip mroute' +++
show ip mroute
IP Multicast Routing Table
Flags: D - Dense, S - Sparse, B - Bidir Group, s - SSM Group, C - Connected,
      L - Local, P - Pruned, R - RP-bit set, F - Register flag,
      T - SPT-bit set, J - Join SPT, M - MSDP created entry, E - Extranet,
      X - Proxy Join Timer Running, A - Candidate for MSDP Advertisement,
      U - URD, I - Received Source Specific Host Report,
      Z - Multicast Tunnel, z - MDT-data group sender,
      Y - Joined MDT-data group, y - Sending to MDT-data group,
      G - Received BGP C-Mroute, g - Sent BGP C-Mroute,
      N - Received BGP Shared-Tree Prune, n - BGP C-Mroute suppressed,
      Q - Received BGP S-A Route, q - Sent BGP S-A Route,
      V - RD & Vector, v - Vector, p - PIM Joins on route,
      x - VxLAN group, c - PFP-SA cache created entry,
      * - determined by Assert, # - iif-starg configured on rpf intf,
      e - encap-helper tunnel flag, l - LISP decap ref count contributor
Outgoing interface flags: H - Hardware switched, A - Assert winner, p - PIM Join
                          t - LISP transit group
Timers: Uptime/Expires
Interface state: Interface, Next-Hop or VCD, State/Mode

(*, 224.0.1.40), 00:00:46/00:02:13, RP 0.0.0.0, flags: DCL
  Incoming interface: Null, RPF nbr 0.0.0.0
  Outgoing interface list:
    Ethernet0/0, Forward/Sparse, 00:00:46/00:02:13, flags:

host2#
2025-09-06 10:48:34: %LAMP-INFO: +..............................................................................+
2025-09-06 10:48:34: %LAMP-INFO: :                           Collecting SAVE Entries                            :
2025-09-06 10:48:34: %LAMP-INFO: +..............................................................................+
Add SAVE filter (y/N): y
╭────────────────────────────╮
│ List of available filters: │
│ 1. regex                   │
│ 2. regex_findall           │
╰────────────────────────────╯
Enter filter option number/name (1/2/regex/regex_findall): 1
Enter regex expression: (?P<oif>\S+)\, Forward\/Sparse
{'oif': 'Ethernet0/0'}
Do you wish to add this regex filter (Y/n):
(lamp-h2)

LAMP prints the result of the regex filter before prompting for confirmation to save the variable. This helps verify the regex and helps debug issues.

View the generated variable with variable list:

(lamp-h2) variable list
{'oif': 'Ethernet0/0'}

parse

Dq filter can be used for parse action outputs. Example:

(lamp-h2) parse -s show ip mroute
2025-09-06 10:52:46: %LAMP-INFO: +..............................................................................+
2025-09-06 10:52:46: %LAMP-INFO: :                        Parse 'show ip mroute' on 'h2'                        :
2025-09-06 10:52:46: %LAMP-INFO: +..............................................................................+

2025-09-06 10:52:46,751: %UNICON-INFO: +++ host2(alias=h2) with via 'a': executing command 'show ip mroute' +++
show ip mroute
IP Multicast Routing Table
Flags: D - Dense, S - Sparse, B - Bidir Group, s - SSM Group, C - Connected,
      L - Local, P - Pruned, R - RP-bit set, F - Register flag,
      T - SPT-bit set, J - Join SPT, M - MSDP created entry, E - Extranet,
      X - Proxy Join Timer Running, A - Candidate for MSDP Advertisement,
      U - URD, I - Received Source Specific Host Report,
      Z - Multicast Tunnel, z - MDT-data group sender,
      Y - Joined MDT-data group, y - Sending to MDT-data group,
      G - Received BGP C-Mroute, g - Sent BGP C-Mroute,
      N - Received BGP Shared-Tree Prune, n - BGP C-Mroute suppressed,
      Q - Received BGP S-A Route, q - Sent BGP S-A Route,
      V - RD & Vector, v - Vector, p - PIM Joins on route,
      x - VxLAN group, c - PFP-SA cache created entry,
      * - determined by Assert, # - iif-starg configured on rpf intf,
      e - encap-helper tunnel flag, l - LISP decap ref count contributor
Outgoing interface flags: H - Hardware switched, A - Assert winner, p - PIM Join
                          t - LISP transit group
Timers: Uptime/Expires
Interface state: Interface, Next-Hop or VCD, State/Mode

(*, 224.0.1.40), 00:04:58/00:02:58, RP 0.0.0.0, flags: DCL
  Incoming interface: Null, RPF nbr 0.0.0.0
  Outgoing interface list:
    Ethernet0/0, Forward/Sparse, 00:04:58/00:02:58, flags:

host2#
2025-09-06 10:52:46: %LAMP-INFO: +..............................................................................+
2025-09-06 10:52:46: %LAMP-INFO: :                                Parsed output                                 :
2025-09-06 10:52:46: %LAMP-INFO: +..............................................................................+
{
    'vrf': {
        'default': {
            'address_family': {
                'ipv4': {
                    'multicast_group': {
                        '224.0.1.40': {
                            'source_address': {
                                '*': {
                                    'uptime': '00:04:58',
                                    'expire': '00:02:58',
                                    'flags': 'DCL',
                                    'msdp_learned': False,
                                    'rp_bit': False,
                                    'rp': '0.0.0.0',
                                    'rpf_nbr': '0.0.0.0',
                                    'outgoing_interface_list': {
                                        'Ethernet0/0': {
                                            'uptime': '00:04:58',
                                            'expire': '00:02:58',
                                            'state_mode': 'forward/sparse'
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
2025-09-06 10:52:46: %LAMP-INFO: +..............................................................................+
2025-09-06 10:52:46: %LAMP-INFO: :                           Collecting SAVE Entries                            :
2025-09-06 10:52:46: %LAMP-INFO: +..............................................................................+
Add SAVE filter (y/N): y
╭────────────────────────────╮
│ List of available filters: │
│ 1. dq                      │
╰────────────────────────────╯
Enter filter option number/name (1/dq): 1
Enter Dq query: raw("[vrf][default][address_family][ipv4][multicast_group][224.0.1.40][source_address][*][flags]")
'DCL'
Do you wish to add this Dq query (Y/n):
Enter variable name to save: autorp_flags
(lamp-h2)

The reconstructed Dq query output gets printed before prompting for confirmation to save the variable. This helps verify the Dq query and helps debug issues.

View the generated variable with variable list:

(lamp-h2) variable list
{'autorp_flags': 'DCL'}

api

Below is an example for generating a variable from an api action output:

(lamp-h2) api -s get_interface_ipv4_address
Get the ip address for an interface on target device

Args:
    interface ('string'): interface to get address for
    device: ('obj'): Device Object
Returns:
    None
    String with interface ip address

device: h2
interface: Ethernet0/0
2025-09-06 10:57:54: %LAMP-INFO: +..............................................................................+
2025-09-06 10:57:54: %LAMP-INFO: :              Api 'get_interface_ipv4_address' with parameters:               :
2025-09-06 10:57:54: %LAMP-INFO: :                                 device: 'h2'                                 :
2025-09-06 10:57:54: %LAMP-INFO: :                           interface: 'Ethernet0/0'                           :
2025-09-06 10:57:54: %LAMP-INFO: +..............................................................................+

2025-09-06 10:57:55,506: %UNICON-INFO: +++ host2(alias=h2) with via 'a': executing command 'show interfaces Ethernet0/0' +++
show interfaces Ethernet0/0
Ethernet0/0 is up, line protocol is up
  Internet address is 1.1.1.1/24
<TRUNCATED>
host2#
2025-09-06 10:57:55: %LAMP-INFO: +..............................................................................+
2025-09-06 10:57:55: %LAMP-INFO: :                                  API Output                                  :
2025-09-06 10:57:55: %LAMP-INFO: +..............................................................................+
                                                                  '1.1.1.1/24'
2025-09-06 10:57:55: %LAMP-INFO: +..............................................................................+
2025-09-06 10:57:55: %LAMP-INFO: +..............................................................................+
2025-09-06 10:57:55: %LAMP-INFO: :                           Collecting SAVE Entries                            :
2025-09-06 10:57:55: %LAMP-INFO: +..............................................................................+
Add SAVE filter (y/N):
Enter variable name to save: eth0_0_ip
(lamp-h2)
(lamp-h2) ^
{'eth0_0_ip': '1.1.1.1/24'}
(lamp-h2)

Available filters for API output depend on the API return type: Dq for dictionary outputs, regex for string outputs.

Using variables

Variables can be used as arguments to execute, configure, api, and parse commands, or in include/exclude entries.

An example of using a variable as an include entry in execute:

(lamp-h2) ^
{'oif': 'Ethernet0/0'}
(lamp-h2)
(lamp-h2) execute -i show ip mfib
2025-09-06 10:03:55: %LAMP-INFO: +..............................................................................+
2025-09-06 10:03:55: %LAMP-INFO: :                      Execute 'show ip mfib' on 'host2'                       :
2025-09-06 10:03:55: %LAMP-INFO: +..............................................................................+

2025-09-06 10:03:55,678: %UNICON-INFO: +++ host2(alias=h2) with via 'a': executing command 'show ip mfib' +++
show ip mfib
Entry Flags:    C - Directly Connected, S - Signal, IA - Inherit A flag,
                ET - Data Rate Exceeds Threshold, K - Keepalive
                DDE - Data Driven Event, HW - Hardware Installed
                ME - MoFRR ECMP entry, MNE - MoFRR Non-ECMP entry, MP - MFIB
                MoFRR Primary, RP - MRIB MoFRR Primary, P - MoFRR Primary
                MS  - MoFRR  Entry in Sync, MC - MoFRR entry in MoFRR Client,
                e   - Encap helper tunnel flag.
I/O Item Flags: IC - Internal Copy, NP - Not platform switched,
                NS - Negate Signalling, SP - Signal Present,
                A - Accept, F - Forward, RA - MRIB Accept, RF - MRIB Forward,
                MA - MFIB Accept, A2 - Accept backup,
                RA2 - MRIB Accept backup, MA2 - MFIB Accept backup

Forwarding Counts: Pkt Count/Pkts per second/Avg Pkt Size/Kbits per second
Other counts:      Total/RPF failed/Other drops
I/O Item Counts:   HW Pkt Count/FS Pkt Count/PS Pkt Count   Egress Rate in pps
Default
(*,224.0.0.0/4) Flags:
  SW Forwarding: 0/0/0/0, Other: 0/0/0
(*,224.0.1.40) Flags: C
  SW Forwarding: 0/0/0/0, Other: 0/0/0
  Ethernet0/0 Flags: F IC NS
    Pkts: 0/0/0    Rate: 0 pps

host2#
2025-09-06 10:03:55: %LAMP-INFO: +..............................................................................+
2025-09-06 10:03:55: %LAMP-INFO: :                          Collecting INCLUDE Entries                          :
2025-09-06 10:03:55: %LAMP-INFO: +..............................................................................+
Enter pattern to 'INCLUDE' (Press enter for multiple patterns): ^{oif}
(lamp-h2)
(lamp-h2) list 1
  - execute:
      device: host2
      command: show ip mfib
      include:
        - '%VARIABLES{oif}'
(lamp-h2)

Note the ‘%VARIABLES{oif}’ markup appearing in the autogenerated Blitz action snippet instead of the actual variable value.

The variable value always gets validated against the command output. If the variable value does not match with the command output, LAMP raises an error as shown below:

2025-09-23 16:43:36: %LAMP-INFO: +..............................................................................+
2025-09-23 16:43:36: %LAMP-INFO: :                          Collecting INCLUDE Entries                          :
2025-09-23 16:43:36: %LAMP-INFO: +..............................................................................+
Enter pattern to 'INCLUDE' (Press enter for multiple patterns): ^{addr}
LAMP-ERROR: Pattern '10.0.0.1' doesn't match the output
Do you still want to add this non-matching pattern (y/N):

Variables can also be used in Dq shorthand queries. Example:

(lamp-h2) parse -i show ip mroute
2025-09-06 11:03:10: %LAMP-INFO: +..............................................................................+
2025-09-06 11:03:10: %LAMP-INFO: :                        Parse 'show ip mroute' on 'h2'                        :
2025-09-06 11:03:10: %LAMP-INFO: +..............................................................................+

2025-09-06 11:03:11,101: %UNICON-INFO: +++ host2(alias=h2) with via 'a': executing command 'show ip mroute' +++
show ip mroute
IP Multicast Routing Table
Flags: D - Dense, S - Sparse, B - Bidir Group, s - SSM Group, C - Connected,
      L - Local, P - Pruned, R - RP-bit set, F - Register flag,
      T - SPT-bit set, J - Join SPT, M - MSDP created entry, E - Extranet,
      X - Proxy Join Timer Running, A - Candidate for MSDP Advertisement,
      U - URD, I - Received Source Specific Host Report,
      Z - Multicast Tunnel, z - MDT-data group sender,
      Y - Joined MDT-data group, y - Sending to MDT-data group,
      G - Received BGP C-Mroute, g - Sent BGP C-Mroute,
      N - Received BGP Shared-Tree Prune, n - BGP C-Mroute suppressed,
      Q - Received BGP S-A Route, q - Sent BGP S-A Route,
      V - RD & Vector, v - Vector, p - PIM Joins on route,
      x - VxLAN group, c - PFP-SA cache created entry,
      * - determined by Assert, # - iif-starg configured on rpf intf,
      e - encap-helper tunnel flag, l - LISP decap ref count contributor
Outgoing interface flags: H - Hardware switched, A - Assert winner, p - PIM Join
                          t - LISP transit group
Timers: Uptime/Expires
Interface state: Interface, Next-Hop or VCD, State/Mode

(*, 224.0.1.40), 00:15:22/00:02:33, RP 0.0.0.0, flags: DCL
  Incoming interface: Null, RPF nbr 0.0.0.0
  Outgoing interface list:
    Ethernet0/0, Forward/Sparse, 00:15:22/00:02:33, flags:

host2#
2025-09-06 11:03:11: %LAMP-INFO: +..............................................................................+
2025-09-06 11:03:11: %LAMP-INFO: :                                Parsed output                                 :
2025-09-06 11:03:11: %LAMP-INFO: +..............................................................................+
{
    'vrf': {
        'default': {
            'address_family': {
                'ipv4': {
                    'multicast_group': {
                        '224.0.1.40': {
                            'source_address': {
                                '*': {
                                    'uptime': '00:15:22',
                                    'expire': '00:02:33',
                                    'flags': 'DCL',
                                    'msdp_learned': False,
                                    'rp_bit': False,
                                    'rp': '0.0.0.0',
                                    'rpf_nbr': '0.0.0.0',
                                    'outgoing_interface_list': {
                                        'Ethernet0/0': {
                                            'uptime': '00:15:22',
                                            'expire': '00:02:33',
                                            'state_mode': 'forward/sparse'
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
2025-09-06 11:03:11: %LAMP-INFO: +..............................................................................+
2025-09-06 11:03:11: %LAMP-INFO: :                          Collecting INCLUDE Entries                          :
2025-09-06 11:03:11: %LAMP-INFO: +..............................................................................+
ROOT
└── (1) vrf
    └── (2) default
        └── (3) address_family
            └── (4) ipv4
                └── (5) multicast_group
                    └── (6) 224.0.1.40
                        └── (7) source_address
                            └── (8) *
                                ├── (9) uptime: 00:15:22
                                ├── (10) expire: 00:02:33
                                ├── (11) flags: DCL
                                ├── (12) msdp_learned: False
                                ├── (13) rp_bit: False
                                ├── (14) rp: 0.0.0.0
                                ├── (15) rpf_nbr: 0.0.0.0
                                └── (16) outgoing_interface_list
                                    └── (17) Ethernet0/0
                                        ├── (18) uptime: 00:15:22
                                        ├── (19) expire: 00:02:33
                                        └── (20) state_mode: forward/sparse
Enter Dq item (or) line numbers (Press enter for multiple entries): 224.0.1.40,^{oif}
contains('224.0.1.40').contains('%VARIABLES{oif}')
{
    'vrf': {
        'default': {
            'address_family': {
                'ipv4': {
                    'multicast_group': {
                        '224.0.1.40': {
                            'source_address': {
                                '*': {
                                    'outgoing_interface_list': {
                                        'Ethernet0/0': {
                                            'uptime': '00:15:22',
                                            'expire': '00:02:33',
                                            'state_mode': 'forward/sparse'
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Do you wish to add this Dq query (Y/n):
(lamp-h2) list 1
  - parse:
      device: h2
      command: show ip mroute
      include:
        - contains('224.0.1.40').contains('%VARIABLES{oif}')
(lamp-h2)

Note the ‘%VARIABLES{oif}’ markup appearing in the autogenerated Blitz action snippet within the Dq query.

Variable autocompletion

LAMP autocompletes variables in command arguments and in include/exclude entries, just like parameter autocompletion. Press <TAB> after ‘^{’ to see available variables.

Example: variable autocompletion when adding an include entry:

2024-10-05 19:33:15: %LAMP-INFO: +..............................................................................+
2024-10-05 19:33:15: %LAMP-INFO: :                                   INCLUDE                                    :
2024-10-05 19:33:15: %LAMP-INFO: +..............................................................................+
Enter pattern to INCLUDE (Press enter for multiple patterns): ^{
^{addr_1}      ^{addr_2}