cisco.ios.ios_vrf_interfaces module – Manages VRF configuration on interfaces.

Note

This module is part of the cisco.ios collection (version 9.1.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install cisco.ios.

To use it in a playbook, specify: cisco.ios.ios_vrf_interfaces.

New in cisco.ios 1.0.0

Synopsis

  • Manages Virtual Routing and Forwarding (VRF) configuration on interfaces of Cisco IOS devices.

Parameters

Parameter

Comments

config

list / elements=dictionary

A list of interface VRF configurations.

name

string / required

Full name of the interface to be configured.

Example - GigabitEthernet1, Loopback24

vrf_name

string

Name of the VRF to be configured on the interface.

When configured, applies ‘vrf forwarding <vrf_name>’ under the interface.

running_config

string

This option is used only with state parsed.

The value of this option should be the output received from the IOS device by executing the command show running-config | section ^interface.

The state parsed reads the configuration from running_config option and transforms it into Ansible structured data as per the resource module’s argspec and the value is then returned in the parsed key within the result.

state

string

The state the configuration should be left in.

Choices:

  • "merged" ← (default)

  • "replaced"

  • "overridden"

  • "deleted"

  • "gathered"

  • "rendered"

  • "parsed"

Notes

Note

  • Tested against Cisco IOS XE Version 17.13.01a

  • VRF must exist before assigning to an interface

  • When removing VRF from interface, associated IP addresses will be removed

  • For more information on using Ansible to manage network devices see the :ref:`Ansible Network Guide <network_guide>`

  • For more information on using Ansible to manage Cisco devices see the `Cisco integration page <https://www.ansible.com/integrations/networks/cisco>`_.

Examples

# Using merged

# Before state:
# -------------
#
# vios#show running-config | section ^interface
# interface Loopback24
#  no ip address
# interface GigabitEthernet1
#  ip address dhcp
#  negotiation auto
# interface GigabitEthernet2
#  no ip address
#  shutdown
#  negotiation auto
# interface GigabitEthernet3
#  no ip address
#  negotiation auto
# interface GigabitEthernet4
#  no ip address
#  shutdown
#  negotiation auto

- name: Merge provided configuration with device configuration
  cisco.ios.ios_vrf_interfaces:
    config:
      - name: GigabitEthernet1
      - name: GigabitEthernet2
        vrf_name: vrf_D
      - name: GigabitEthernet3
      - name: GigabitEthernet4
    state: merged

# Task Output:
# ------------
#
# before:
#   - name: "Loopback24"
#   - name: "GigabitEthernet1"
#   - name: "GigabitEthernet2"
#   - name: "GigabitEthernet3"
#   - name: "GigabitEthernet4"
#
# commands:
#   - interface GigabitEthernet2
#   - vrf forwarding vrf_D
#
# after:
#   - name: "Loopback24"
#   - name: "GigabitEthernet1"
#   - name: "GigabitEthernet2"
#     vrf_name: "vrf_D"
#   - name: "GigabitEthernet3"
#   - name: "GigabitEthernet4"

# After state:
# ------------
#
# vios#show running-config | section ^interface
# interface Loopback24
#  no ip address
# interface GigabitEthernet1
#  ip address dhcp
#  negotiation auto
# interface GigabitEthernet2
#  vrf forwarding vrf_D
#  no ip address
#  shutdown
#  negotiation auto
# interface GigabitEthernet3
#  no ip address
#  negotiation auto
# interface GigabitEthernet4
#  no ip address
#  shutdown
#  negotiation auto

# Using overridden

# Before state:
# -------------
#
# vios#show running-config | section ^interface
# interface Loopback24
#  no ip address
# interface GigabitEthernet1
#  ip address dhcp
#  negotiation auto
# interface GigabitEthernet2
#  vrf forwarding vrf_B
#  no ip address
#  shutdown
#  negotiation auto
# interface GigabitEthernet3
#  no ip address
#  negotiation auto
# interface GigabitEthernet4
#  no ip address
#  shutdown
#  negotiation auto

- name: Override device configuration with provided configuration
  cisco.ios.ios_vrf_interfaces:
    config:
      - name: GigabitEthernet1
      - name: GigabitEthernet2
      - name: GigabitEthernet3
      - name: GigabitEthernet4
    state: overridden

# Task Output:
# ------------
#
# before:
#   - name: "Loopback24"
#   - name: "GigabitEthernet1"
#   - name: "GigabitEthernet2"
#     vrf_name: "vrf_B"
#   - name: "GigabitEthernet3"
#   - name: "GigabitEthernet4"
#
# commands:
#   - interface GigabitEthernet2
#   - no vrf forwarding vrf_B
#
# after:
#   - name: "Loopback24"
#   - name: "GigabitEthernet1"
#   - name: "GigabitEthernet2"
#   - name: "GigabitEthernet3"
#   - name: "GigabitEthernet4"

# After state:
# ------------
#
# vios#show running-config | section ^interface
# interface Loopback24
#  no ip address
# interface GigabitEthernet1
#  ip address dhcp
#  negotiation auto
# interface GigabitEthernet2
#  no ip address
#  shutdown
#  negotiation auto
# interface GigabitEthernet3
#  no ip address
#  negotiation auto
# interface GigabitEthernet4
#  no ip address
#  shutdown
#  negotiation auto

# Using gathered

# Before state:
# -------------
#
# vios#show running-config | section ^interface
# interface Loopback24
#  no ip address
# interface GigabitEthernet1
#  ip address dhcp
#  negotiation auto
# interface GigabitEthernet2
#  vrf forwarding vrf_B
#  no ip address
#  shutdown
#  negotiation auto
# interface GigabitEthernet3
#  no ip address
#  negotiation auto
# interface GigabitEthernet4
#  no ip address
#  shutdown
#  negotiation auto

- name: Gather listed VRF interfaces
  cisco.ios.ios_vrf_interfaces:
    state: gathered

# Task Output:
# ------------
#
# gathered:
#   - name: "Loopback24"
#   - name: "GigabitEthernet1"
#   - name: "GigabitEthernet2"
#     vrf_name: "vrf_B"
#   - name: "GigabitEthernet3"
#   - name: "GigabitEthernet4"

# Using rendered

- name: Render VRF configuration
  cisco.ios.ios_vrf_interfaces:
    config:
      - name: GigabitEthernet1
      - name: GigabitEthernet2
        vrf_name: vrf_D
      - name: GigabitEthernet3
      - name: GigabitEthernet4
    state: rendered

# Task Output:
# ------------
#
# rendered:
#   - interface GigabitEthernet2
#   - vrf forwarding vrf_D

# Using parsed

# File: parsed.cfg
# ---------------
#
# interface GigabitEthernet1
#  vrf vrf_C
#  shutdown
# !
# interface GigabitEthernet2
#  vrf vrf_D
#  shutdown
# !
# interface GigabitEthernet3
#  shutdown
# !
# interface GigabitEthernet4
#  shutdown
# !

- name: Parse configuration from device running config
  cisco.ios.ios_vrf_interfaces:
    running_config: "{{ lookup('file', 'parsed.cfg') }}"
    state: parsed

# Task Output:
# ------------
#
# parsed:
#   - name: "GigabitEthernet1"
#     vrf_name: "vrf_C"
#   - name: "GigabitEthernet2"
#     vrf_name: "vrf_D"
#   - name: "GigabitEthernet3"
#   - name: "GigabitEthernet4"

# Using replaced

# Before state:
# -------------
#
# vios#show running-config | section ^interface
# interface Loopback24
#  no ip address
# interface GigabitEthernet1
#  vrf forwarding vrf_A
#  ip address dhcp
#  negotiation auto
# interface GigabitEthernet2
#  vrf forwarding vrf_B
#  no ip address
#  shutdown
#  negotiation auto
# interface GigabitEthernet3
#  no ip address
#  negotiation auto
# interface GigabitEthernet4
#  vrf forwarding vrf_C
#  no ip address
#  shutdown
#  negotiation auto

- name: Replace device configuration of listed VRF interfaces with provided configuration
  cisco.ios.ios_vrf_interfaces:
    config:
      - name: GigabitEthernet1
        vrf_name: vrf_D
      - name: GigabitEthernet2
        vrf_name: vrf_E
    state: replaced

# Task Output:
# ------------
#
# before:
#   - name: "Loopback24"
#   - name: "GigabitEthernet1"
#     vrf_name: "vrf_A"
#   - name: "GigabitEthernet2"
#     vrf_name: "vrf_B"
#   - name: "GigabitEthernet3"
#   - name: "GigabitEthernet4"
#     vrf_name: "vrf_C"
#
# commands:
#   - interface GigabitEthernet1
#   - no vrf forwarding vrf_A
#   - vrf forwarding vrf_D
#   - interface GigabitEthernet2
#   - no vrf forwarding vrf_B
#   - vrf forwarding vrf_E
#
# after:
#   - name: "Loopback24"
#   - name: "GigabitEthernet1"
#     vrf_name: "vrf_D"
#   - name: "GigabitEthernet2"
#     vrf_name: "vrf_E"
#   - name: "GigabitEthernet3"
#   - name: "GigabitEthernet4"
#     vrf_name: "vrf_C"

# Using deleted

# Before state:
# -------------
#
# vios#show running-config | section ^interface
# interface Loopback24
#  no ip address
# interface GigabitEthernet1
#  vrf forwarding vrf_A
#  ip address dhcp
#  negotiation auto
# interface GigabitEthernet2
#  vrf forwarding vrf_B
#  no ip address
#  shutdown
#  negotiation auto
# interface GigabitEthernet3
#  no ip address
#  negotiation auto
# interface GigabitEthernet4
#  vrf forwarding vrf_C
#  no ip address
#  shutdown
#  negotiation auto

- name: Delete VRF configuration of specified interfaces
  cisco.ios.ios_vrf_interfaces:
    config:
      - name: GigabitEthernet1
      - name: GigabitEthernet2
    state: deleted

# Task Output:
# ------------
#
# before:
#   - name: "Loopback24"
#   - name: "GigabitEthernet1"
#     vrf_name: "vrf_A"
#   - name: "GigabitEthernet2"
#     vrf_name: "vrf_B"
#   - name: "GigabitEthernet3"
#   - name: "GigabitEthernet4"
#     vrf_name: "vrf_C"
#
# commands:
#   - interface GigabitEthernet1
#   - no vrf forwarding vrf_A
#   - interface GigabitEthernet2
#   - no vrf forwarding vrf_B
#
# after:
#   - name: "Loopback24"
#   - name: "GigabitEthernet1"
#   - name: "GigabitEthernet2"
#   - name: "GigabitEthernet3"
#   - name: "GigabitEthernet4"
#     vrf_name: "vrf_C"

# After state:
# ------------
#
# vios#show running-config | section ^interface
# interface Loopback24
#  no ip address
# interface GigabitEthernet1
#  ip address dhcp
#  negotiation auto
# interface GigabitEthernet2
#  no ip address
#  shutdown
#  negotiation auto
# interface GigabitEthernet3
#  no ip address
#  negotiation auto
# interface GigabitEthernet4
#  vrf forwarding vrf_C
#  no ip address
#  shutdown
#  negotiation auto

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

after

list / elements=string

The resulting configuration after module execution.

Returned: when changed

Sample: ["[\n    {\n        \"name\": \"Loopback24\"\n    }", "\n    {\n        \"name\": \"GigabitEthernet1\"\n    }", "\n    {\n        \"name\": \"GigabitEthernet2\"", "\n        \"vrf_name\": \"vrf_D\"\n    }", "\n    {\n        \"name\": \"GigabitEthernet3\"\n    }", "\n    {\n        \"name\": \"GigabitEthernet4\"\n    }\n]\n"]

before

list / elements=string

The configuration prior to the module execution.

Returned: when state is merged, replaced, overridden, deleted

Sample: ["[\n    {\n        \"name\": \"Loopback24\"\n    }", "\n    {\n        \"name\": \"GigabitEthernet1\"\n    }", "\n    {\n        \"name\": \"GigabitEthernet2\"", "\n        \"vrf_name\": \"vrf_B\"\n    }", "\n    {\n        \"name\": \"GigabitEthernet3\"\n    }", "\n    {\n        \"name\": \"GigabitEthernet4\"\n    }\n]\n"]

commands

list / elements=string

The set of commands pushed to the remote device.

Returned: when state is merged, replaced, overridden, deleted

Sample: ["interface GigabitEthernet2", "vrf forwarding vrf_D", "no vrf forwarding vrf_B"]

gathered

list / elements=string

Facts about the network resource gathered from the remote device as structured data.

Returned: when state is gathered

Sample: ["[\n    {\n        \"name\": \"Loopback24\"\n    }", "\n    {\n        \"name\": \"GigabitEthernet1\"\n    }", "\n    {\n        \"name\": \"GigabitEthernet2\"", "\n        \"vrf_name\": \"vrf_B\"\n    }", "\n    {\n        \"name\": \"GigabitEthernet3\"\n    }", "\n    {\n        \"name\": \"GigabitEthernet4\"\n    }\n]\n"]

parsed

list / elements=string

The device native config provided in running_config option parsed into structured data as per module argspec.

Returned: when state is parsed

Sample: ["[\n    {\n        \"name\": \"GigabitEthernet1\"", "\n        \"vrf_name\": \"vrf_C\"\n    }", "\n    {\n        \"name\": \"GigabitEthernet2\"", "\n        \"vrf_name\": \"vrf_D\"\n    }", "\n    {\n        \"name\": \"GigabitEthernet3\"\n    }", "\n    {\n        \"name\": \"GigabitEthernet4\"\n    }\n]\n"]

rendered

list / elements=string

The provided configuration in the task rendered in device-native format (offline).

Returned: when state is rendered

Sample: ["interface GigabitEthernet1", "vrf forwarding vrf_C", "interface GigabitEthernet2", "vrf forwarding vrf_D"]

Authors

  • AAYUSH ANAND (@AAYUSH2091)