knowledge/technology/tools/Ansible/modules/ansible.builtin.assert.md

42 lines
1.8 KiB
Markdown
Raw Permalink Normal View History

2023-12-04 10:02:23 +00:00
# ansible.builtin.assert
This module asserts that given expressions are true with an optional custom message
## Parameters
| Parameter | Type | Description |
| ----------- | --------------------------------- | ---------------------------------------------------------------------------------------- |
| **fail_msg** | string | The customized message used for a failing assertion |
2024-01-17 08:44:04 +00:00
| **quiet** | boolean | Set this to `true` to avoid verbose output |
2023-12-04 10:02:23 +00:00
| **success_msg** | string | The customized message used for a successful assertion |
2024-01-17 08:44:04 +00:00
| **that** | list / elements=string / required | A list of string expressions of the same form that can be passed to the when statement |
2023-12-04 10:02:23 +00:00
## Examples
```yaml
- ansible.builtin.assert: { that: "ansible_os_family != 'RedHat'" }
- ansible.builtin.assert:
that:
- "'foo' in some_command_result.stdout"
- number_of_the_counting == 3
- name: After version 2.7 both 'msg' and 'fail_msg' can customize failing assertion message
ansible.builtin.assert:
that:
- my_param <= 100
- my_param >= 0
fail_msg: "'my_param' must be between 0 and 100"
success_msg: "'my_param' is between 0 and 100"
- name: Please use 'msg' when ansible version is smaller than 2.7
ansible.builtin.assert:
that:
- my_param <= 100
- my_param >= 0
msg: "'my_param' must be between 0 and 100"
- name: Use quiet to avoid verbose output
ansible.builtin.assert:
that:
- my_param <= 100
- my_param >= 0
quiet: true
```