junipernetworks.junos.junos_command 模块 – 在 Juniper JUNOS 设备上运行任意命令
注意
此模块是 junipernetworks.junos 集合(版本 9.1.0)的一部分。
如果您正在使用 ansible 包,则可能已安装此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list。
要安装它,请使用:ansible-galaxy collection install junipernetworks.junos。您需要更多要求才能使用此模块,有关详细信息,请参阅要求。
要在 playbook 中使用它,请指定:junipernetworks.junos.junos_command。
junipernetworks.junos 1.0.0 中的新功能
概要
- 向 JUNOS 节点发送一组任意命令,并返回从设备读取的结果。此模块包含一个参数,该参数将导致模块等待特定条件,然后返回,如果未满足条件,则超时。 
要求
在执行此模块的主机上需要以下要求。
- jxmlease 
- ncclient (>=v0.5.2) 
参数
| 参数 | 注释 | 
|---|---|
| 要发送到远程 junos 设备的命令。返回命令的结果输出。如果提供了 wait_for 参数,则该模块不会返回,直到满足条件或超过了 retries 的次数。 | |
| 在序列化来自设备的输出时使用的编码方案。这处理如何正确理解输出并将条件路径应用于结果集。对于 rpcs 参数,默认 display 是  选择 
 | |
| 配置命令重试之间等待的间隔(以秒为单位)。如果命令未通过指定的条件,则间隔指示再次尝试该命令之前等待的时间。 默认值:  | |
| match 参数与 wait_for 参数结合使用,以指定匹配策略。有效值为  选择 
 | |
| 指定在被认为失败之前应尝试命令的重试次数。每次重试时,命令都会在目标设备上运行,并针对 wait_for 条件进行评估。 默认值:  | |
| 
 | |
| 指定从命令的输出中评估什么以及应用什么条件。此参数将导致任务等待特定条件为真,然后再继续。如果配置的重试次数未达到条件,则任务失败。请参阅示例。 | 
注释
注意
- 此模块要求在被管理的远程设备上启用 netconf 系统服务。 
- 已针对 vSRX JUNOS 版本 15.1X49-D15.4,vqfx-10000 JUNOS 版本 15.1X53-D60.4 进行测试。 
- 建议的连接是 - netconf。请参阅Junos OS 平台选项。
- 此模块也适用于 - network_cli连接和用于旧版 playbook 的- local连接。
- 有关使用 CLI 和 netconf 的信息,请参阅 :ref:`Junos OS 平台选项指南 - ` 
- 有关使用 Ansible 管理网络设备的更多信息,请参阅 :ref:`Ansible 网络指南 <network_guide>`。 
- 有关使用 Ansible 管理 Juniper 网络设备的更多信息,请参阅 https://ansible.org.cn/ansible-juniper。 
示例
- name: run show version on remote devices
  junipernetworks.junos.junos_command:
    commands: show version
- name: run show version and check to see if output contains Juniper
  junipernetworks.junos.junos_command:
    commands: show version
    wait_for: result[0] contains Juniper
- name: run multiple commands on remote nodes
  junipernetworks.junos.junos_command:
    commands:
      - show version
      - show interfaces
- name: run multiple commands and evaluate the output
  junipernetworks.junos.junos_command:
    commands:
      - show version
      - show interfaces
    wait_for:
      - result[0] contains Juniper
      - result[1] contains Loopback0
- name: run commands and specify the output format
  junipernetworks.junos.junos_command:
    commands: show version
    display: json
- name: run rpc on the remote device
  junipernetworks.junos.junos_command:
    commands: show configuration
    display: set
- name: run rpc on the remote device
  junipernetworks.junos.junos_command:
    rpcs: get-software-information
返回值
通用返回值记录在这里,以下是此模块独有的字段
| 键 | 描述 | 
|---|---|
| 已失败的条件列表 返回: 失败 示例:  | |
| 从命令响应转换成 JSON 格式的 XML 集合 返回: 如果 display 的格式为  示例:  | |
| 来自命令的响应集合 返回: 总是返回,除非出现低级错误(例如操作插件) 示例:  | |
| stdout 的值分割成列表 返回: 总是返回,除非出现低级错误(例如操作插件) 示例:  | 
