cisco.nxos.nxos_interfaces (7.0.0) — module

Interfaces resource module

| "added in version" 1.0.0 of cisco.nxos"

Authors: Trishna Guha (@trishnaguha)

Install collection

Install with ansible-galaxy collection install cisco.nxos:==7.0.0


Add to requirements.yml

  collections:
    - name: cisco.nxos
      version: 7.0.0

Description

This module manages the interface attributes of NX-OS interfaces.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Using merged

# Before state:
# -------------
#
# switch# show running-config | section interface
# interface Ethernet1/1
#   description testing
# interface mgmt0
#   description mgmt interface
#   ip address dhcp
#   vrf member management

- name: Merge provided configuration with device configuration
  cisco.nxos.nxos_interfaces:
    config:
      - name: Ethernet1/1
        description: Configured by Ansible
        enabled: true
      - name: Ethernet1/2
        description: Configured by Ansible Network
        enabled: false
    state: merged
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Task Output
# -----------
#
# before:
# - description: testing
#   name: Ethernet1/1
# - description: mgmt interface
#   name: mgmt0
# commands:
# - interface Ethernet1/1
# - description Configured by Ansible
# - interface Ethernet1/2
# - description Configured by Ansible Network
# - shutdown
# after:
# - description: Configured by Ansible
#   name: Ethernet1/1
# - description: Configured by Ansible Network
#   enabled: false
#   name: Ethernet1/2
# - description: mgmt interface
#   name: mgmt0

# After state:
# ------------
#
# switch# show running-config | section interface
# interface Ethernet1/1
#   description Configured by Ansible
# interface Ethernet1/2
#   description Configured by Ansible Network
#   shutdown
# interface mgmt0
#   description mgmt interface
#   ip address dhcp
#   vrf member management

# Using replaced

# Before state:
# -------------
#
# switch# show running-config | section interface
# interface Ethernet1/1
#   description Updated by Ansible
# interface Ethernet1/2
#   description Configured by Ansible Network
#   shutdown
# interface mgmt0
#   description mgmt interface
#   ip address dhcp
#   vrf member management

- name: Replaces device configuration of listed interfaces with provided configuration
  cisco.nxos.nxos_interfaces:
    config:
      - name: Ethernet1/1
        description: Configured by Ansible
        enabled: true
        mtu: 9000
      - name: Ethernet1/2
        description: Configured by Ansible Network
        enabled: false
        mode: layer2
    state: replaced
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Task Output
# -----------
#
# before:
# - description: Updated by Ansible
#   name: Ethernet1/1
# - description: Configured by Ansible Network
#   enabled: false
#   name: Ethernet1/2
# - description: mgmt interface
#   name: mgmt0
# commands:
# - interface Ethernet1/1
# - mtu 1500
# - interface Ethernet1/2
# - description Updated by Ansible
# after:
# - description: Updated by Ansible
#   name: Ethernet1/1
# - description: Updated by Ansible
#   enabled: false
#   name: Ethernet1/2
# - description: mgmt interface
#   name: mgmt0

# After state:
# ------------
#
# switch# show running-config | section interface
# interface Ethernet1/1
#   description Updated by Ansible
# interface Ethernet1/2
#   description Updated by Ansible
#   shutdown
# interface mgmt0
#   description mgmt interface
#   ip address dhcp
#   vrf member management

# Using overridden

# Before state:
# -------------
#
# switch# show running-config | section interface
# interface Ethernet1/1
#   description Updated by Ansible
# interface Ethernet1/2
#   description Updated by Ansible
#   shutdown
# interface mgmt0
#   description mgmt interface
#   ip address dhcp
#   vrf member management

- name: Override device configuration of all interfaces with provided configuration
  cisco.nxos.nxos_interfaces:
    config:
      - name: Ethernet1/1
        enabled: true
      - name: Ethernet1/2
        description: Configured by Ansible Network
        enabled: false
      - description: mgmt interface
        name: mgmt0
    state: overridden
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Task Output
# -----------
#
# before:
# - description: Updated by Ansible
#   name: Ethernet1/1
# - description: Updated by Ansible
#   enabled: false
#   name: Ethernet1/2
# - description: mgmt interface
#   name: mgmt0
# commands:
# - interface Ethernet1/1
# - no description
# - interface Ethernet1/2
# - description Configured by Ansible Network
# after:
# - name: Ethernet1/1
# - description: Configured by Ansible Network
#   enabled: false
#   name: Ethernet1/2
# - description: mgmt interface
#   name: mgmt0

# After state:
# ------------
#
# switch# show running-config | section interface
# interface Ethernet1/1
# interface Ethernet1/2
#   description Configured by Ansible Network
#   shutdown
# interface mgmt0
#   description mgmt interface
#   ip address dhcp
#   vrf member management

# Using deleted

# Before state:
# -------------
#
# switch# show running-config | section interface
# interface Ethernet1/1
# interface Ethernet1/2
#   description Configured by Ansible Network
#   shutdown
# interface mgmt0
#   description mgmt interface
#   ip address dhcp
#   vrf member management

- name: Delete or return interface parameters to default settings
  cisco.nxos.nxos_interfaces:
    config:
      - name: Ethernet1/2
    state: deleted
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Task Output
# -----------
#
# before:
# - name: Ethernet1/1
# - description: Configured by Ansible Network
#   enabled: false
#   name: Ethernet1/2
# - description: mgmt interface
#   name: mgmt0
# commands:
# - interface Ethernet1/2
# - no description
# - no shutdown
# after:
# - name: Ethernet1/1
# - name: Ethernet1/2
# - description: mgmt interface
#   name: mgmt0

