cisco.ios.ios_interfaces 模块 – 配置接口的资源模块。
注意
此模块是 cisco.ios 集合 (版本 9.0.3) 的一部分。
如果您使用的是 ansible
包,则可能已经安装了此集合。它不包含在 ansible-core
中。要检查它是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用: ansible-galaxy collection install cisco.ios
。
要在playbook中使用它,请指定: cisco.ios.ios_interfaces
。
cisco.ios 1.0.0 中的新增功能
概要
此模块管理Cisco IOS网络设备的接口属性。
参数
参数 |
注释 |
---|---|
接口选项的字典 |
|
接口描述。 |
|
接口链路状态。仅适用于以太网接口,可以是半双工、全双工或自动状态(自动协商双工)。 选项
|
|
接口的管理状态。 将值设置为 选项
|
|
管理接口的二层或三层状态。 对于二层设备模式,Layer2 添加 switchport 命令(默认影响幂等性)。 对于二层设备模式,Layer3 添加 no switchport 命令。 对于三层设备模式,Layer3/2 没有影响,应用命令会失败。 选项
|
|
特定接口的MTU。仅适用于以太网接口。 请参考厂商文档以了解有效值。 |
|
接口的全名,例如 GigabitEthernet0/2、loopback999。 |
|
接口链路速度。仅适用于以太网接口。 |
|
IOS模板名称。 |
|
此选项仅与 state parsed 一起使用。 此选项的值应是从 IOS 设备执行命令 **show running-config | section ^interface** 接收到的输出。 state parsed 从 |
|
配置应保留的状态 状态 rendered、gathered 和 parsed 不会对设备进行任何更改。 状态 rendered 将 状态 gathered 将从设备获取运行配置并将其转换为结构化数据(格式根据资源模块 argspec),并将值返回结果中的 gathered 键。 状态 parsed 从 状态 purged 会从运行配置中删除任务中指定的虚拟/逻辑接口。 选项
|
备注
注意
在 CML 上针对 Cisco IOSXE 版本 17.3 进行了测试。
此模块与连接
network_cli
一起使用。请参见 https://docs.ansible.org.cn/ansible/latest/network/user_guide/platform_ios.html模块示例使用回调插件 (stdout_callback = yaml) 以 yaml 格式生成任务输出。
示例
# Using merged
# Before state:
# -------------
#
# Router#sh running-config | section interface
# interface Loopback888
# no ip address
# interface Loopback999
# no ip address
# interface GigabitEthernet1
# ip address dhcp
# negotiation auto
# interface GigabitEthernet2
# description Configured and Merged by Ansible Network
# ip address dhcp
# speed 1000
# no negotiation auto
# interface GigabitEthernet3
# no ip address
# speed 1000
# no negotiation auto
# interface GigabitEthernet4
# no ip address
# shutdown
# negotiation auto
- name: Merge provided configuration with device configuration
cisco.ios.ios_interfaces:
config:
- name: GigabitEthernet2
description: Configured and Merged by Ansible Network
enabled: true
- name: GigabitEthernet3
description: Configured and Merged by Ansible Network
mtu: 3800
enabled: false
speed: 100
duplex: full
state: merged
# Task Output
# -----------
#
# before:
# - enabled: true
# name: GigabitEthernet1
# - description: Configured and Merged by Ansible Network
# enabled: true
# name: GigabitEthernet2
# speed: '1000'
# - description: Configured and Merged by Ansible Network
# enabled: false
# mtu: 3800
# name: GigabitEthernet3
# speed: '1000'
# - enabled: false
# name: GigabitEthernet4
# - enabled: true
# name: Loopback888
# - enabled: true
# name: Loopback999
# commands:
# - interface GigabitEthernet3
# - description Configured and Merged by Ansible Network
# - speed 100
# - mtu 3800
# - duplex full
# - shutdown
# after:
# - enabled: true
# name: GigabitEthernet1
# - description: Configured and Merged by Ansible Network
# enabled: true
# name: GigabitEthernet2
# speed: '1000'
# - description: Configured and Merged by Ansible Network
# enabled: true
# mtu: 2800
# name: GigabitEthernet3
# speed: '1000'
# - enabled: false
# name: GigabitEthernet4
# - enabled: true
# name: Loopback888
# - enabled: true
# name: Loopback999
# After state:
# ------------
#
# Router#show running-config | section ^interface
# interface Loopback888
# no ip address
# interface Loopback999
# no ip address
# interface GigabitEthernet1
# ip address dhcp
# negotiation auto
# interface GigabitEthernet2
# description Configured and Merged by Ansible Network
# ip address dhcp
# speed 1000
# no negotiation auto
# interface GigabitEthernet3
# description Configured and Merged by Ansible Network
# mtu 3800
# no ip address
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet4
# no ip address
# shutdown
# negotiation auto
# Using merged - with mode attribute
# Before state:
# -------------
#
# vios#show running-config | section ^interface
# interface GigabitEthernet1
# description Configured by Ansible
# interface GigabitEthernet2
# description This is test
# interface GigabitEthernet3
# description This is test
# no switchport
- name: Merge provided configuration with device configuration
cisco.ios.ios_interfaces:
config:
- name: GigabitEthernet2
description: Configured and Merged by Ansible Network
enabled: true
mode: layer2
- name: GigabitEthernet3
description: Configured and Merged by Ansible Network
mode: layer3
state: merged
# Task Output
# -----------
#
# before:
# - enabled: true
# name: GigabitEthernet1
# - description: Configured and Merged by Ansible Network
# name: GigabitEthernet2
# - description: Configured and Merged by Ansible Network
# name: GigabitEthernet3
# commands:
# - interface GigabitEthernet2
# - description Configured and Merged by Ansible Network
# - switchport
# - interface GigabitEthernet3
# - description Configured and Merged by Ansible Network
# after:
# - enabled: true
# name: GigabitEthernet1
# - description: Configured and Merged by Ansible Network
# enabled: true
# name: GigabitEthernet2
# - description: Configured and Merged by Ansible Network
# name: GigabitEthernet3
# mode: layer3
# After state:
# ------------
#
# vios#show running-config | section ^interface
# interface GigabitEthernet1
# description Configured by Ansible
# interface GigabitEthernet2
# description Configured and Merged by Ansible Network
# interface GigabitEthernet3
# description Configured and Merged by Ansible Network
# no switchport
# Using replaced
# Before state:
# -------------
#
# vios#show running-config | section ^interface
# interface Loopback888
# no ip address
# interface Loopback999
# no ip address
# interface GigabitEthernet1
# description Management interface do not change
# ip address dhcp
# negotiation auto
# interface GigabitEthernet2
# ip address dhcp
# speed 1000
# no negotiation auto
# interface GigabitEthernet3
# no ip address
# speed 1000
# no negotiation auto
# interface GigabitEthernet4
# no ip address
# shutdown
# negotiation auto
# interface Vlan50
# ip address dhcp hostname testHostname
- name: Replaces device configuration of listed interfaces with provided configuration
cisco.ios.ios_interfaces:
config:
- name: GigabitEthernet3
description: Configured and Replaced by Ansible Network
enabled: false
speed: 1000
state: replaced
# Task Output
# -----------
#
# before:
# - description: Management interface do not change
# enabled: true
# name: GigabitEthernet1
# - enabled: true
# name: GigabitEthernet2
# speed: '1000'
# - enabled: true
# name: GigabitEthernet3
# speed: '1000'
# - enabled: false
# name: GigabitEthernet4
# - enabled: true
# name: Loopback888
# - enabled: true
# name: Loopback999
# - enabled: true
# name: Vlan50
# commands:
# - interface GigabitEthernet3
# - description Configured and Replaced by Ansible Network
# - shutdown
# after:
# - description: Management interface do not change
# enabled: true
# name: GigabitEthernet1
# - enabled: true
# name: GigabitEthernet2
# speed: '1000'
# - description: Configured and Replaced by Ansible Network
# enabled: false
# name: GigabitEthernet3
# speed: '1000'
# - enabled: false
# name: GigabitEthernet4
# - enabled: true
# name: Loopback888
# - enabled: true
# name: Loopback999
# - enabled: true
# name: Vlan50
# After state:
# -------------
#
# vios#show running-config | section ^interface
# interface Loopback888
# no ip address
# interface Loopback999
# no ip address
# interface GigabitEthernet1
# description Management interface do not change
# ip address dhcp
# negotiation auto
# interface GigabitEthernet2
# ip address dhcp
# speed 1000
# no negotiation auto
# interface GigabitEthernet3
# description Configured and Replaced by Ansible Network
# no ip address
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet4
# no ip address
# shutdown
# negotiation auto
# interface Vlan50
# ip address dhcp hostname testHostname
# Using overridden
# Before state:
# -------------
#
# vios#show running-config | section ^interface
# interface Loopback888
# no ip address
# interface Loopback999
# no ip address
# interface GigabitEthernet1
# description Management interface do not change
# ip address dhcp
# negotiation auto
# interface GigabitEthernet2
# ip address dhcp
# speed 1000
# no negotiation auto
# interface GigabitEthernet3
# description Configured and Replaced by Ansible Network
# no ip address
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet4
# no ip address
# shutdown
# negotiation auto
# interface Vlan50
# ip address dhcp hostname testHostname
- name: Override device configuration of all interfaces with provided configuration
cisco.ios.ios_interfaces:
config:
- description: Management interface do not change
enabled: true
name: GigabitEthernet1
- name: GigabitEthernet2
description: Configured and Overridden by Ansible Network
speed: 10000
- name: GigabitEthernet3
description: Configured and Overridden by Ansible Network
enabled: false
state: overridden
# Task Output
# -----------
#
# before:
# - description: Management interface do not change
# enabled: true
# name: GigabitEthernet1
# - enabled: true
# name: GigabitEthernet2
# speed: '1000'
# - description: Configured and Replaced by Ansible Network
# enabled: false
# name: GigabitEthernet3
# speed: '1000'
# - enabled: false
# name: GigabitEthernet4
# - enabled: true
# name: Loopback888
# - enabled: true
# name: Loopback999
# - enabled: true
# name: Vlan50
# commands:
# - interface loopback888
# - shutdown
# - interface loopback999
# - shutdown
# - interface Vlan50
# - shutdown
# - interface GigabitEthernet2
# - description Configured and Overridden by Ansible Network
# - speed 10000
# - interface GigabitEthernet3
# - description Configured and Overridden by Ansible Network
# - no speed 1000
# after:
# - description: Management interface do not change
# enabled: true
# name: GigabitEthernet1
# - description: Configured and Overridden by Ansible Network
# enabled: true
# name: GigabitEthernet2
# speed: '10000'
# - description: Configured and Overridden by Ansible Network
# enabled: false
# name: GigabitEthernet3
# speed: '1000'
# - enabled: false
# name: GigabitEthernet4
# - enabled: false
# name: Loopback888
# - enabled: false
# name: Loopback999
# - enabled: false
# name: Vlan50
# After state:
# -------------
#
# vios#show running-config | section ^interface
# interface Loopback888
# no ip address
# shutdown
# interface Loopback999
# no ip address
# shutdown
# interface GigabitEthernet1
# description Management interface do not change
# ip address dhcp
# negotiation auto
# interface GigabitEthernet2
# description Configured and Overridden by Ansible Network
# ip address dhcp
# speed 10000
# no negotiation auto
# interface GigabitEthernet3
# description Configured and Overridden by Ansible Network
# no ip address
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet4
# no ip address
# shutdown
# negotiation auto
# interface Vlan50
# ip address dhcp hostname testHostname
# shutdown
# Using Deleted
# Before state:
# -------------
#
# vios#show running-config | section ^interface
# interface Loopback888
# no ip address
# shutdown
# interface Loopback999
# no ip address
# shutdown
# interface GigabitEthernet1
# description Management interface do not change
# ip address dhcp
# negotiation auto
# interface GigabitEthernet2
# description Configured and Overridden by Ansible Network
# ip address dhcp
# speed 10000
# no negotiation auto
# interface GigabitEthernet3
# description Configured and Overridden by Ansible Network
# no ip address
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet4
# no ip address
# shutdown
# negotiation auto
# interface Vlan50
# ip address dhcp hostname testHostname
# shutdown
- name: "Delete interface attributes (Note: This won't delete the interface itself)"
cisco.ios.ios_interfaces:
config:
- name: GigabitEthernet2
state: deleted
# Task Output
# -----------
#
# before:
# - description: Management interface do not change
# enabled: true
# name: GigabitEthernet1
# - description: Configured and Overridden by Ansible Network
# enabled: true
# name: GigabitEthernet2
# speed: '10000'
# - description: Configured and Overridden by Ansible Network
# enabled: false
# name: GigabitEthernet3
# speed: '1000'
# - enabled: false
# name: GigabitEthernet4
# - enabled: false
# name: Loopback888
# - enabled: false
# name: Loopback999
# - enabled: false
# name: Vlan50
# commands:
# - interface GigabitEthernet2
# - no description Configured and Overridden by Ansible Network
# - no speed 10000
# - shutdown
# after:
# - description: Management interface do not change
# enabled: true
# name: GigabitEthernet1
# - enabled: false
# name: GigabitEthernet2
# speed: '1000'
# - description: Configured and Overridden by Ansible Network
# enabled: false
# name: GigabitEthernet3
# speed: '1000'
# - enabled: false
# name: GigabitEthernet4
# - enabled: false
# name: Loopback888
# - enabled: false
# name: Loopback999
# - enabled: false
# name: Vlan50
# After state:
# -------------
#
# vios#show running-config | section ^interface
# interface Loopback888
# no ip address
# shutdown
# interface Loopback999
# no ip address
# shutdown
# interface GigabitEthernet1
# description Management interface do not change
# ip address dhcp
# negotiation auto
# interface GigabitEthernet2
# ip address dhcp
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet3
# description Configured and Overridden by Ansible Network
# no ip address
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet4
# no ip address
# shutdown
# negotiation auto
# interface Vlan50
# ip address dhcp hostname testHostname
# shutdown
# Using Purged
# Before state:
# -------------
#
# vios#show running-config | section ^interface
# interface Loopback888
# no ip address
# shutdown
# interface Loopback999
# no ip address
# shutdown
# interface GigabitEthernet1
# description Management interface do not change
# ip address dhcp
# negotiation auto
# interface GigabitEthernet2
# ip address dhcp
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet3
# description Configured and Overridden by Ansible Network
# no ip address
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet4
# no ip address
# shutdown
# negotiation auto
# interface Vlan50
# ip address dhcp hostname testHostname
# shutdown
- name: "Purge given interfaces (Note: This will delete the interface itself)"
cisco.ios.ios_interfaces:
config:
- name: Loopback888
- name: Vlan50
state: purged
# Task Output
# -----------
#
# before:
# - description: Management interface do not change
# enabled: true
# name: GigabitEthernet1
# - enabled: false
# name: GigabitEthernet2
# speed: '1000'
# - description: Configured and Overridden by Ansible Network
# enabled: false
# name: GigabitEthernet3
# speed: '1000'
# - enabled: false
# name: GigabitEthernet4
# - enabled: false
# name: Loopback888
# - enabled: false
# name: Loopback999
# - enabled: false
# name: Vlan50
# commands:
# - no interface loopback888
# - no interface Vlan50
# after:
# - description: Management interface do not change
# enabled: true
# name: GigabitEthernet1
# - enabled: false
# name: GigabitEthernet2
# speed: '1000'
# - description: Configured and Overridden by Ansible Network
# enabled: false
# name: GigabitEthernet3
# speed: '1000'
# - enabled: false
# name: GigabitEthernet4
# - enabled: false
# name: Loopback999
# After state:
# -------------
#
# vios#show running-config | section ^interface
# interface Loopback999
# no ip address
# shutdown
# interface GigabitEthernet1
# description Management interface do not change
# ip address dhcp
# negotiation auto
# interface GigabitEthernet2
# ip address dhcp
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet3
# description Configured and Overridden by Ansible Network
# no ip address
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet4
# no ip address
# shutdown
# negotiation auto
# Using gathered
# Before state:
# -------------
#
# vios#sh running-config | section ^interface
# interface Loopback999
# no ip address
# shutdown
# interface GigabitEthernet1
# description Management interface do not change
# ip address dhcp
# negotiation auto
# interface GigabitEthernet2
# ip address dhcp
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet3
# description Configured and Overridden by Ansible Network
# no ip address
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet4
# no ip address
# shutdown
# negotiation auto
- name: Gather facts of interfaces
cisco.ios.ios_interfaces:
config:
state: gathered
# Task Output
# -----------
#
# gathered:
# - description: Management interface do not change
# enabled: true
# name: GigabitEthernet1
# - enabled: false
# name: GigabitEthernet2
# speed: '1000'
# - description: Configured and Overridden by Ansible Network
# enabled: false
# name: GigabitEthernet3
# speed: '1000'
# - enabled: false
# name: GigabitEthernet4
# - enabled: false
# name: Loopback999
# Using rendered
- name: Render the commands for provided configuration
cisco.ios.ios_interfaces:
config:
- name: GigabitEthernet1
description: Configured by Ansible-Network
mtu: 110
enabled: true
duplex: half
- name: GigabitEthernet2
description: Configured by Ansible-Network
mtu: 2800
enabled: false
speed: 100
duplex: full
state: rendered
# Task Output
# -----------
#
# rendered:
# - interface GigabitEthernet1
# - description Configured by Ansible-Network
# - mtu 110
# - duplex half
# - no shutdown
# - interface GigabitEthernet2
# - description Configured by Ansible-Network
# - speed 100
# - mtu 2800
# - duplex full
# - shutdown
# Using parsed
# File: parsed.cfg
# ----------------
#
# interface Loopback999
# no ip address
# shutdown
# interface GigabitEthernet1
# description Management interface do not change
# ip address dhcp
# negotiation auto
# interface GigabitEthernet2
# ip address dhcp
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet3
# description Configured and Overridden by Ansible Network
# no ip address
# shutdown
# speed 1000
# no negotiation auto
# interface GigabitEthernet4
# no ip address
# shutdown
# negotiation auto
- name: Parse the provided configuration
cisco.ios.ios_interfaces:
running_config: "{{ lookup('file', 'parsed.cfg') }}"
state: parsed
# Task Output
# -----------
#
# parsed:
# - description: Management interface do not change
# enabled: true
# name: GigabitEthernet1
# - enabled: false
# name: GigabitEthernet2
# speed: '1000'
# - description: Configured and Overridden by Ansible Network
# enabled: false
# name: GigabitEthernet3
# speed: '1000'
# - enabled: false
# name: GigabitEthernet4
# - enabled: false
# name: Loopback999
返回值
常见的返回值已在 此处 记录,以下是此模块特有的字段
键 |
描述 |
---|---|
模块执行后的结果配置。 返回:已更改时 示例: |
|
模块执行之前的配置。 返回:当 state 为 示例: |
|
推送到远程设备的命令集。 返回:当 state 为 示例: |
|
从远程设备收集的关于网络资源的结构化数据事实。 返回:当 state 为 示例: |
|
根据模块 argspec 将 running_config 选项中提供的设备原生配置解析为结构化数据。 返回:当 state 为 示例: |
|
以设备原生格式(离线)渲染的任务中提供的配置。 返回:当 state 为 示例: |