kubekey/docs/en/modules/assert.md
liujian 192af7bb7e
feat: add Chinese README and documentation updates (#2791)
- Introduced a new Chinese version of the README file (README_zh-CN.md) to enhance accessibility for Chinese-speaking users.
- Updated the English README to reflect new features and installation instructions.
- Added detailed documentation for project structure, playbooks, roles, tasks, and modules to improve user understanding and usability.

Signed-off-by: [Your Name] <[Your Email]>
Signed-off-by: redscholar <blacktiledhouse@gmail.com>
2025-09-30 10:00:07 +08:00

1.4 KiB

assert Module

The assert module allows users to perform assertions on parameter conditions.

Parameters

Parameter Description Type Required Default
that Assertion condition. Must use template syntax. Array or string Yes -
success_msg Message output to task result stdout when the assertion evaluates to true. String No True
fail_msg Message output to task result stderr when the assertion evaluates to false. String No False
msg Same as fail_msg. Lower priority than fail_msg. String No False

Usage Examples

  1. Assertion condition as a string
- name: assert single condition
  assert:
    that: eq 1 1

Task execution result:
stdout: "True"
stderr: ""

  1. Assertion condition as an array
- name: assert multi-condition
  assert:
    that: 
     - eq 1 1
     - eq 1 2

Task execution result:
stdout: "False"
stderr: "False"

  1. Set custom success output
- name: assert is succeed
  assert:
    that: eq 1 1
    success_msg: "It's succeed"

Task execution result:
stdout: "It's succeed"
stderr: ""

  1. Set custom failure output
- name: assert is failed
  assert:
    that: eq 1 2
    fail_msg: "It's failed"
    msg: "It's failed!"

Task execution result:
stdout: "False"
stderr: "It's failed"