Debian Codegraph @

lib/ansible/modules/debug.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: debug
12 short_description: Print statements during execution
13 description:
14 - This module prints statements during execution and can be useful
15 for debugging variables or expressions without necessarily halting
16 the playbook.
17 - Useful for debugging together with the C(when:) directive.
18 - This module is also supported for Windows targets.
19 version_added: '0.8'
20 options:
21 msg:
22 description:
23 - The customized message that is printed. If omitted, prints a generic message.
24 type: str
25 default: 'Hello world!'
26 var:
27 description:
28 - A variable name to debug.
29 - Mutually exclusive with the O(msg) option.
30 - Be aware that this option already runs in Jinja2 context and has an implicit C({{ }}) wrapping,
31 so you should not be using Jinja2 delimiters unless you are looking for double interpolation.
32 type: str
33 verbosity:
34 description:
35 - A number that controls when the debug is run, if you set to 3 it will only run debug when -vvv or above.
36 type: int
37 default: 0
38 version_added: '2.1'
39 extends_documentation_fragment:
40 - action_common_attributes
41 - action_common_attributes.conn
42 - action_common_attributes.flow
43
44 attributes:
45 action:
46 support: full
47 async:
48 support: none
49 bypass_host_loop:
50 support: none
51 become:
52 support: none
53 check_mode:
54 support: full
55 diff_mode:
56 support: none
57 connection:
58 support: none
59 delegation:
60 details: Aside from C(register) and/or in combination with C(delegate_facts), it has little effect.
61 support: partial
62 platform:
63 support: full
64 platforms: all
65 seealso:
66 - module: ansible.builtin.assert
67 - module: ansible.builtin.fail
68 author:
69 - Dag Wieers (@dagwieers)
70 - Michael DeHaan
71 """
72
73 EXAMPLES = r"""
74 - name: Print the gateway for each host when defined
75 ansible.builtin.debug:
76 msg: System {{ inventory_hostname }} has gateway {{ ansible_default_ipv4.gateway }}
77 when: ansible_default_ipv4.gateway is defined
78
79 - name: Get uptime information
80 ansible.builtin.shell: /usr/bin/uptime
81 register: result
82
83 - name: Print return information from the previous task
84 ansible.builtin.debug:
85 var: result
86 verbosity: 2
87
88 - name: Display all variables/facts known for a host
89 ansible.builtin.debug:
90 var: hostvars[inventory_hostname]
91 verbosity: 4
92
93 - name: Prints two lines of messages, but only if there is an environment value set
94 ansible.builtin.debug:
95 msg:
96 - "Provisioning based on YOUR_KEY which is: {{ lookup('ansible.builtin.env', 'YOUR_KEY') }}"
97 - "These servers were built using the password of '{{ password_used }}'. Please retain this for later use."
98 """