community.network.ce_command 模块 – 在华为 CloudEngine 设备上运行任意命令。

注意

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

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

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

要在 playbook 中使用它,请指定:community.network.ce_command

注意

community.network 集合已被弃用,并将从 Ansible 12 中移除。有关更多信息,请参阅讨论主题

已弃用

中移除

版本 6.0.0

原因

此集合及其中的所有内容均未维护且已弃用。

替代方案

未知。

概要

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

别名:network.cloudengine.ce_command

参数

参数

注释

commands

字符串 / 必需

通过配置的提供程序发送到远程华为 CloudEngine 设备的命令。将返回命令的结果输出。如果提供了 wait_for 参数,则模块不会返回,直到满足条件或超过 retries 的次数。

interval

字符串

配置命令重试之间等待的间隔(以秒为单位)。如果命令未通过指定的条件,则间隔表示在再次尝试命令之前要等待多长时间。

默认值: 1

match

字符串

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

默认值: "all"

retries

字符串

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

默认值: 10

wait_for

字符串

指定从命令输出中评估什么以及应用什么条件。此参数将导致任务等待特定条件为真,然后再继续进行。如果配置的重试次数未能满足条件,则任务将失败。请参见示例。

备注

注意

  • 建议的连接是 network_cli

  • 此模块也适用于遗留 playbook 的 local 连接。

示例

# Note: examples below use the following provider dict to handle
#       transport and authentication to the node.

- name: CloudEngine command test
  hosts: cloudengine
  connection: local
  gather_facts: false
  vars:
    cli:
      host: "{{ inventory_hostname }}"
      port: "{{ ansible_ssh_port }}"
      username: "{{ username }}"
      password: "{{ password }}"
      transport: cli

  tasks:
  - name: "Run display version on remote devices"
    community.network.ce_command:
      commands: display version
      provider: "{{ cli }}"

  - name: "Run display version and check to see if output contains HUAWEI"
    community.network.ce_command:
      commands: display version
      wait_for: result[0] contains HUAWEI
      provider: "{{ cli }}"

  - name: "Run multiple commands on remote nodes"
    community.network.ce_command:
      commands:
        - display version
        - display device
      provider: "{{ cli }}"

  - name: "Run multiple commands and evaluate the output"
    community.network.ce_command:
      commands:
        - display version
        - display device
      wait_for:
        - result[0] contains HUAWEI
        - result[1] contains Device
      provider: "{{ cli }}"

返回值

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

描述

failed_conditions

列表 / 元素=字符串

失败的条件

已返回:失败

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

stdout

列表 / 元素=字符串

来自命令的响应集

已返回:始终

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

stdout_lines

列表 / 元素=字符串

stdout 的值拆分为列表

已返回:始终

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

状态

  • 此模块将在 6.0.0 版本中删除。 [已弃用]

  • 有关更多信息,请参见已弃用

作者

  • JackyGao2016 (@CloudEngine-Ansible)