Documentation
  • Docs »
  • assert – Asserts given expressions are true

assert – Asserts given expressions are true

Synopsis

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

Parameters

Parameter Choices/Defaults Comments
fail_msg
string
added in 2.7
The customized message used for a failing assertion.
This argument was called 'msg' before Ansible 2.7, now it is renamed to 'fail_msg' with alias 'msg'.

aliases: msg
quiet
boolean
added in 2.8
    Choices:
  • no ←
  • yes
Set this to yes to avoid verbose output.
success_msg
string
added in 2.7
The customized message used for a successful assertion.
that
list / required
A list of string expressions of the same form that can be passed to the 'when' statement.

Notes

Note

  • This module is also supported for Windows targets.

See Also

See also

debug – Print statements during execution
The official documentation on the debug module.
fail – Fail with custom message
The official documentation on the fail module.
meta – Execute Ansible ‘actions’
The official documentation on the meta module.

Examples

- assert: { that: "ansible_os_family != 'RedHat'" }

- 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
  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
  assert:
    that:
      - my_param <= 100
      - my_param >= 0
    msg: "'my_param' must be between 0 and 100"

- name: use quiet to avoid verbose output
  assert:
    that:
      - my_param <= 100
      - my_param >= 0
    quiet: true

Status

Red Hat Support

More information about Red Hat’s support of this module is available from this Red Hat Knowledge Base article.

Authors

  • Ansible Core Team
  • Michael DeHaan

Hint

If you notice any issues in this documentation you can edit this document to improve it.