cisco.ios.ios_service 模块 – 配置服务的资源模块。

注意

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

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

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

要在 playbook 中使用它,请指定: cisco.ios.ios_service

cisco.ios 4.6.0 中的新增功能

摘要

  • 此模块配置和管理 IOS 平台上的服务属性

参数

参数

注释

config

字典

服务的配置字典

call_home

布尔值

Cisco 回拨服务

选项

  • false

  • true

compress_config

布尔值

压缩 nvram 配置文件

选项

  • false

  • true

config

布尔值

TFTP 加载配置文件

选项

  • false

  • true

counters

整数

通过设置最大计数器老化阈值来控制接口计数器的老化。

默认值: 0

dhcp

布尔值

启用 DHCP 服务器和中继代理

选项

  • false

  • true ← (默认)

disable_ip_fast_frag

布尔值

禁用基于粒子的 IP 快速分段

选项

  • false

  • true

exec_callback

布尔值

启用 exec 回调

选项

  • false

  • true

exec_wait

布尔值

延迟在嘈杂线路上的 EXEC 启动

选项

  • false

  • true

hide_telnet_addresses

布尔值

隐藏 telnet 命令中的目标地址

选项

  • false

  • true

internal

布尔值

启用/禁用内部命令

选项

  • false

  • true

linenumber

布尔值

为每个 exec 启用行号横幅

选项

  • false

  • true

log

布尔值

记录回溯

选项

  • false

  • true

log_hidden

布尔值

为隐藏/内部命令启用 syslog 消息

选项

  • false

  • true

nagle

布尔值

启用 Nagle 的拥塞控制算法

选项

  • false

  • true

old_slip_prompts

布尔值

允许旧脚本与 slip/ppp 一起操作

选项

  • false

  • true

pad

布尔值

启用 PAD 命令

选项

  • false

  • true

pad_cmns

布尔值

启用通过 CMNS 连接的 PAD

选项

  • false

  • true

pad_from_xot

布尔值

接受 XOT 到 PAD 的连接

选项

  • false

  • true

pad_to_xot

布尔值

允许通过 XOT 连接发出 PAD

选项

  • false

  • true

password_encryption

布尔值

加密系统密码

选项

  • false

  • true

password_recovery

布尔值

密码恢复

选项

  • false

  • true ← (默认)

private_config_encryption

布尔值

启用私有配置文件加密

选项

  • false

  • true

prompt

布尔值

启用模式特定的提示

选项

  • false

  • true ← (默认)

pt_vty_logging

布尔值

记录重要的 VTY-Async 事件

选项

  • false

  • true

scripting

布尔值

scripting

选项

  • false

  • true

sequence_numbers

布尔值

用序列号标记日志消息

选项

  • false

  • true

slave_coredump

布尔值

slave-coredump

选项

  • false

  • true

slave_log

布尔值

启用从属 IP 的日志功能

选项

  • false

  • true ← (默认)

tcp_keepalives_in

布尔值

在空闲的传入网络连接上生成 keepalives

选项

  • false

  • true

tcp_keepalives_out

布尔值

在空闲的传出网络连接上生成 keepalives

选项

  • false

  • true

tcp_small_servers

字典

TCP 小型服务器是在路由器中运行的服务器(在 Unix 中称为守护进程),可用于诊断。

enable

布尔值

启用小型 TCP 服务器(例如,ECHO)

选项

  • false

  • true

max_servers

整数

设置允许的 TCP 小型服务器数量

1 到 2147483647

no_limit

布尔值

允许的 TCP 小型服务器数量不限

选项

  • false

  • true

telnet_zeroidle

布尔值

连接空闲时将 TCP 窗口设置为 0

选项

  • false

  • true

timestamps

列表 / 元素=字典

时间戳调试/日志消息

datetime_options

字典

日期和时间时间戳的选项

localtime

布尔值

对时间戳使用本地时区

选项

  • false

  • true

msec

布尔值

在时间戳中包含毫秒

选项

  • false

  • true

show_timezone

布尔值

将时区信息添加到时间戳

选项

  • false

  • true

year

布尔值

在时间戳中包含年份

选项

  • false

  • true

enable

布尔值

为选择的邮件启用时间戳

选项

  • false

  • true

msg

字符串

时间戳日志或调试消息

选项

  • "debug"

  • "log"

timestamp

字符串

使用日期和时间或系统运行时间的时间戳

选项

  • "datetime"

  • "uptime"

udp_small_servers

字典

UDP 小型服务器是在路由器中运行的服务器(在 Unix 中称为守护进程),可用于诊断。

enable

布尔值

启用小型 UDP 服务器(例如,ECHO)

选项

  • false

  • true

max_servers

整数

设置允许的 UDP 小型服务器数量

1 到 2147483647

no_limit

布尔值

允许的 UDP 小型服务器数量不限

选项

  • false

  • true

unsupported_transceiver

布尔值

启用对第三方收发器的支持

