cisco.nxos.nxos_interfaces 模块 – 接口资源模块

注意

此模块是 cisco.nxos 集合 (版本 9.2.1) 的一部分。

如果您使用的是 ansible 软件包,则可能已安装此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用: ansible-galaxy collection install cisco.nxos

要在 playbook 中使用它,请指定: cisco.nxos.nxos_interfaces

cisco.nxos 1.0.0 中的新增功能

概要

  • 此模块管理 NX-OS 接口的接口属性。

参数

参数

注释

config

列表 / 元素=字典

接口选项的字典

description

字符串

接口描述。

duplex

字符串

接口链路状态。仅适用于以太网接口。

选项

  • "full"

  • "half"

  • "auto"

enabled

布尔值

接口的管理状态。将值设置为 true 以在管理上启用接口,或设置为 false 以禁用它。

选项

  • false

  • true

fabric_forwarding_anycast_gateway

布尔值

在 VLAN 配置模式下将 SVI 与 anycast 网关关联。仅适用于 SVI 接口。

选项

  • false

  • true

ip_forward

布尔值

启用或禁用 SVI 上的 IP 转发功能。将值设置为 true 以启用,或设置为 false 以禁用。

选项

  • false

  • true

mode

字符串

管理接口的二层或三层状态。仅适用于以太网和端口通道接口。

选项

  • "layer2"

  • "layer3"

mtu

字符串

特定接口的 MTU。必须是 576 到 9216 之间的偶数。仅适用于以太网接口。

name

字符串 / 必需

接口的全名,例如 Ethernet1/1、port-channel10。

speed

字符串

接口链路速度。仅适用于以太网接口。

running_config

字符串

此选项仅与 state _parsed_ 一起使用。

此选项的值应是从 NX-OS 设备通过执行命令 **show running-config | section ^interface** 收到的输出。

state _parsed_ 从 running_config 选项读取配置并将其转换为 Ansible 结构化数据,根据资源模块的 argspec,然后该值将返回到结果中的 _parsed_ 键中。

state

字符串

模块完成后配置的状态

state _rendered_ 认为接口的系统默认模式为“Layer 3”,接口的系统默认状态为关闭。

state _purged_ 会否定任务中从 running-config 指定的虚拟接口。

选项

  • "merged" ← (默认)

  • "replaced"

  • "overridden"

  • "deleted"

  • "gathered"

  • "rendered"

  • "parsed"

  • "purged"

备注

注意

  • 在 VIRL 上针对 NXOS 7.3.(0)D1(1) 进行了测试

  • 不支持 Cisco MDS

示例

# 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

# 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

# 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

# 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

# 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

# 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

# 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

# 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

# Task output
# ------------
#
# before:
#   - name: Vlan1
#   - mtu: '1800'
#     name: Vlan42
#   - name: port-channel10
#   - name: port-channel11
#   - name: Ethernet1/1
#   - name: Ethernet1/2
#   - description: sub-intf
#     name: Ethernet1/2.100
# commands:
#   - no interface port-channel10
#   - no interface Ethernet1/2.100
#   - no interface Vlan42
# after:
#   - name: Vlan1
#   - name: port-channel11
#   - name: Ethernet1/1
#   - name: Ethernet1/2

# After state:
# -------------
#
# switch# show running-config | section interface
# interface Vlan1
# interface port-channel11
# interface Ethernet1/1
# interface Ethernet1/2

返回值

常见的返回值已在 此处 记录,以下是此模块独有的字段

描述

after

列表 / 元素=字符串

模块完成后作为结构化数据的配置。

返回:已更改时

示例: ["The configuration returned will always be in the same format\n of the parameters above.\n"]

before

列表 / 元素=字符串

模块调用之前的结构化数据配置。

返回:始终返回

示例: ["The configuration returned will always be in the same format\n of the parameters above.\n"]

commands

列表 / 元素=字符串

推送到远程设备的命令集。

返回:始终返回

示例: ["interface Ethernet1/1", "mtu 1800"]

作者

  • Trishna Guha (@trishnaguha)