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

布尔值

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

选项

  • false

  • true

tcp_keepalives_out

布尔值

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

选项

  • 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 设备收到的输出。

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

state

字符串

配置应保留的状态。

对于 replaced 和 overridden 状态,该模块具有声明相似的行为。

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

选项

  • "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

字典

模块执行后的最终配置。

返回值: 当发生更改时返回

示例: "此 输出 始终 模块 argspec 格式相同。\n"

before

字典

模块执行之前的配置。

返回值:statemergedreplacedoverriddendeletedpurged 时返回

示例: "此 输出 始终 模块 argspec 格式相同。\n"

commands

列表 / 元素=字符串

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

返回值:statemergedreplacedoverriddendeletedpurged 时返回

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

gathered

列表 / 元素=字符串

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

返回值:stategathered 时返回

示例: ["此 输出 始终 模块 argspec 格式相同。\n"]

parsed

列表 / 元素=字符串

按照模块 argspec,将 running_config 选项中提供的设备本机配置解析为结构化数据。

返回值:stateparsed 时返回

示例: ["此 输出 始终 模块 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)