cisco.nxos.nxos_vrf_interfaces module – Resource module to configure VRF interfaces.

Note

This module is part of the cisco.nxos collection (version 9.3.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.nxos.

To use it in a playbook, specify: cisco.nxos.nxos_vrf_interfaces.

New in cisco.nxos 1.0.0

Synopsis

  • This module configures and manages the VRF configuration on interfaces on NX-OS platforms.

Parameters

Parameter

Comments

config

list / elements=dictionary

A list of interface VRF configurations.

name

string / required

Full name of the interface excluding any logical unit number, i.e. Ethernet1/1.

vrf_name

string

Name of the VRF to be configured on the interface.

When configured, applies ‘vrf member <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 NX-OS device by executing the command show running-config 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 NX-OS.

  • This module works with connection network_cli.

Examples

# Using merged

# Before state:
# -------------
#
# nxos#show running-config interface
# interface Ethernet1/1
#  no switchport
# interface Ethernet1/2
#  description test
#  no switchport
#  no shutdown
# interface Ethernet1/3
# interface Ethernet1/4
#  no switchport
#  speed 1000
#  no shutdown

- name: Merge provided configuration with device configuration
  cisco.nxos.nxos_vrf_interfaces:
    config:
      - name: Ethernet1/1
      - name: Ethernet1/2
        vrf_name: test
      - name: Ethernet1/3
      - name:Ethernet1/4
    state: merged

# Task Output:
# ------------
#
# before:
#   - name: "Ethernet1/1"
#   - name: "Ethernet1/2"
#   - name: "Ethernet1/3"
#   - name: "Ethernet1/4"
#
# commands:
#   - interface Ethernet1/2
#   - vrf member test
#
# after:
#   - name: "Ethernet1/1"
#   - name: "Ethernet1/2"
#     vrf_name: "test2"
#   - name: "Ethernet1/3"
#   - name: "Ethernet1/4"

# After state:
# ------------
#
# nxos#show running-config interface
# interface Ethernet1/1
#  no ip address
# interface Ethernet1/2
#  vrf member test
#  no ip address
#  shutdown
#  negotiation auto
# interface Ethernet1/3
#  no ip address
#  negotiation auto
# interfaceEthernet1/4
#  no ip address
#  shutdown
#  negotiation auto

# Using overridden

# Before state:
# -------------
#
# nxos#show running-config interface
# interface Ethernet1/1
#  no ip address
# interface Ethernet1/1
#  ip address dhcp
#  negotiation auto
# interface Ethernet1/2
#  vrf member vrf_B
#  no ip address
#  shutdown
#  negotiation auto
# interface Ethernet1/3
#  no ip address
#  negotiation auto
# interface Ethernet1/4
#  no ip address
#  shutdown
#  negotiation auto

- name: Override device configuration with provided configuration
  cisco.nxos.nxos_vrf_interfaces:
    config:
      - name: Ethernet1/1
      - name: Ethernet1/2
      - name: Ethernet1/3
      - name: Ethernet1/4
    state: overridden

# Task Output:
# ------------
#
# before:
#   - name: "Ethernet1/1"
#   - name: "Ethernet1/2"
#     vrf_name: "vrf_B"
#   - name: "Ethernet1/3"
#   - name: "Ethernet1/4"
#
# commands:
#   - interface Ethernet1/2
#   - no vrf member vrf_B
#
# after:
#   - name: "Ethernet1/1"
#   - name: "Ethernet1/2"
#   - name: "Ethernet1/3"
#   - name: "Ethernet1/4"

# After state:
# ------------
#
# nxos#show running-config interface
# interface Ethernet1/1
#  no ip address
# interface Ethernet1/2
#  no ip address
#  shutdown
#  negotiation auto
# interface Ethernet1/3
#  no ip address
#  negotiation auto
# interface Ethernet1/4
#  no ip address
#  shutdown
#  negotiation auto

# Using gathered

# Before state:
# -------------
#
# nxos#show running-config interface
# interface Ethernet1/1
#  no ip address
# interface Ethernet1/2
#  vrf member vrf_B
#  no ip address
#  shutdown
#  negotiation auto
# interface Ethernet1/3
#  no ip address
#  negotiation auto
# interfaceEthernet1/4
#  no ip address
#  shutdown
#  negotiation auto

- name: Gather listed VRF interfaces
  cisco.nxos.nxos_vrf_interfaces:
    state: gathered

# Task Output:
# ------------
#
# gathered:
#   - name: "Ethernet1/1"
#   - name: "Ethernet1/2"
#     vrf_name: "vrf_B"
#   - name: "Ethernet1/3"

# Using rendered

- name: Render VRF configuration
  cisco.nxos.nxos_vrf_interfaces:
    config:
      - name: Ethernet1/1
      - name: Ethernet1/2
        vrf_name: test
      - name: Ethernet1/3
      - name: Ethernet1/4
    state: rendered

# Task Output:
# ------------
#
# rendered:
#   - interface Ethernet1/2
#   - vrf member test

# Using parsed

# File: parsed.cfg
# ---------------
#
# interface Ethernet1/2
#   no switchport
#   vrf member VRF1
# interface Ethernet1/6
#   no switchport
#   speed 1000
#   vrf member TEST_VRF

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

# Task Output:
# ------------
#
# parsed:
#   - name: "Ethernet1/2"
#     vrf_name: "VRF1"
#   - name: "Ethernet1/6"
#     vrf_name: "TEST_VRF"

# Using replaced

# Before state:
# -------------
#
# nxos#show running-config interface
# interface Ethernet1/1
#  no ip address
# interface Ethernet1/2
#  vrf member vrf_B
#  no ip address
#  shutdown
# interface Ethernet1/3
#  no ip address
# interfaceEthernet1/4
#  vrf member vrf_C
#  no ip address
#  shutdown

- name: Replace device configuration of listed VRF interfaces with provided configuration
  cisco.nxos.nxos_vrf_interfaces:
    config:
      - name: Ethernet1/1
        vrf_name: test
      - name: Ethernet1/2
        vrf_name: vrf_E
    state: replaced

# Task Output:
# ------------
#
# before:
#   - name: "Ethernet1/1"
#     vrf_name: "vrf_A"
#   - name: "Ethernet1/2"
#     vrf_name: "vrf_B"
#   - name: "Ethernet1/3"
#   - name: "Ethernet1/4"
#     vrf_name: "vrf_C"
#
# commands:
#   - interface Ethernet1/1
#   - no vrf member vrf_A
#   - vrf member test
#   - interface Ethernet1/2
#   - no vrf member vrf_B
#   - vrf member vrf_E
#
# after:
#   - name: "Ethernet1/1"
#     vrf_name: "test"
#   - name: "Ethernet1/2"
#     vrf_name: "vrf_E"
#   - name: "Ethernet1/3"
#   - name: "Ethernet1/4"
#     vrf_name: "vrf_C"

# Using deleted

# Before state:
# -------------
#
# nxos#show running-config interface
# interface Ethernet1/1
#  vrf member vrf_A
#  ip address dhcp
# interface Ethernet1/2
#  vrf member vrf_B
#  no ip address
#  shutdown
# interface Ethernet1/3
#  no ip address
# interfaceEthernet1/4
#  vrf member vrf_C
#  no ip address
#  shutdown

- name: Delete VRF configuration of specified interfaces
  cisco.nxos.nxos_vrf_interfaces:
    config:
      - name: Ethernet1/1
      - name: Ethernet1/2
    state: deleted

# Task Output:
# ------------
#
# before:
#   - name: "Ethernet1/1"
#     vrf_name: "vrf_A"
#   - name: "Ethernet1/2"
#     vrf_name: "vrf_B"
#   - name: "Ethernet1/3"
#   - name: "Ethernet1/4"
#     vrf_name: "vrf_C"
#
# commands:
#   - interface Ethernet1/1
#   - no vrf member vrf_A
#   - interface Ethernet1/2
#   - no vrf member vrf_B
#
# after:
#   - name: "Ethernet1/1"
#   - name: "Ethernet1/1"
#   - name: "Ethernet1/2"
#   - name: "Ethernet1/3"
#   - name: "Ethernet1/4"
#     vrf_name: "vrf_C"

# After state:
# ------------
#
# nxos#show running-config interface
# interface Ethernet1/1
#  ip address dhcp
# interface Ethernet1/2
#  no ip address
#  shutdown
# interface Ethernet1/3
#  no ip address
# interfaceEthernet1/4
#  vrf member vrf_C
#  no ip address
#  shutdown

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\": \"Ethernet1/1\"\n    }", "\n    {\n        \"name\": \"Ethernet1/2\"", "\n        \"vrf_name\": \"test\"\n    }", "\n    {\n        \"name\": \"Ethernet1/3\"\n    }", "\n    {\n        \"name\": \"Ethernet1/4\"\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\": \"Ethernet1/1\"\n    }", "\n    {\n        \"name\": \"Ethernet1/2\"", "\n        \"vrf_name\": \"test\"\n    }", "\n    {\n        \"name\": \"Ethernet1/3\"\n    }", "\n    {\n        \"name\": \"Ethernet1/4\"\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 Ethernet1/2", "vrf member test", "no vrf member 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\": \"Ethernet1/1\"\n    }", "\n    {\n        \"name\": \"Ethernet1/2\"", "\n        \"vrf_name\": \"vrf_B\"\n    }", "\n    {\n        \"name\": \"Ethernet1/3\"\n    }", "\n    {\n        \"name\": \"Ethernet1/4\"\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\": \"Ethernet1/1\"", "\n        \"vrf_name\": \"vrf_C\"\n    }", "\n    {\n        \"name\": \"Ethernet1/2\"", "\n        \"vrf_name\": \"test\"\n    }", "\n    {\n        \"name\": \"Ethernet1/3\"\n    }", "\n    {\n        \"name\": \"Ethernet1/4\"\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 Ethernet1/1", "vrf member vrf_C", "interface Ethernet1/2", "vrf member test"]

Authors

  • Ruchi Pakhle (@Ruchip16)