Debian Codegraph @

lib/ansible/modules/ping.py

raw
1 # -*- coding: utf-8 -*-
2
3 # (c) 2012, Michael DeHaan <[email protected]>
4 # (c) 2016, Toshio Kuratomi <[email protected]>
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 from __future__ import annotations
8
9
10 DOCUMENTATION = """
11 ---
12 module: ping
13 version_added: historical
14 short_description: Try to connect to host, verify a usable python and return V(pong) on success
15 description:
16 - A trivial test module, this module always returns V(pong) on successful
17 contact. It does not make sense in playbooks, but it is useful from
18 C(/usr/bin/ansible) to verify the ability to login and that a usable Python is configured.
19 - This is NOT ICMP ping, this is just a trivial test module that requires Python on the remote-node.
20 - For Windows targets, use the M(ansible.windows.win_ping) module instead.
21 - For Network targets, use the M(ansible.netcommon.net_ping) module instead.
22 options:
23 data:
24 description:
25 - Data to return for the RV(ping) return value.
26 - If this parameter is set to V(crash), the module will cause an exception.
27 type: str
28 default: pong
29 extends_documentation_fragment:
30 - action_common_attributes
31 attributes:
32 check_mode:
33 support: full
34 diff_mode:
35 support: none
36 platform:
37 platforms: posix
38 seealso:
39 - module: ansible.netcommon.net_ping
40 - module: ansible.windows.win_ping
41 author:
42 - Ansible Core Team
43 - Michael DeHaan
44 """
45
46 EXAMPLES = """
47 # Test we can logon to 'webservers' and execute python with json lib.
48 # ansible webservers -m ansible.builtin.ping
49
50 - name: Example from an Ansible Playbook
51 ansible.builtin.ping:
52
53 - name: Induce an exception to see what happens
54 ansible.builtin.ping:
55 data: crash
56 """
57
58 RETURN = """
59 ping:
60 description: Value provided with the O(data) parameter.
61 returned: success
62 type: str
63 sample: pong
64 """
65
66 from ansible.module_utils.basic import AnsibleModule
67
68
69 def main():
70 module = AnsibleModule(
71 argument_spec=dict(
72 data=dict(type='str', default='pong'),
73 ),
74 supports_check_mode=True
75 )
76
77 if module.params['data'] == 'crash':
78 raise Exception("boom")
79
80 result = dict(
81 ping=module.params['data'],
82 )
83
84 module.exit_json(**result)
85
86
87 if __name__ == '__main__':
88 main()