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
参数
| 参数 | 注释 | 
|---|---|
| 通过配置的提供程序发送到远程华为 CloudEngine 设备的命令。 返回命令的结果输出。如果提供了 wait_for 参数,则在满足条件或超出 retries 次数之前,不会返回模块。 | |
| 配置命令重试之间等待的秒数间隔。如果命令未通过指定的条件,则间隔表示在再次尝试命令之前要等待多长时间。 默认值:  | |
| match 参数与 wait_for 参数结合使用,以指定匹配策略。有效值为  默认值:  | |
| 指定在被认为失败之前应尝试的命令的重试次数。 命令在每次重试时在目标设备上运行,并根据 wait_for 条件进行评估。 默认值:  | |
| 指定从命令输出中评估的内容以及要应用的条件。此参数将导致任务等待特定的条件为真,然后才继续。 如果在配置的重试次数之前条件不为真,则任务将失败。请参见示例。 | 
备注
注意
- 建议的连接是 - network_cli。
- 此模块也适用于 - local连接以用于旧版 playbook。
示例
# 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 }}"
返回值
常见返回值在此处记录 此处,以下是此模块独有的字段
| 键 | 描述 | 
|---|---|
| 失败的条件 已返回: 失败 示例:  | |
| 来自命令的响应集合 返回: 总是 示例:  | |
| 将 stdout 的值拆分为列表 返回: 总是 示例:  | 
状态
- 此模块将在 6.0.0 版本中移除。 [已弃用] 
- 更多信息请查看 已弃用。 
