cisco.ios.ios_hostname 模块 – 配置主机名的资源模块。
注意
此模块是 cisco.ios 集合 (版本 9.0.3) 的一部分。
如果您使用的是 ansible 包,则可能已安装此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list。
要安装它,请使用: ansible-galaxy collection install cisco.ios。
要在 playbook 中使用它,请指定: cisco.ios.ios_hostname。
cisco.ios 2.7.0 中的新增功能
概要
- 此模块提供对 Cisco IOS 设备上主机名的声明式管理。 
参数
| 参数 | 注释 | 
|---|---|
| 主机名选项的字典 | |
| 设置 IOS 的主机名 | |
| 此选项仅与状态 *parsed* 一起使用。 此选项的值应为通过执行命令 **show running-config | section ^hostname** 从 IOS 设备接收到的输出。 状态 *parsed* 从  | |
| 配置应保留的状态 状态 *rendered*、*gathered* 和 *parsed* 不会对设备进行任何更改。 状态 *rendered* 将  对于此模块,状态 *merged*、*replaced* 和 *overridden* 的行为相同。 状态 *gathered* 将从设备获取运行配置,并将其转换为符合资源模块 argspec 格式的结构化数据,该值将返回结果中的 *gathered* 键中。 状态 *parsed* 从  选项 
 | 
备注
注意
- 在 CML 上针对 Cisco IOS XE 版本 17.3 进行测试。 
- 此模块与连接 - network_cli配合使用。
示例
# Using state: merged
# Before state:
# -------------
# router-ios#show running-config | section ^hostname
# hostname Router
# Merged play:
# ------------
- name: Apply the provided configuration
  cisco.ios.ios_hostname:
    config:
      hostname: Router1
    state: merged
# Commands Fired:
# ---------------
# "commands": [
#         "hostname Router1",
# ],
# After state:
# ------------
# router-ios#show running-config | section ^hostname
# hostname Router1
# Using state: deleted
# Before state:
# -------------
# router-ios#show running-config | section ^hostname
# hostname RouterTest
# Deleted play:
# -------------
- name: Remove all existing configuration
  cisco.ios.ios_hostname:
    state: deleted
# Commands Fired:
# ---------------
# "commands": [
#     "no hostname RouterTest",
# ],
# After state:
# ------------
# router-ios#show running-config | section ^hostname
# hostname Router
# Using state: overridden
# Before state:
# -------------
# router-ios#show running-config | section ^hostname
# hostname Router
# Overridden play:
# ----------------
- name: Override commands with provided configuration
  cisco.ios.ios_hostname:
    config:
      hostname: RouterTest
    state: overridden
# Commands Fired:
# ---------------
# "commands": [
#       "hostname RouterTest",
#     ],
# After state:
# ------------
# router-ios#show running-config | section ^hostname
# hostname RouterTest
# Using state: replaced
# Before state:
# -------------
# router-ios#show running-config | section ^hostname
# hostname RouterTest
# Replaced play:
# --------------
- name: Replace commands with provided configuration
  cisco.ios.ios_hostname:
    config:
      hostname: RouterTest
    state: replaced
# Commands Fired:
# ---------------
# "commands": [],
# After state:
# ------------
# router-ios#show running-config | section ^hostname
# hostname RouterTest
# Using state: gathered
# Before state:
# -------------
# router-ios#show running-config | section ^hostname
# hostname RouterTest
# Gathered play:
# --------------
- name: Gather listed hostname config
  cisco.ios.ios_hostname:
    state: gathered
# Module Execution Result:
# ------------------------
#   "gathered": {
#      "hostname": "RouterTest"
#     },
# Using state: rendered
# Rendered play:
# --------------
- name: Render the commands for provided configuration
  cisco.ios.ios_hostname:
    config:
      hostname: RouterTest
    state: rendered
# Module Execution Result:
# ------------------------
# "rendered": [
#     "hostname RouterTest",
# ]
# Using state: parsed
# File: parsed.cfg
# ----------------
# hostname RouterTest
# Parsed play:
# ------------
- name: Parse the provided configuration with the existing running configuration
  cisco.ios.ios_hostname:
    running_config: "{{ lookup('file', 'parsed.cfg') }}"
    state: parsed
# Module Execution Result:
# ------------------------
#  "parsed": {
#     "hostname": "RouterTest"
# }
返回值
常见的返回值已在 此处 记录,以下是此模块特有的字段
| 键 | 描述 | 
|---|---|
| 模块执行后的结果配置。 返回:发生更改时 示例:  | |
| 模块执行之前的配置。 返回:当 state 为  示例:  | |
| 推送到远程设备的命令集。 返回:当 state 为  示例:  | |
| 从远程设备收集到的网络资源信息,以结构化数据的形式呈现。 返回:当state 为  示例:  | |
| 根据模块argspec,将running_config选项中提供的设备原生配置解析成结构化数据。 返回:当state 为  示例:  | |
| 以设备原生格式(离线)呈现任务中提供的配置。 返回:当state 为  示例:  | 