# After state:
# ------------
#
# switch# show running-config | section interface
# interface Ethernet1/1
# interface Ethernet1/2
# interface mgmt0
#   description mgmt interface
#   ip address dhcp
#   vrf member management

# Using rendered

- name: Use rendered state to convert task input to device specific commands
  cisco.nxos.nxos_interfaces:
    config:
      - name: Ethernet1/1
        description: outbound-intf
        mode: layer3
        speed: 100
      - name: Ethernet1/2
        mode: layer2
        enabled: true
        duplex: full
    state: rendered
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Task Output
# -----------
#
# rendered:
#   - "interface Ethernet1/1"
#   - "description outbound-intf"
#   - "speed 100"
#   - "interface Ethernet1/2"
#   - "switchport"
#   - "duplex full"
#   - "no shutdown"

# Using parsed

# parsed.cfg
# ------------
#
# interface Ethernet1/800
#   description test-1
#   speed 1000
#   shutdown
#   no switchport
#   duplex half
# interface Ethernet1/801
#   description test-2
#   switchport
#   no shutdown
#   mtu 1800

- name: Use parsed state to convert externally supplied config to structured format
  cisco.nxos.nxos_interfaces:
    running_config: "{{ lookup('file', 'parsed.cfg') }}"
    state: parsed
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Task output
# -----------
#
#  parsed:
#    - description: "test-1"
#      duplex: "half"
#      enabled: false
#      mode: "layer3"
#      name: "Ethernet1/800"
#      speed: "1000"
#    - description: "test-2"
#      enabled: true
#      mode: "layer2"
#      mtu: "1800"
#      name: "Ethernet1/801"

# Using gathered

# Before state:
# -------------
#
# switch# show running-config | section interface
# interface Ethernet1/1
#   description outbound-intf
#   switchport
#   no shutdown
# interface Ethernet1/2
#   description intf-l3
#   speed 1000
# interface Ethernet1/3
# interface Ethernet1/4
# interface Ethernet1/5

- name: Gather interfaces facts from the device using nxos_interfaces
  cisco.nxos.nxos_interfaces:
    state: gathered
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Task output
# -----------
#
# - name: Ethernet1/1
#   description: outbound-intf
#   mode: layer2
#   enabled: True
# - name: Ethernet1/2
#   description: intf-l3
#   speed: "1000"

# Using purged

# Before state:
# -------------
#
# switch# show running-config | section interface
# interface Vlan1
# interface Vlan42
#   mtu 1800
# interface port-channel10
# interface port-channel11
# interface Ethernet1/1
# interface Ethernet1/2
# interface Ethernet1/2.100
#   description sub-intf

- name: Purge virtual interfaces from running-config
  cisco.nxos.nxos_interfaces:
    config:
      - name: Vlan42
      - name: port-channel10
      - name: Ethernet1/2.100
    state: purged

Inputs

    
state:
    choices:
    - merged
    - replaced
    - overridden
    - deleted
    - gathered
    - rendered
    - parsed
    - purged
    default: merged
    description:
    - The state of the configuration after module completion
    - The state I(rendered) considers the system default mode for interfaces to be "Layer
      3" and the system default state for interfaces to be shutdown.
    - The state I(purged) negates virtual interfaces that are specified in task from running-config.
    type: str

config:
    description: A dictionary of interface options
    elements: dict
    suboptions:
      description:
        description:
        - Interface description.
        type: str
      duplex:
        choices:
        - full
        - half
        - auto
        description:
        - Interface link status. Applicable for Ethernet interfaces only.
        type: str
      enabled:
        description:
        - Administrative state of the interface. Set the value to C(true) to administratively
          enable the interface or C(false) to disable it
        type: bool
      fabric_forwarding_anycast_gateway:
        description:
        - Associate SVI with anycast gateway under VLAN configuration mode. Applicable
          for SVI interfaces only.
        type: bool
      ip_forward:
        description:
        - Enable or disable IP forward feature on SVIs. Set the value to C(true) to enable  or
          C(false) to disable.
        type: bool
      mode:
        choices:
        - layer2
        - layer3
        description:
        - Manage Layer2 or Layer3 state of the interface. Applicable for Ethernet and
          port channel interfaces only.
        type: str
      mtu:
        description:
        - MTU for a specific interface. Must be an even number between 576 and 9216. Applicable
          for Ethernet interfaces only.
        type: str
      name:
        description:
        - Full name of interface, e.g. Ethernet1/1, port-channel10.
        required: true
        type: str
      speed:
        description:
        - Interface link speed. Applicable for Ethernet interfaces only.
        type: str
    type: list

running_config:
    description:
    - This option is used only with state I(parsed).
    - The value of this option should be the output received from the NX-OS device by
      executing the command B(show running-config | section ^interface)
    - The state I(parsed) reads the configuration from C(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 I(parsed) key within the result.
    type: str

Outputs

after:
  description: The configuration as structured data after module completion.
  returned: when changed
  sample: "The configuration returned will always be in the same format\n of the parameters\
    \ above.\n"
  type: list
before:
  description: The configuration as structured data prior to module invocation.
  returned: always
  sample: "The configuration returned will always be in the same format\n of the parameters\
    \ above.\n"
  type: list
commands:
  description: The set of commands pushed to the remote device.
  returned: always
  sample:
  - interface Ethernet1/1
  - mtu 1800
  type: list