W3cubDocs

/Ansible 2.7

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

This module is flagged as stableinterface which means that the maintainers for this module guarantee that no backward incompatible interface changes will be made.

Maintenance

This module is flagged as core which means that it is maintained by the Ansible Core Team. See Module Maintenance & Support for more info.

For a list of other modules that are also maintained by the Ansible Core Team, see here.

Support

For more information about Red Hat’s support of this module, please refer to this Knowledge Base article

Author

  • 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 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.7/modules/assert_module.html