dellemc.enterprise_sonic.sonic_command 模块 – 在运行 Enterprise SONiC 的设备上运行命令
注意
此模块是 dellemc.enterprise_sonic 集合(版本 2.5.1)的一部分。
如果您使用的是 ansible 包,您可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list。
要安装它,请使用:ansible-galaxy collection install dellemc.enterprise_sonic。
要在 playbook 中使用它,请指定:dellemc.enterprise_sonic.sonic_command。
dellemc.enterprise_sonic 1.0.0 中的新增功能
概要
- 在运行 Dell Technologies 的 Enterprise SONiC 发行版的远程设备上运行命令。将任意命令发送到 Enterprise SONiC 节点,并返回从设备读取的结果。此模块包含一个参数,该参数使模块在返回之前等待特定条件,或者在条件不满足时超时。 
- 此模块不支持在配置模式下运行命令。要配置 SONiC 设备,请使用 dellemc.enterprise_sonic.sonic_config。 
注意
此模块具有相应的 操作插件。
参数
| 参数 | 注释 | 
|---|---|
| 通过配置的 provider 发送到远程 Enterprise SONiC 设备的命令列表。返回命令的输出结果。如果提供了 wait_for 参数,则在满足条件或重试次数过期之前,模块不会返回。如果发送到设备的命令需要回答提示,则可以传递包含 command、answer 和 prompt 的字典。常见的答案是“yes”或 “\r”(回车符,必须使用双引号)。请参阅示例。 | |
| 配置在重试命令之间等待的秒数间隔。如果命令未通过指定的条件,则间隔指示在再次尝试命令之前等待多长时间。 默认值:  | |
| match 参数与 wait_for 参数结合使用,以指定匹配策略。有效值为  选择 
 | |
| 指定命令在被视为失败之前应运行的重试次数。每次重试时,命令都会在目标设备上运行,并根据 wait_for 条件进行评估。 默认值:  | |
| 要根据命令输出评估的条件列表。任务会等待每个条件为 true,然后再继续执行。如果在配置的重试次数内条件不为 true,则任务将失败。请参阅示例。 | 
注意
注意
- 已针对 Dell Technologies 的 Enterprise SONiC 发行版进行了测试。 
- 支持 - check_mode。
示例
- name: Runs show version on remote devices
  dellemc.enterprise_sonic.sonic_command:
    commands: show version
- name: Runs show version and checks to see if output contains 'Dell'
  dellemc.enterprise_sonic.sonic_command:
    commands: show version
    wait_for: result[0] contains Dell
- name: Runs multiple commands on remote nodes
  dellemc.enterprise_sonic.sonic_command:
    commands:
      - show version
      - show interface
- name: Runs multiple commands and evaluate the output
  dellemc.enterprise_sonic.sonic_command:
    commands:
      - 'show version'
      - 'show system'
    wait_for:
      - result[0] contains Dell
      - result[1] contains Hostname
- name: Runs commands that require answering a prompt
  dellemc.enterprise_sonic.sonic_command:
    commands:
      - command: 'reload'
        prompt: '[confirm yes/no]: ?$'
        answer: 'no'
返回值
常见返回值记录在此处,以下是此模块独有的字段
| 键 | 描述 | 
|---|---|
| 失败的条件列表。 返回: 失败 示例:  | |
| 命令的响应集。 返回: 除底层错误(例如操作插件)外,始终返回 示例:  | |
| stdout 的值拆分为列表。 返回: 除底层错误(例如操作插件)外,始终返回 示例:  | |
| 模块根据参数生成的警告列表(如果有)。 返回: 始终 示例:  | 
