community.ciscosmb.command 模块 – 在远程 Cisco SMB 设备上运行命令

注意

此模块是 community.ciscosmb 集合(版本 1.0.9)的一部分。

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

要安装它,请使用: ansible-galaxy collection install community.ciscosmb

要在 playbook 中使用它,请指定: community.ciscosmb.command

概要

  • 将任意命令发送到 Cisco SMB 节点并返回从设备读取的结果。此模块包含一个参数,该参数将导致模块在返回之前等待特定条件,或者如果未满足条件则超时。

参数

参数

注释

commands

列表 / 元素=字符串 / 必需

要通过配置的提供程序发送到远程 Cisco SMB 设备的命令列表。返回命令的输出结果。如果提供了 *wait_for* 参数,则在满足条件或重试次数过期之前,模块不会返回。

interval

整数

配置命令重试之间等待的秒数间隔。如果命令未通过指定的条件,则间隔指示在再次尝试命令之前要等待的时间。

默认值: 1

match

字符串

*match* 参数与 *wait_for* 参数一起使用以指定匹配策略。有效值为 allany。如果值为 all,则必须满足 wait_for 中的所有条件。如果值为 any,则只需要满足其中一个值。

选项

  • "any"

  • "all" ← (默认)

retries

整数

指定在命令被认为失败之前应尝试的重试次数。命令在每次重试时都在目标设备上运行,并根据 *wait_for* 条件进行评估。

默认值: 10

wait_for

列表 / 元素=字符串

要根据命令输出评估的条件列表。任务将等待每个条件为真才能继续执行。如果在配置的重试次数内条件不为真,则任务失败。参见示例。

示例

- name: Run command on remote devices
  community.ciscosmb.command:
    commands: show version

- name: Run command and check to see if output contains PID
  community.ciscosmb.command:
    commands: show inventory
    wait_for: result[0] contains PID

- name: Run multiple commands on remote nodes
  community.ciscosmb.command:
    commands:
      - show version
      - show system

- name: Run multiple commands and evaluate the output
  community.ciscosmb.command:
    commands:
      - show version
      - show system
    wait_for:
      - result[0] contains Active-image
      - result[1] contains "System Up Time"

返回值

常见的返回值在 此处 有文档记录,以下是此模块特有的字段

描述

failed_conditions

列表 / 元素=字符串

已失败的条件列表。

返回:失败

示例: ["...", "..."]

stdout

列表 / 元素=字符串

命令的响应集。

返回:始终返回,除了低级别错误(例如动作插件)

示例: ["...", "..."]

stdout_lines

列表 / 元素=字符串

stdout 的值拆分为列表。

返回:始终返回,除了低级别错误(例如动作插件)

示例: [["...", "..."], ["..."], ["..."]]

作者

  • Petr Klima (@qaxi)