Debian Codegraph @

lib/ansible/modules/assert.py

raw
1 # -*- coding: utf-8 -*-
2
3 # Copyright: (c) 2012, Dag Wieers <[email protected]>
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 from __future__ import annotations
7
8
9 DOCUMENTATION = r"""
10 ---
11 module: assert
12 short_description: Asserts given expressions are true
13 description:
14 - This module asserts that given expressions are true with an optional custom message.
15 - This module is also supported for Windows targets.
16 version_added: "1.5"
17 options:
18 that:
19 description:
20 - A list of string expressions of the same form that can be passed to the C(when) statement.
21 type: list
22 elements: str
23 required: true
24 fail_msg:
25 description:
26 - The customized message used for a failing assertion.
27 - This argument was called O(msg) before Ansible 2.7, now it is renamed to O(fail_msg) with alias O(msg).
28 type: str
29 aliases: [ msg ]
30 version_added: "2.7"
31 success_msg:
32 description:
33 - The customized message used for a successful assertion.
34 type: str
35 version_added: "2.7"
36 quiet:
37 description:
38 - Set this to V(true) to avoid verbose output.
39 type: bool
40 default: no
41 version_added: "2.8"
42 extends_documentation_fragment:
43 - action_common_attributes
44 - action_common_attributes.conn
45 - action_common_attributes.flow
46 attributes:
47 action:
48 support: full
49 async:
50 support: none
51 become:
52 support: none
53 bypass_host_loop:
54 support: none
55 connection:
56 support: none
57 check_mode:
58 support: full
59 delegation:
60 support: none
61 details: Aside from C(register) and/or in combination with C(delegate_facts), it has little effect.
62 diff_mode:
63 support: none
64 platform:
65 platforms: all
66 seealso:
67 - module: ansible.builtin.debug
68 - module: ansible.builtin.fail
69 - module: ansible.builtin.meta
70 author:
71 - Ansible Core Team
72 - Michael DeHaan
73 """
74
75 EXAMPLES = r"""
76 - name: A single condition can be supplied as string instead of list
77 ansible.builtin.assert:
78 that: "ansible_os_family != 'RedHat'"
79
80 - name: Use yaml multiline strings to ease escaping
81 ansible.builtin.assert:
82 that:
83 - "'foo' in some_command_result.stdout"
84 - number_of_the_counting == 3
85 - >
86 "reject" not in some_command_result.stderr
87
88 - name: After version 2.7 both O(msg) and O(fail_msg) can customize failing assertion message
89 ansible.builtin.assert:
90 that:
91 - my_param <= 100
92 - my_param >= 0
93 fail_msg: "'my_param' must be between 0 and 100"
94 success_msg: "'my_param' is between 0 and 100"
95
96 - name: Please use O(msg) when ansible version is smaller than 2.7
97 ansible.builtin.assert:
98 that:
99 - my_param <= 100
100 - my_param >= 0
101 msg: "'my_param' must be between 0 and 100"
102
103 - name: Use quiet to avoid verbose output
104 ansible.builtin.assert:
105 that:
106 - my_param <= 100
107 - my_param >= 0
108 quiet: true
109 """