Skip to content

Instantly share code, notes, and snippets.

@mwpeterson
Created April 25, 2018 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwpeterson/a7d6c6fc6d6a9fb2906d9c28f44682a9 to your computer and use it in GitHub Desktop.
Save mwpeterson/a7d6c6fc6d6a9fb2906d9c28f44682a9 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
import json
import traceback
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
from ansible.module_utils.urls import fetch_url
def get_url(module, msg):
if module.check_mode:
# In check mode, exit before actually sending the message
module.exit_json(changed=False)
url = "https://google.com/search?q=%s" % msg
response, info = fetch_url(module, url)
if info['status'] == 200:
return response.read()
else:
module.fail_json(msg="failed to send message, return status=%s" % str(info['status']))
def main():
module = AnsibleModule(
argument_spec=dict(
msg=dict(required=True),
),
supports_check_mode=True
)
msg = module.params["msg"]
try:
get_url(module, msg)
except Exception as e:
module.fail_json(msg="unable to send msg: %s" % to_native(e), exception=traceback.format_exc())
changed = True
module.exit_json(changed=changed, msg=msg)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment