Debian Codegraph @

test/integration/targets/module_defaults/library/legacy_ping.py

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