cisco.iosxr.iosxr_hostname 模块 – 用于配置主机名的资源模块。

注意

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

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

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

要在 playbook 中使用它,请指定:cisco.iosxr.iosxr_hostname

cisco.iosxr 2.7.0 中的新功能

概要

  • 此模块在 Cisco IOSXR 平台上配置和管理主机名的属性。

参数

参数

注释

config

字典

主机名配置。

hostname

字符串

iosxr box 的主机名。

running_config

字符串

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

此选项的值应是通过执行命令 **show running-config hostname** 从 IOSXR 设备收到的输出。

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

state

字符串

配置应保留的状态

状态 *rendered*、*gathered* 和 *parsed* 不会对设备执行任何更改。

状态 *rendered* 会将 config 选项中的配置转换为特定于平台的 CLI 命令,这些命令将返回在结果中的 *rendered* 键中。对于状态 *rendered*,不需要与远程主机的活动连接。

状态 *merged*、*replaced* 和 *overridden* 对于此模块具有相同的行为。

状态 *gathered* 将从设备获取运行配置,并按照资源模块 argspec 将其转换为结构化数据,并且该值将返回在结果中的 *gathered* 键内。

状态 *parsed* 从 running_config 选项读取配置,并按照资源模块参数将其转换为 JSON 格式,该值将返回在结果中的 *parsed* 键内。running_config 选项的值应与在设备上执行的命令 *show running-config hostname* 的输出格式相同。对于状态 *parsed*,不需要与远程主机的活动连接。

选择

  • "deleted"

  • "merged" ←(默认)

  • "overridden"

  • "replaced"

  • "gathered"

  • "rendered"

  • "parsed"

备注

注意

  • 已针对 Cisco Iosxr 7.0.2 进行测试

  • 此模块使用连接 network_cli

示例

# Using state: merged
# Before state:
# -------------

# RP/0/RP0/CPU0:ios#show running-config hostname
# Thu Jan 20 19:48:56.011 UTC
# hostname ios

# Merged play:
# ------------

- name: Apply the provided configuration
  cisco.iosxr.iosxr_hostname:
    config:
      hostname: Router1
    state: merged

# Commands Fired:
# ---------------
# "commands": [
#         "hostname Router1",
# ],

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

# RP/0/0/CPU0:Router1#show running-config hostname
# Thu Jan 20 19:48:56.011 UTC
# hostname Router1


# Using state: deleted
# Before state:
# -------------

# RP/0/0/CPU0:Router1#show running-config hostname
# Thu Jan 20 19:48:56.011 UTC
# hostname Router1

# Deleted play:
# -------------

- name: Remove all existing configuration
  cisco.iosxr.iosxr_hostname:
    state: deleted

# Commands Fired:
# ---------------

# "commands": [
#     "no hostname Router1",
# ],

# After state:
# ------------
# RP/0/RP0/CPU0:ios#show running-config hostname
# Thu Jan 20 19:55:12.971 UTC
# hostname ios

# Using state: overridden
# Before state:
# -------------

# RP/0/0/CPU0:ios#show running-config hostname
# hostname ios

# Overridden play:
# ----------------

- name: Override commands with provided configuration
  cisco.iosxr.iosxr_hostname:
    config:
      hostname: RouterTest
    state: overridden

# Commands Fired:
# ---------------
# "commands": [
#       "hostname RouterTest",
#     ],

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

# RP/0/RP0/CPU0:RouterTest#show running-config hostname
# Thu Jan 20 19:48:56.011 UTC
# hostname RouterTest

# Using state: replaced
# Before state:
# -------------

# RP/0/RP0/CPU0:RouterTest#show running-config hostname
# Thu Jan 20 19:48:56.011 UTC
# hostname RouterTest

# Replaced play:
# --------------

- name: Replace commands with provided configuration
  cisco.iosxr.iosxr_hostname:
    config:
      hostname: RouterTest
    state: replaced

# Commands Fired:
# ---------------
# "commands": [],

# After state:
# ------------
# RP/0/0/CPU0:RouterTest#show running-config hostname
# hostname RouterTest

# Using state: gathered
# Before state:
# -------------

# RP/0/RP0/CPU0:RouterTest#show running-config hostname
# Thu Jan 20 19:48:56.011 UTC
# hostname RouterTest

# Gathered play:
# --------------

- name: Gather listed hostname config
  cisco.iosxr.iosxr_hostname:
    state: gathered

# Module Execution Result:
# ------------------------
#   "gathered": {
#      "hostname": "RouterTest"
#     },

# Using state: rendered
# Rendered play:
# --------------

- name: Render the commands for provided configuration
  cisco.iosxr.iosxr_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.iosxr.iosxr_hostname:
    running_config: "{{ lookup('file', 'parsed.cfg') }}"
    state: parsed

# Module Execution Result:
# ------------------------
#  "parsed": {
#     "hostname": "RouterTest"
# }

返回值

通用返回值记录在此处,以下是此模块独有的字段

描述

after

字典

模块执行后的结果配置。

已返回:当更改时

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

before

字典

模块执行之前的配置。

已返回:当 *state* 为 mergedreplacedoverriddendeletedpurged

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

commands

列表 / elements=字符串

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

已返回:当 *state* 为 mergedreplacedoverriddendeletedpurged

示例:["hostname Router1"]

gathered

列表 / elements=字符串

从远程设备收集的有关网络资源的结构化数据的事实。

已返回:当 *state* 为 gathered

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

parsed

列表 / elements=字符串

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

已返回:当 *state* 为 parsed

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

rendered

列表 / elements=字符串

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

已返回:当 *state* 为 rendered

示例:["hostname Router1"]

作者

  • Ashwini Mhatre (@amhatre)