Skip to content

assert

Collection Note

This module is part of the ansible.builtin collection. To install the collection, use:

ansible-galaxy collection install ansible.builtin
Added in version 1.5.

Synopsis

  • This module asserts that given expressions are true with an optional custom message.
  • This module is also supported for Windows targets.

Parameters

Parameter Defaults / Choices Comments
fail_msg
str
The customized message used for a failing assertion.
This argument was called O(msg) before Ansible 2.7, now it is renamed to O(fail_msg) with alias O(msg).
Version Added: 2.7
quiet
bool
Set this to V(true) to avoid verbose output.
Version Added: 2.8
success_msg
str
The customized message used for a successful assertion.
Version Added: 2.7
that
list / elements=str
required
A list of string expressions of the same form that can be passed to the C(when) statement.

Examples

- name: A single condition can be supplied as string instead of list
  ansible.builtin.assert:
    that: "ansible_os_family != 'RedHat'"

- name: Use yaml multiline strings to ease escaping
  ansible.builtin.assert:
    that:
      - "'foo' in some_command_result.stdout"
      - number_of_the_counting == 3
      - >
        "reject" not in some_command_result.stderr

- name: After version 2.7 both O(msg) and O(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 O(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

Authors

  • Ansible Core Team
  • Michael Dehaan