端くれプログラマの備忘録 Ansible [Ansible] assertモジュール

[Ansible] assertモジュール

機能

与えられた式が真であることを、オプションのカスタムメッセージで表示する。thatパラメータにwhenステートメントに渡すのと同様の文字列リストを指定する。

使用例

- ansible.builtin.assert: { that: "ansible_os_family != 'RedHat'" }

- ansible.builtin.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
  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"

- 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"

- name: Use quiet to avoid verbose output
  ansible.builtin.assert:
    that:
      - my_param <= 100
      - my_param >= 0
    quiet: true

参考サイト

ansible.builtin.assert module – Asserts given expressions are true — Ansible Documentation
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/assert_module.html