Debian Codegraph @

test/integration/targets/ansible-galaxy-collection/files/test_module.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 C(pong) on success
15 description:
16 - A trivial test module, this module always returns C(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 C(ping) return value.
26 - If this parameter is set to C(crash), the module will cause an exception.
27 type: str
28 default: pong
29 seealso:
30 - module: ansible.netcommon.net_ping
31 - module: ansible.windows.win_ping
32 author:
33 - Ansible Core Team
34 - Michael DeHaan
35 """
36
37 EXAMPLES = """
38 # Test we can logon to 'webservers' and execute python with json lib.
39 # ansible webservers -m ping
40
41 - name: Example from an Ansible Playbook
42 ping:
43
44 - name: Induce an exception to see what happens
45 ping:
46 data: crash
47 """
48
49 RETURN = """
50 ping:
51 description: value provided with the data parameter
52 returned: success
53 type: str
54 sample: pong
55 """
56
57 from ansible.module_utils.basic import AnsibleModule
58
59
60 def main():
61 module = AnsibleModule(
62 argument_spec=dict(
63 data=dict(type='str', default='pong'),
64 ),
65 supports_check_mode=True
66 )
67
68 if module.params['data'] == 'crash':
69 raise Exception("boom")
70
71 result = dict(
72 ping=module.params['data'],
73 )
74
75 module.exit_json(**result)
76
77
78 if __name__ == '__main__':
79 main()