选项

  • false

  • true

running_config

字符串

此选项仅与状态 *parsed* 一起使用。

此选项的值应为通过执行命令 **show running-config | section ^service|^no service** 从 IOS 设备接收到的输出。

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

state

字符串

配置应保留的状态。

该模块对替换和覆盖状态具有声明性相似的行为。

有关更多详细信息,请参阅示例。

选项

  • "merged" ← (默认)

  • "replaced"

  • "overridden"

  • "deleted"

  • "gathered"

  • "rendered"

  • "parsed"

注释

注意

示例

# Using merged

# Before state:
# -------------

# router-ios#show running-config all | section ^service
# service slave-log
# service timestamps debug datetime msec
# service timestamps log datetime msec
# service private-config-encryption
# service prompt config
# service counters max age 0
# service dhcp
# service call-home
# service password-recovery

- name: Merge provided configuration with device configuration
  cisco.ios.ios_service:
    config:
      tcp_keepalives_in: true
      tcp_keepalives_out: true
      timestamps:
        - msg: debug
          enable: true
          timestamp: datetime
        - msg: log
          enable: true
          timestamp: datetime
      pad: false
      password_encryption: true
    state: merged

# Task Output
# -----------
#
# before:
#   call_home: true
#   counters: 0
#   dhcp: true
#   password_recovery: true
#   private_config_encryption: true
#   prompt: true
#   slave_log: true
#   timestamps:
#   - datetime_options:
#       msec: true
#     msg: debug
#     timestamp: datetime
#   - datetime_options:
#       msec: true
#     msg: log
#     timestamp: datetime
# commands:
# - service password-encryption
# - service tcp-keepalives-in
# - service tcp-keepalives-out
# after:
#   call_home: true
#   counters: 0
#   dhcp: true
#   password_encryption: true
#   password_recovery: true
#   private_config_encryption: true
#   prompt: true
#   slave_log: true
#   tcp_keepalives_in: true
#   tcp_keepalives_out: true
#   timestamps:
#   - datetime_options:
#       msec: true
#     msg: debug
#     timestamp: datetime
#   - datetime_options:
#       msec: true
#     msg: log
#     timestamp: datetime

# After state:
# ------------

# router-ios#show running-config all | section ^service
# service slave-log
# service tcp-keepalives-in
# service tcp-keepalives-out
# service timestamps debug datetime msec
# service timestamps log datetime msec
# service password-encryption
# service private-config-encryption
# service prompt config
# service counters max age 0
# service dhcp
# service call-home
# service password-recovery

# Using replaced

# Before state:
# -------------

# router-ios#show running-config all | section ^service
# service slave-log
# service tcp-keepalives-in
# service tcp-keepalives-out
# service timestamps debug datetime msec
# service timestamps log datetime msec
# service password-encryption
# service private-config-encryption
# service prompt config
# service counters max age 0
# service dhcp
# service call-home
# service password-recovery

- name: Replaces device configuration of services with provided configuration
  cisco.ios.ios_service:
    config:
      timestamps:
        - msg: log
          enable: true
          timestamp: datetime
          datetime_options:
            localtime: true
            msec: true
            show_timezone: true
            year: true
        - msg: debug
          enable: true
          timestamp: datetime
      pad: false
      password_encryption: true
    state: "replaced"

# Task Output
# -----------
#
# before:
#   call_home: true
#   counters: 0
#   dhcp: true
#   password_encryption: true
#   password_recovery: true
#   private_config_encryption: true
#   prompt: true
#   slave_log: true
#   tcp_keepalives_in: true
#   tcp_keepalives_out: true
#   timestamps:
#   - datetime_options:
#       msec: true
#     msg: debug
#     timestamp: datetime
#   - datetime_options:
#       msec: true
#     msg: log
#     timestamp: datetime
# commands:
# - no service call-home
# - no service tcp-keepalives-in
# - no service tcp-keepalives-out
# - no service timestamps log
# - service timestamps log datetime msec localtime show-timezone year
# - no service timestamps debug
# - service timestamps debug datetime
# after:
#   counters: 0
#   dhcp: true
#   password_encryption: true
#   password_recovery: true
#   private_config_encryption: true
#   prompt: true
#   slave_log: true
#   timestamps:
#   - msg: debug
#     timestamp: datetime
#   - datetime_options:
#       localtime: true
#       msec: true
#       show_timezone: true
#       year: true
#     msg: log
#     timestamp: datetime

# After state:
# ------------

# router-ios#show running-config all | section ^service
# service slave-log
# service timestamps debug datetime
# service timestamps log datetime msec localtime show-timezone year
# service password-encryption
# service private-config-encryption
# service prompt config
# service counters max age 0
# service dhcp
# service password-recovery

# Using Deleted

# Before state:
# -------------

