ansible/system/ping.py

63 lines
1.9 KiB
Python
Raw Normal View History

2012-02-23 20:18:51 +01:00
#!/usr/bin/python
# -*- coding: utf-8 -*-
2012-02-23 20:18:51 +01:00
# (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
2016-05-11 06:57:05 +02:00
# (c) 2016, Toshio Kuratomi <tkuratomi@ansible.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
2012-09-29 16:21:00 +02:00
DOCUMENTATION = '''
---
module: ping
version_added: historical
short_description: Try to connect to host, verify a usable python and return C(pong) on success.
2012-09-29 16:21:00 +02:00
description:
2012-11-21 18:49:30 +01:00
- A trivial test module, this module always returns C(pong) on successful
contact. It does not make sense in playbooks, but it is useful from
2015-10-21 19:57:47 +02:00
C(/usr/bin/ansible) to verify the ability to login and that a usable python is configured.
- This is NOT ICMP ping, this is just a trivial test module.
options: {}
2015-10-21 19:57:47 +02:00
author:
- "Ansible Core Team"
- "Michael DeHaan"
2012-09-29 16:21:00 +02:00
'''
EXAMPLES = '''
2015-10-21 19:57:47 +02:00
# Test we can logon to 'webservers' and execute python with json lib.
ansible webservers -m ping
'''
2016-05-11 06:57:05 +02:00
from ansible.module_utils.basic import AnsibleModule
def main():
module = AnsibleModule(
2016-05-11 06:58:22 +02:00
argument_spec=dict(
2013-02-17 21:01:49 +01:00
data=dict(required=False, default=None),
),
2016-05-11 06:58:22 +02:00
supports_check_mode=True
)
2013-02-17 21:01:49 +01:00
result = dict(ping='pong')
if module.params['data']:
if module.params['data'] == 'crash':
2016-05-11 06:57:05 +02:00
raise Exception("boom")
2013-02-17 21:01:49 +01:00
result['ping'] = module.params['data']
module.exit_json(**result)
2016-05-11 06:57:05 +02:00
if __name__ == '__main__':
main()