cisco.iosxr.iosxr_command 模块 – 在远程设备上运行命令的模块。
注意
此模块是 cisco.iosxr 集合(版本 10.2.2)的一部分。
如果您使用的是 ansible
包,您可能已经安装了此集合。它不包含在 ansible-core
中。要检查是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用:ansible-galaxy collection install cisco.iosxr
。
要在 playbook 中使用它,请指定:cisco.iosxr.iosxr_command
。
cisco.iosxr 1.0.0 中的新功能
概要
向 IOS XR 节点发送任意命令,并返回从设备读取的结果。此模块包含一个参数,该参数将导致模块在返回之前等待特定条件,或者如果未满足条件则超时。
此模块不支持在配置模式下运行命令。请使用 cisco.iosxr.iosxr_config 来配置 iosxr 设备。
参数
参数 |
注释 |
---|---|
要通过配置的提供程序发送到远程 iosxr 设备的命令列表。将返回命令的结果输出。如果提供了 wait_for 参数,则在满足条件或重试次数到期之前,模块不会返回。 如果发送到设备的命令需要回答提示,则可以传递包含命令、答案和提示的字典。常见的答案是 ‘y’ 或 “\r”(回车符,必须使用双引号)。请参阅示例 |
|
配置重试命令之间等待的秒数间隔。如果命令未通过指定的条件,则间隔指示在再次尝试命令之前等待多长时间。 默认值: |
|
match 参数与 wait_for 参数结合使用,以指定匹配策略。有效值为 选择
|
|
指定在认为命令失败之前应尝试的重试次数。每次重试都会在目标设备上运行命令,并根据 wait_for 条件进行评估。 默认值: |
|
要针对命令输出评估的条件列表。任务将等待每个条件为真,然后再继续前进。如果在配置的重试次数内条件不为真,则任务失败。请参阅示例。 |
说明
注意
确保用户已被授权执行命令 terminal length 0、terminal width 512 和 terminal exec prompt no-timestamp。
此模块与
network_cli
一起使用。请参阅 IOS-XR 平台选项。此模块不支持
netconf
连接。有关使用 Ansible 管理网络设备的更多信息,请参阅:ref:`Ansible 网络指南 <network_guide>`
有关使用 Ansible 管理 Cisco 设备的更多信息,请参阅 `Cisco 集成页面 <https://ansible.org.cn/integrations/networks/cisco>`_。
示例
- name: run show version on remote devices
cisco.iosxr.iosxr_command:
commands: show version
- name: run show version and check to see if output contains iosxr
cisco.iosxr.iosxr_command:
commands: show version
wait_for: result[0] contains IOS-XR
- name: run multiple commands on remote nodes
cisco.iosxr.iosxr_command:
commands:
- show version
- show interfaces
- {command: example command that prompts, prompt: expected prompt, answer: true}
- name: run multiple commands and evaluate the output
cisco.iosxr.iosxr_command:
commands:
- show version
- show interfaces
wait_for:
- result[0] contains IOS-XR
- result[1] contains Loopback0
- name: 'multiple prompt, multiple answer (mandatory check for all prompts)'
cisco.iosxr.iosxr_command:
commands:
- command: key config-key password-encryption
prompt:
- 'Enter old key :'
- 'Enter new key :'
- 'Enter confirm key :'
answer:
- test1234
- test12345
- test12345
check_all: true
返回值
常见的返回值记录在此处,以下是此模块特有的字段
键 |
描述 |
---|---|
失败的条件列表 返回:失败 示例: |
|
来自命令的响应集 返回:始终返回,除了低级错误(例如操作插件) 示例: |
|
stdout 的值拆分为列表 返回:始终返回,除了低级错误(例如操作插件) 示例: |