# router-ios#show running-config all | section ^service
# service slave-log
# service timestamps debug datetime
# service timestamps log datetime msec localtime show-timezone year
# service password-encryption
# service private-config-encryption
# service prompt config
# service counters max age 0
# service dhcp
# service password-recovery

- name: "Delete service configuration and restore default configuration for some important service (those with a default value in module)"
  cisco.ios.ios_service:
    state: deleted

# Task Output
# -----------
#
# before:
#   counters: 0
#   dhcp: true
#   password_encryption: true
#   password_recovery: true
#   private_config_encryption: true
#   prompt: true
#   slave_log: true
#   timestamps:
#   - msg: debug
#     timestamp: datetime
#   - datetime_options:
#       localtime: true
#       msec: true
#       show_timezone: true
#       year: true
#     msg: log
#     timestamp: datetime
# commands:
# - no service password-encryption
# - no service timestamps debug
# - no service timestamps log
# after:
#   counters: 0
#   dhcp: true
#   password_recovery: true
#   private_config_encryption: true
#   prompt: true
#   slave_log: true

# After state:
# ------------
#
# router-ios#show running-config all | section ^service
# service slave-log
# service private-config-encryption
# service prompt config
# service counters max age 0
# service dhcp
# service password-recovery

# Using gathered

# Before state:
# -------------
#
# router-ios#show running-config all | section ^service
# service slave-log
# service timestamps debug datetime
# service timestamps log datetime msec localtime show-timezone year
# service password-encryption
# service private-config-encryption
# service prompt config
# service counters max age 0
# service dhcp
# service password-recovery

- name: Gather facts of interfaces
  cisco.ios.ios_service:
    config:
    state: gathered

# Task Output
# -----------
#
# gathered:
#   counters: 0
#   dhcp: true
#   password_encryption: true
#   password_recovery: true
#   private_config_encryption: true
#   prompt: true
#   slave_log: true
#   timestamps:
#   - msg: debug
#     timestamp: datetime
#   - datetime_options:
#       localtime: true
#       msec: true
#       show_timezone: true
#       year: true
#     msg: log
#     timestamp: datetime

# Using rendered

- name: Render the commands for provided configuration
  cisco.ios.ios_service:
    config:
      timestamps:
        - msg: log
          enable: true
          timestamp: datetime
          datetime_options:
            localtime: true
            msec: true
            show_timezone: true
            year: true
        - msg: debug
          enable: true
          timestamp: datetime
      pad: false
      password_encryption: true
    state: rendered

# ·Task·Output
# -----------
#
# rendered:
# - service dhcp
# - service password-encryption
# - service password-recovery
# - service prompt config
# - service slave-log
# - service timestamps log datetime msec localtime show-timezone year
# - service timestamps debug datetime

# Using parsed

# File: parsed.cfg
# ----------------
#
# no service pad
# service password-encryption
# service tcp-keepalives-in
# service tcp-keepalives-out
# service timestamps debug datetime msec localtime show-timezone year
# service timestamps log datetime msec localtime show-timezone year
# service counters max age 5

- name: Parse the provided configuration
  cisco.ios.ios_service:
    running_config: "{{ lookup('file', 'parsed.cfg') }}"
    state: parsed

# Task Output
# -----------
#
# parsed:
#   counters: 5
#   dhcp: true
#   password_encryption: true
#   password_recovery: true
#   prompt: true
#   slave_log: true
#   tcp_keepalives_in: true
#   tcp_keepalives_out: true
#   timestamps:
#   - datetime_options:
#       localtime: true
#       msec: true
#       show_timezone: true
#       year: true
#     msg: debug
#     timestamp: datetime
#   - datetime_options:
#       localtime: true
#       msec: true
#       show_timezone: true
#       year: true
#     msg: log
#     timestamp: datetime

返回值

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

描述

after

字典

模块执行后的最终配置。

返回: 当发生更改时

示例: "This output will always be in the same format as the module argspec.\n"

before

字典

模块执行之前的配置。

返回:statemergedreplacedoverriddendeletedpurged

示例: "This output will always be in the same format as the module argspec.\n"

commands

列表 / 元素=字符串

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

返回:statemergedreplacedoverriddendeletedpurged

示例: ["no service config", "service tcp-keepalives-in", "service tcp-keepalives-out"]

gathered

列表 / 元素=字符串

从远程设备收集到的关于网络资源的事实信息,以结构化数据形式呈现。

返回:stategathered

示例: ["This output will always be in the same format as the module argspec.\n"]

parsed

列表 / 元素=字符串

根据模块argspec将running_config选项中提供的设备原生配置解析为结构化数据。

返回:stateparsed

示例: ["This output will always be in the same format as the module argspec.\n"]

rendered

列表 / 元素=字符串

以设备原生格式呈现的任务中提供的配置(离线)。

返回:staterendered

示例: ["service dhcp", "service password-encryption", "service password-recovery", "service prompt config", "service slave-log"]

作者

  • Ambroise Rosset (@earendilfr)

  • Sagar Paul (@KB-perByte)