assert – Asserts given expressions are true

From Get docs
Ansible/docs/2.7/modules/assert module


assert – Asserts given expressions are true

New 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 Choices/Defaults Comments

fail_msg

-

added in 2.7

The customized message used for a failing assertion

This argument was called 'msg' before version 2.7, now it's renamed to 'fail_msg' with alias 'msg'


aliases: msg

success_msg

-

added in 2.7

The customized message used for a successful assertion

that

- / required

A string expression of the same form that can be passed to the 'when' statement

Alternatively, a list of string expressions



Notes

Note

  • This module is also supported for Windows targets.


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"

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.


© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.7/modules/assert_module.html