ansible.builtin.assert – Asserts given expressions are true

Note

This module is part of ansible-core and included in all Ansible installations. In most cases, you can use the short module name assert even without specifying the collections: keyword. However, 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

Comments

fail_msg

aliases: 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’.

quiet

boolean

added in 2.8 of ansible.builtin

Set this to yes to avoid verbose output.

Choices:

  • no ← (default)

  • yes

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