kubekey/docs/zh/modules/assert.md
liujian e3f2372ee0
feat: docs for modules (#2623)
Signed-off-by: joyceliu <joyceliu@yunify.com>
2025-06-17 09:40:31 +00:00

59 lines
1.2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# assert 模块
assert模块允许用户对参数条件进行断言。
## 参数
| 参数 | 说明 | 类型 | 必填 | 默认值 |
|------|------|------|------|-------|
| that | 断言的条件.需采用[模板语法](../101-syntax.md)编写 | 数组或字符串 | 是 | - |
| success_msg | 断言结果为true时输出到任务结果的 stdout 信息 | 字符串 | 否 | True |
| fail_msg | 断言结果为false时输出到任务结果的 stderr 信息 | 字符串 | 否 | False |
| msg | 通fail_msg. 优先级低于fail_msg | 字符串 | 否 | False |
## 使用示例
1. 断言条件为字符串
```yaml
- name: assert single condition
assert:
that: eq 1 1
```
任务执行结果:
stdout: "True"
stderr: ""
2. 断言条件为数组
```yaml
- name: assert multi-condition
assert:
that:
- eq 1 1
- eq 1 2
```
任务执行结果:
stdout: "False"
stderr: "False"
3. 设置成功输出
```yaml
- name: assert is succeed
assert:
that: eq 1 1
success_msg: "It's succeed"
```
任务执行结果:
stdout: "It's succeed"
stderr: ""
1. 设置失败输出
```yaml
- name: assert is failed
assert:
that: eq 1 2
fail_msg: "It's failed"
msg: "It's failed!"
```
任务执行结果:
stdout: "False"
stderr: "It's failed"