W3cubDocs

/Ansible 2.11

ansible.builtin.assert – Asserts given expressions are true

Note

This module is part of ansible-base and included in all Ansible installations. In most cases, you can use the short module name assert even without specifying the collections: keyword. Despite that, we recommend you use the FQCN for easy linking to the module documentation and to avoid conflicting with other collections that may have the same module name.

New in version 1.5: of ansible.builtin

Synopsis

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

Note

This module has a corresponding action plugin.

Parameters

Parameter Choices/Defaults Comments
fail_msg
string
added in 2.7 of ansible.builtin
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 of ansible.builtin
    Choices:
  • no
  • yes
Set this to yes to avoid verbose output.
success_msg
string
added in 2.7 of ansible.builtin
The customized message used for a successful assertion.
that
list / elements=string / 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

ansible.builtin.debug

The official documentation on the ansible.builtin.debug module.

ansible.builtin.fail

The official documentation on the ansible.builtin.fail module.

ansible.builtin.meta

The official documentation on the ansible.builtin.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

Authors

  • Ansible Core Team
  • Michael DeHaan

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