Skip to content

Latest commit

 

History

History
738 lines (676 loc) · 22.9 KB

cisco.ios.ios_vrf_interfaces_module.rst

File metadata and controls

738 lines (676 loc) · 22.9 KB

cisco.ios.ios_vrf_interfaces

Manages VRF configuration on interfaces.

Version added: 1.0.0

  • Manages Virtual Routing and Forwarding (VRF) configuration on interfaces of Cisco IOS devices.
Parameter Choices/Defaults 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
    Choices:
  • merged ←
  • replaced
  • overridden
  • deleted
  • gathered
  • rendered
  • parsed
The state the configuration should be left in.

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.
# 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

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

Key Returned Description
after
list
when changed
The resulting configuration after module execution.

Sample:
[ { "name": "Loopback24" }, { "name": "GigabitEthernet1" }, { "name": "GigabitEthernet2", "vrf_name": "vrf_D" }, { "name": "GigabitEthernet3" }, { "name": "GigabitEthernet4" } ]
before
list
when state is merged, replaced, overridden, deleted
The configuration prior to the module execution.

Sample:
[ { "name": "Loopback24" }, { "name": "GigabitEthernet1" }, { "name": "GigabitEthernet2", "vrf_name": "vrf_B" }, { "name": "GigabitEthernet3" }, { "name": "GigabitEthernet4" } ]
commands
list
when state is merged, replaced, overridden, deleted
The set of commands pushed to the remote device.

Sample:
['interface GigabitEthernet2', 'vrf forwarding vrf_D', 'no vrf forwarding vrf_B']
gathered
list
when state is gathered
Facts about the network resource gathered from the remote device as structured data.

Sample:
[ { "name": "Loopback24" }, { "name": "GigabitEthernet1" }, { "name": "GigabitEthernet2", "vrf_name": "vrf_B" }, { "name": "GigabitEthernet3" }, { "name": "GigabitEthernet4" } ]
parsed
list
when state is parsed
The device native config provided in running_config option parsed into structured data as per module argspec.

Sample:
[ { "name": "GigabitEthernet1", "vrf_name": "vrf_C" }, { "name": "GigabitEthernet2", "vrf_name": "vrf_D" }, { "name": "GigabitEthernet3" }, { "name": "GigabitEthernet4" } ]
rendered
list
when state is rendered
The provided configuration in the task rendered in device-native format (offline).

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


Authors

  • AAYUSH ANAND (@AAYUSH2091)