Ansible Module ansible.builtin.assert: Difference between revisions
Jump to navigation
Jump to search
(Created page with "=Internal= * Ansible Concepts =Overview=") |
|||
(8 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
=External= | |||
* https://docs.ansible.com/ansible/latest/collections/ansible/builtin/assert_module.html#ansible-collections-ansible-builtin-assert-module | |||
=Internal= | =Internal= | ||
* [[Ansible Concepts#ansible.builtin.assert|Ansible Concepts]] | * [[Ansible Concepts#ansible.builtin.assert|Ansible Concepts]] | ||
=Overview= | =Overview= | ||
This module asserts that given expressions are true with an optional custom message. | |||
<syntaxhighlight lang='yaml'> | |||
- name: ... | |||
assert: | |||
that: | |||
fail_msg: | |||
success_msg: | |||
</syntaxhighlight> | |||
=Module Parameters= | |||
===<tt>that</tt>=== | |||
A list of string expressions of the same form that can be passed to the <code>[[Ansible_Concepts#when_-_Conditional_Task_Execution|when]]</code> statement. | |||
=Use Cases= | |||
====Ensure that a Directory Exists==== | |||
<syntaxhighlight lang='yaml'> | |||
- name: Gather stats on the given path | |||
stat: | |||
path: "{{ some_path }}" | |||
register: some_path_info | |||
- name: Ensure that some directory exist | |||
assert: | |||
that: "{{ some_path_info.stat.exists }}" | |||
fail_msg: "{{ some_path_info.stat.path }} does not exit" | |||
</syntaxhighlight> | |||
More details on the <code>stat</code> module available here: {{Internal|Ansible Module stat#Overview|stat}} |
Latest revision as of 06:21, 5 July 2021
External
Internal
Overview
This module asserts that given expressions are true with an optional custom message.
- name: ...
assert:
that:
fail_msg:
success_msg:
Module Parameters
that
A list of string expressions of the same form that can be passed to the when
statement.
Use Cases
Ensure that a Directory Exists
- name: Gather stats on the given path
stat:
path: "{{ some_path }}"
register: some_path_info
- name: Ensure that some directory exist
assert:
that: "{{ some_path_info.stat.exists }}"
fail_msg: "{{ some_path_info.stat.path }} does not exit"
More details on the stat
module available here: