ansible.builtin.assert (v2.16.5) — module

Asserts given expressions are true

| "added in version" 1.5 of ansible.builtin"

Authors: Ansible Core Team, Michael DeHaan

This plugin has a corresponding action plugin.

Install Ansible via pip

Install with pip install ansible-core==2.16.5

Description

This module asserts that given expressions are true with an optional custom message.

This module is also supported for Windows targets.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- ansible.builtin.assert: { that: "ansible_os_family != 'RedHat'" }
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- ansible.builtin.assert:
    that:
      - "'foo' in some_command_result.stdout"
      - number_of_the_counting == 3
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: After version 2.7 both 'msg' and 'fail_msg' can customize failing assertion message
  ansible.builtin.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"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Please use 'msg' when ansible version is smaller than 2.7
  ansible.builtin.assert:
    that:
      - my_param <= 100
      - my_param >= 0
    msg: "'my_param' must be between 0 and 100"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Use quiet to avoid verbose output
  ansible.builtin.assert:
    that:
      - my_param <= 100
      - my_param >= 0
    quiet: true

Inputs

    
that:
    description:
    - A list of string expressions of the same form that can be passed to the 'when' statement.
    elements: str
    required: true
    type: list

quiet:
    default: false
    description:
    - Set this to V(true) to avoid verbose output.
    type: bool
    version_added: '2.8'
    version_added_collection: ansible.builtin

fail_msg:
    aliases:
    - msg
    description:
    - 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'.
    type: str
    version_added: '2.7'
    version_added_collection: ansible.builtin

success_msg:
    description:
    - The customized message used for a successful assertion.
    type: str
    version_added: '2.7'
    version_added_collection: ansible.builtin

See also