To apply a macro to an interface or to apply and debug a macro on an interface, use the macro command in interface configuration mode.
macro {apply | trace} macro-name [parameter {value}] [parameter {value}] [parameter {value}]
Syntax Description
apply
|
Applies a macro to an interface.
|
trace
|
Applies a macro to an interface and then debugs it.
|
macro-name
|
Specifies the name of the macro.
|
parameter value
|
(Optional) Specifies unique parameter values that are specific to the interface. You can enter up to three keyword-value pairs.
Parameter keyword matching is case sensitive.
All matching occurrences of the keyword are replaced with the corresponding value.
|
Command Default
This command has no default setting.
Command Modes
Interface configuration (config-if)
Command History
Release |
Modification |
Cisco IOS XE Everest 16.5.1a
|
This command was introduced.
|
Usage Guidelines
You can use the macro apply macro-name command to apply and show the macros running on an interface.
You can use the macro trace macro-name command to apply and then debug the macro to find any syntax or configuration errors.
If a command fails because of a syntax error or a configuration error when you apply a macro, the macro continues to apply
the remaining commands to the interface.
When creating a macro that requires the assignment of unique values, use the parameter value keywords to designate values specific to the interface.
Keyword matching is case sensitive. All matching occurrences of the keyword are replaced with the corresponding value. Any
full match of a keyword, even if it is part of a larger string, is considered a match and is replaced by the corresponding
value.
Some macros might contain keywords that require a parameter value. You can use the macro apply macro-name ? command to display a list of any required values in the macro. If you apply a macro without entering the keyword values,
the commands are invalid and are not applied.
There are Cisco-default SmartPorts macros embedded in the switch software. You can display these macros and the commands that
they contain by using the show parser macro command in user EXEC mode.
Follow these guidelines when you apply a Cisco-default SmartPorts macro on an interface:
-
Display all macros on the switch by using the show parser macro command in user EXEC mode. Display the contents of a specific macro by using the show parser macro macro-name command in user EXEC mode.
-
Keywords that begin with $ mean that a unique parameter value is required. Append the Cisco-default macro with the required
values by using the parameter value keywords.
The Cisco-default macros use the $ character to identify required keywords. You can use the $ character to define keywords
when you create a macro.
When you apply a macro to an interface, the macro name is automatically added to the interface. You can display the applied
commands and macro names by using the show running-config interface interface-id command in user EXEC mode.
A macro applied to an interface range behaves the same way as a macro applied to a single interface. When you use an interface
range, the macro is applied sequentially to each interface within the range. If a macro command fails on one interface, it
is still applied to the remaining interfaces.
You can delete a macro-applied configuration on an interface by entering the default interface interface-id command in interface configuration mode.
Examples
After you use the macro name command, in interface configuration mode, you can apply it to an interface. This example shows how to apply a user-created
macro called duplex to an interface:
Device(config-if)# macro apply duplex
To debug a macro, use the macro trace command, in interface configuration mode, to find any syntax or configuration errors in the macro as it is applied to an
interface.
Device(config-if)# macro trace duplex
Applying command...‘duplex auto’
%Error Unknown error.
Applying command...‘speed nonegotiate’
This example shows how to display the Cisco-default cisco-desktop macro and how to apply the macro and set the access VLAN
ID to 25 on an interface:
Device# show parser macro cisco-desktop
--------------------------------------------------------------
Macro name : cisco-desktop
Macro type : default
# Basic interface - Enable data VLAN only
# Recommended value for access vlan (AVID) should not be 1
switchport access vlan $AVID
switchport mode access
# Enable port security limiting port to a single
# MAC address -- that of desktop
switchport port-security
switchport port-security maximum 1
# Ensure port-security age is greater than one minute
# and use inactivity timer
switchport port-security violation restrict
switchport port-security aging time 2
switchport port-security aging type inactivity
# Configure port as an edge network port
spanning-tree portfast
spanning-tree bpduguard enable
--------------------------------------------------------------
Device#
Device# configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Device(config)# interface gigabitethernet1/0/4
Device(config-if)# macro apply cisco-desktop $AVID 25