1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fix wildcard imports, remove get_exception, add boilerplate

Fixed for monitoring modules
This commit is contained in:
Toshio Kuratomi 2017-08-12 01:37:41 -07:00
parent aca1950150
commit 7cd81b802d
37 changed files with 288 additions and 618 deletions

View file

@ -2,21 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2013 Bruce Pennypacker <bruce@pennypacker.org> # Copyright 2013 Bruce Pennypacker <bruce@pennypacker.org>
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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/>.
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -77,8 +67,11 @@ EXAMPLES = '''
revision: '4.2' revision: '4.2'
''' '''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import fetch_url
from ansible.module_utils.six.moves.urllib.parse import urlencode from ansible.module_utils.six.moves.urllib.parse import urlencode
# =========================================== # ===========================================
# Module execution. # Module execution.
# #
@ -129,9 +122,6 @@ def main():
else: else:
module.fail_json(msg="HTTP result code: %d connecting to %s" % (info['status'], url)) module.fail_json(msg="HTTP result code: %d connecting to %s" % (info['status'], url))
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.urls import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,20 +1,11 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- 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
# 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/>.
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -117,7 +108,14 @@ EXAMPLES = '''
# =========================================== # ===========================================
# Module execution. # Module execution.
# #
import json
import socket import socket
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 main(): def main():
@ -194,13 +192,9 @@ def main():
module.exit_json(changed=True, **deployment) module.exit_json(changed=True, **deployment)
else: else:
module.fail_json(msg=json.dumps(info)) module.fail_json(msg=json.dumps(info))
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e))
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.urls import *
from ansible.module_utils.pycompat24 import get_exception
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,26 +1,11 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2013, curtis <curtis@serverascode.com>
# 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
Ansible module to add boundary meters. __metaclass__ = type
(c) 2013, curtis <curtis@serverascode.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/>.
"""
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -162,7 +147,7 @@ def create_meter(module, name, apiid, apikey):
for cert_type in types: for cert_type in types:
try: try:
# If we can't open the file it's not there, so we should download it # If we can't open the file it's not there, so we should download it
cert_file = open('%s/%s.pem' % (config_directory,cert_type)) dummy = open('%s/%s.pem' % (config_directory,cert_type))
except IOError: except IOError:
# Now download the file... # Now download the file...
rc = download_request(module, name, apiid, apikey, cert_type) rc = download_request(module, name, apiid, apikey, cert_type)

View file

@ -2,21 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# (c) 2014-2015, Epic Games, Inc. # (c) 2014-2015, Epic Games, Inc.
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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/>.
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -90,11 +80,12 @@ EXAMPLES = '''
''' '''
import json import json
import time import time
import traceback
import requests import requests
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception from ansible.module_utils._text import to_native
def post_annotation(annotation, api_key): def post_annotation(annotation, api_key):
@ -154,9 +145,8 @@ def main():
annotation = create_annotation(module) annotation = create_annotation(module)
try: try:
resp = post_annotation(annotation, module.params['api_key']) resp = post_annotation(annotation, module.params['api_key'])
except requests.exceptions.RequestException: except requests.exceptions.RequestException as e:
err_str = get_exception() module.fail_json(msg='Request Failed', reason=to_native(e), exception=traceback.format_exc())
module.fail_json(msg='Request Failed', reason=err_str)
module.exit_json(changed=True, annotation=resp.json()) module.exit_json(changed=True, annotation=resp.json())

View file

@ -6,21 +6,11 @@
# #
# This module is proudly sponsored by iGeolise (www.igeolise.com) and # This module is proudly sponsored by iGeolise (www.igeolise.com) and
# Tiny Lab Productions (www.tinylabproductions.com). # Tiny Lab Productions (www.tinylabproductions.com).
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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/>.
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -113,6 +103,9 @@ EXAMPLES = '''
tags: 'aa,bb,#host:{{ inventory_hostname }}' tags: 'aa,bb,#host:{{ inventory_hostname }}'
''' '''
import platform
import traceback
# Import Datadog # Import Datadog
try: try:
from datadog import initialize, api from datadog import initialize, api
@ -121,7 +114,7 @@ except:
HAS_DATADOG = False HAS_DATADOG = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception from ansible.module_utils._text import to_native
def main(): def main():
@ -176,12 +169,9 @@ def _post_event(module):
module.fail_json(msg=msg) module.fail_json(msg=msg)
module.exit_json(changed=True, msg=msg) module.exit_json(changed=True, msg=msg)
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e))
from ansible.module_utils.basic import *
from ansible.module_utils.urls import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2015, Sebastian Kornehl <sebastian.kornehl@asideas.de> # (c) 2015, Sebastian Kornehl <sebastian.kornehl@asideas.de>
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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/>.
# import module snippets
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -168,6 +157,7 @@ datadog_monitor:
api_key: "9775a026f1ca7d1c6c5af9d94d9595a4" api_key: "9775a026f1ca7d1c6c5af9d94d9595a4"
app_key: "87ce4a24b5553d2e482ea8a8500e71b8ad4554ff" app_key: "87ce4a24b5553d2e482ea8a8500e71b8ad4554ff"
''' '''
import traceback
# Import Datadog # Import Datadog
try: try:
@ -177,7 +167,7 @@ except:
HAS_DATADOG = False HAS_DATADOG = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception from ansible.module_utils._text import to_native
def main(): def main():
@ -267,9 +257,8 @@ def _post_monitor(module, options):
module.fail_json(msg=str(msg['errors'])) module.fail_json(msg=str(msg['errors']))
else: else:
module.exit_json(changed=True, msg=msg) module.exit_json(changed=True, msg=msg)
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e))
def _equal_dicts(a, b, ignore_keys): def _equal_dicts(a, b, ignore_keys):
@ -293,9 +282,8 @@ def _update_monitor(module, monitor, options):
module.exit_json(changed=False, msg=msg) module.exit_json(changed=False, msg=msg)
else: else:
module.exit_json(changed=True, msg=msg) module.exit_json(changed=True, msg=msg)
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e))
def install_monitor(module): def install_monitor(module):
@ -331,9 +319,8 @@ def delete_monitor(module):
try: try:
msg = api.Monitor.delete(monitor['id']) msg = api.Monitor.delete(monitor['id'])
module.exit_json(changed=True, msg=msg) module.exit_json(changed=True, msg=msg)
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e))
def mute_monitor(module): def mute_monitor(module):
@ -350,9 +337,8 @@ def mute_monitor(module):
else: else:
msg = api.Monitor.mute(id=monitor['id'], silenced=module.params['silenced']) msg = api.Monitor.mute(id=monitor['id'], silenced=module.params['silenced'])
module.exit_json(changed=True, msg=msg) module.exit_json(changed=True, msg=msg)
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e))
def unmute_monitor(module): def unmute_monitor(module):
@ -364,9 +350,8 @@ def unmute_monitor(module):
try: try:
msg = api.Monitor.unmute(monitor['id']) msg = api.Monitor.unmute(monitor['id'])
module.exit_json(changed=True, msg=msg) module.exit_json(changed=True, msg=msg)
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e))
if __name__ == '__main__': if __name__ == '__main__':

View file

@ -2,21 +2,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2014 Benjamin Curtis <benjamin.curtis@gmail.com> # Copyright 2014 Benjamin Curtis <benjamin.curtis@gmail.com>
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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/>.
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -82,11 +71,13 @@ EXAMPLES = '''
RETURN = '''# ''' RETURN = '''# '''
# import module snippets import traceback
from ansible.module_utils.basic import *
from ansible.module_utils.pycompat24 import get_exception from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six.moves.urllib.parse import urlencode from ansible.module_utils.six.moves.urllib.parse import urlencode
from ansible.module_utils.urls import * from ansible.module_utils._text import to_native
from ansible.module_utils.urls import fetch_url
# =========================================== # ===========================================
# Module execution. # Module execution.
@ -132,14 +123,14 @@ def main():
try: try:
data = urlencode(params) data = urlencode(params)
response, info = fetch_url(module, url, data=data) response, info = fetch_url(module, url, data=data)
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg='Unable to notify Honeybadger: %s' % to_native(e), exception=traceback.format_exc())
module.fail_json(msg='Unable to notify Honeybadger: %s' % e)
else: else:
if info['status'] == 201: if info['status'] == 201:
module.exit_json(changed=True) module.exit_json(changed=True)
else: else:
module.fail_json(msg="HTTP result code: %d connecting to %s" % (info['status'], url)) module.fail_json(msg="HTTP result code: %d connecting to %s" % (info['status'], url))
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,28 +1,14 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" # (c) 2016, Loic Blot <loic.blot@unix-experience.fr>
# Sponsored by Infopro Digital. http://www.infopro-digital.com/
# Sponsored by E.T.A.I. http://www.etai.fr/
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
Ansible module to manage Icinga2 feature state from __future__ import absolute_import, division, print_function
(c) 2016, Loic Blot <loic.blot@unix-experience.fr> __metaclass__ = type
Sponsored by Infopro Digital. http://www.infopro-digital.com/
Sponsored by E.T.A.I. http://www.etai.fr/
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/>.
"""
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -62,9 +48,10 @@ RETURN = '''
# #
''' '''
from ansible.module_utils.basic import AnsibleModule
import re import re
from ansible.module_utils.basic import AnsibleModule
class Icinga2FeatureHelper: class Icinga2FeatureHelper:
def __init__(self, module): def __init__(self, module):

View file

@ -2,22 +2,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# (C) Seth Edwards, 2014 # (C) Seth Edwards, 2014
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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/>.
#
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',

View file

@ -2,19 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2013, Ivan Vanderbyl <ivan@app.io> # (c) 2013, Ivan Vanderbyl <ivan@app.io>
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This module is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (at your option) any later version.
#
# This software 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 this software. If not, see <http://www.gnu.org/licenses/>.
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -65,6 +57,9 @@ EXAMPLES = '''
state: absent state: absent
''' '''
from ansible.module_utils.basic import AnsibleModule
def query_log_status(module, le_path, path, state="present"): def query_log_status(module, le_path, path, state="present"):
""" Returns whether a log is followed or not. """ """ Returns whether a log is followed or not. """
@ -75,6 +70,7 @@ def query_log_status(module, le_path, path, state="present"):
return False return False
def follow_log(module, le_path, logs, name=None, logtype=None): def follow_log(module, le_path, logs, name=None, logtype=None):
""" Follows one or more logs if not already followed. """ """ Follows one or more logs if not already followed. """
@ -154,8 +150,6 @@ def main():
elif p["state"] in ["absent", "unfollowed"]: elif p["state"] in ["absent", "unfollowed"]:
unfollow_log(module, le_path, logs) unfollow_log(module, le_path, logs)
# import module snippets
from ansible.module_utils.basic import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -2,20 +2,11 @@
# LogicMonitor Ansible module for managing Collectors, Hosts and Hostgroups # LogicMonitor Ansible module for managing Collectors, Hosts and Hostgroups
# Copyright (C) 2015 LogicMonitor # Copyright (C) 2015 LogicMonitor
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation; either version 3 of the License, or __metaclass__ = type
# (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
RETURN = ''' RETURN = '''
--- ---

View file

@ -1,21 +1,11 @@
#!/usr/bin/python #!/usr/bin/python
# LogicMonitor Ansible module for managing Collectors, Hosts and Hostgroups
# Copyright (C) 2015 LogicMonitor # Copyright (C) 2015 LogicMonitor
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation; either version 3 of the License, or __metaclass__ = type
# (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -136,8 +126,6 @@ RETURN = '''
import socket import socket
import types import types
from ansible.module_utils.six.moves.urllib.parse import urlencode
HAS_LIB_JSON = True HAS_LIB_JSON = True
try: try:
import json import json
@ -159,6 +147,11 @@ except ImportError:
except SyntaxError: except SyntaxError:
HAS_LIB_JSON = False HAS_LIB_JSON = False
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six.moves.urllib.parse import urlencode
from ansible.module_utils._text import to_native
from ansible.module_utils.urls import open_url
class LogicMonitor(object): class LogicMonitor(object):
@ -208,11 +201,10 @@ class LogicMonitor(object):
self.fail(msg="Error: " + resp["errmsg"]) self.fail(msg="Error: " + resp["errmsg"])
else: else:
return raw return raw
except IOError: except IOError as ioe:
ioe = get_exception()
self.fail(msg="Error: Exception making RPC call to " + self.fail(msg="Error: Exception making RPC call to " +
"https://" + self.company + "." + self.lm_url + "https://" + self.company + "." + self.lm_url +
"/rpc/" + action + "\nException" + str(ioe)) "/rpc/" + action + "\nException" + to_native(ioe))
def get_collectors(self): def get_collectors(self):
"""Returns a JSON object containing a list of """Returns a JSON object containing a list of
@ -600,9 +592,6 @@ def main():
selector(module) selector(module)
from ansible.module_utils.basic import *
from ansible.module_utils.urls import *
from ansible.module_utils.urls import open_url
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View file

@ -1,24 +1,11 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2017, Loic Blot <loic.blot@unix-experience.fr>
# 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
Ansible module to manage elasticsearch plugins __metaclass__ = type
(c) 2017, Loic Blot <loic.blot@unix-experience.fr>
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/>.
"""
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -85,12 +72,14 @@ EXAMPLES = '''
name: logstash-filter-multiline name: logstash-filter-multiline
''' '''
from ansible.module_utils.basic import AnsibleModule
PACKAGE_STATE_MAP = dict( PACKAGE_STATE_MAP = dict(
present="install", present="install",
absent="remove" absent="remove"
) )
from ansible.module_utils.basic import AnsibleModule
def is_plugin_present(module, plugin_bin, plugin_name): def is_plugin_present(module, plugin_bin, plugin_name):
cmd_args = [plugin_bin, "list", plugin_name] cmd_args = [plugin_bin, "list", plugin_name]
@ -179,5 +168,6 @@ def main():
module.exit_json(changed=changed, cmd=cmd, name=name, state=state, stdout=out, stderr=err) module.exit_json(changed=changed, cmd=cmd, name=name, state=state, stdout=out, stderr=err)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2013, Darryl Stoflet <stoflet@gmail.com> # (c) 2013, Darryl Stoflet <stoflet@gmail.com>
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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/>.
#
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -64,6 +53,8 @@ EXAMPLES = '''
import time import time
from ansible.module_utils.basic import AnsibleModule
def main(): def main():
arg_spec = dict( arg_spec = dict(
@ -188,8 +179,6 @@ def main():
module.exit_json(changed=False, name=name, state=state) module.exit_json(changed=False, name=name, state=state)
# import module snippets
from ansible.module_utils.basic import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -7,12 +7,10 @@
# func-nagios - Schedule downtime and enables/disable notifications # func-nagios - Schedule downtime and enables/disable notifications
# Copyright 2011, Red Hat, Inc. # Copyright 2011, Red Hat, Inc.
# Tim Bielawa <tbielawa@redhat.com> # Tim Bielawa <tbielawa@redhat.com>
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This software may be freely redistributed under the terms of the GNU
# general public license version 2 or any later version. from __future__ import absolute_import, division, print_function
# __metaclass__ = type
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',

View file

@ -2,21 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2013 Matt Coddington <coddington@gmail.com> # Copyright 2013 Matt Coddington <coddington@gmail.com>
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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/>.
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -88,6 +78,8 @@ EXAMPLES = '''
revision: '1.0' revision: '1.0'
''' '''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import fetch_url
from ansible.module_utils.six.moves.urllib.parse import urlencode from ansible.module_utils.six.moves.urllib.parse import urlencode
# =========================================== # ===========================================
@ -145,9 +137,6 @@ def main():
else: else:
module.fail_json(msg="unable to update newrelic: %s" % info['msg']) module.fail_json(msg="unable to update newrelic: %s" % info['msg'])
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.urls import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,20 +1,12 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# This file is part of Ansible # Copyright: Ansible Project
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by from __future__ import absolute_import, division, print_function
# the Free Software Foundation, either version 3 of the License, or __metaclass__ = type
# (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/>.
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -172,8 +164,12 @@ EXAMPLES='''
service: '{{ pd_window.result.maintenance_window.id }}' service: '{{ pd_window.result.maintenance_window.id }}'
''' '''
import datetime
import base64 import base64
import datetime
import json
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import fetch_url
def auth_header(user, passwd, token): def auth_header(user, passwd, token):
if token: if token:
@ -308,9 +304,6 @@ def main():
module.exit_json(msg="success", result=out, changed=changed) module.exit_json(msg="success", result=out, changed=changed)
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.urls import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,20 +1,11 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# # Copyright: Ansible Project
# This file is part of Ansible # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
#
# Ansible is free software: you can redistribute it and/or modify from __future__ import absolute_import, division, print_function
# it under the terms of the GNU General Public License as published by __metaclass__ = type
# 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/>.
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -116,6 +107,10 @@ EXAMPLES = '''
incident_key: somekey incident_key: somekey
desc: "some text for incident's log" desc: "some text for incident's log"
''' '''
import json
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import fetch_url
def check(module, name, state, service_key, api_key, incident_key=None): def check(module, name, state, service_key, api_key, incident_key=None):
@ -215,9 +210,6 @@ def main():
module.exit_json(result=out, changed=changed) module.exit_json(result=out, changed=changed)
# import module snippets
from ansible.module_utils.basic import *
from ansible.module_utils.urls import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,20 +1,12 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# # Copyright: Ansible Project
# This file is part of Ansible # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
#
# Ansible is free software: you can redistribute it and/or modify from __future__ import absolute_import, division, print_function
# it under the terms of the GNU General Public License as published by __metaclass__ = type
# 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/>.
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
'supported_by': 'community'} 'supported_by': 'community'}
@ -96,6 +88,7 @@ try:
except: except:
HAS_PINGDOM = False HAS_PINGDOM = False
from ansible.module_utils.basic import AnsibleModule
def pause(checkid, uid, passwd, key): def pause(checkid, uid, passwd, key):
@ -154,8 +147,6 @@ def main():
module.exit_json(checkid=checkid, name=name, status=result) module.exit_json(checkid=checkid, name=name, status=result)
# import module snippets
from ansible.module_utils.basic import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -2,21 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2014, Max Riveiro, <kavu13@gmail.com> # Copyright 2014, Max Riveiro, <kavu13@gmail.com>
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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/>.
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -81,10 +71,11 @@ EXAMPLES = '''
rollbar_user: admin rollbar_user: admin
comment: Test Deploy comment: Test Deploy
''' '''
import traceback
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils.six.moves.urllib.parse import urlencode from ansible.module_utils.six.moves.urllib.parse import urlencode
from ansible.module_utils._text import to_native
from ansible.module_utils.urls import fetch_url from ansible.module_utils.urls import fetch_url
@ -130,9 +121,8 @@ def main():
try: try:
data = urlencode(params) data = urlencode(params)
response, info = fetch_url(module, url, data=data) response, info = fetch_url(module, url, data=data)
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg='Unable to notify Rollbar: %s' % to_native(e), exception=traceback.format_exc())
module.fail_json(msg='Unable to notify Rollbar: %s' % e)
else: else:
if info['status'] == 200: if info['status'] == 200:
module.exit_json(changed=True) module.exit_json(changed=True)

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2014, Anders Ingemann <aim@secoya.dk> # (c) 2014, Anders Ingemann <aim@secoya.dk>
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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/>.
#
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -207,14 +196,11 @@ EXAMPLES = '''
state: absent state: absent
''' '''
try: import json
import json import traceback
except ImportError:
try: from ansible.module_utils.basic import AnsibleModule
import simplejson as json from ansible.module_utils._text import to_native
except ImportError:
# Let snippet from module_utils/basic.py return a proper error in this case
pass
def sensu_check(module, path, name, state='present', backup=False): def sensu_check(module, path, name, state='present', backup=False):
@ -226,15 +212,14 @@ def sensu_check(module, path, name, state='present', backup=False):
try: try:
stream = open(path, 'r') stream = open(path, 'r')
config = json.load(stream) config = json.load(stream)
except IOError: except IOError as e:
e = get_exception()
if e.errno is 2: # File not found, non-fatal if e.errno is 2: # File not found, non-fatal
if state == 'absent': if state == 'absent':
reasons.append('file did not exist and state is `absent\'') reasons.append('file did not exist and state is `absent\'')
return changed, reasons return changed, reasons
config = {} config = {}
else: else:
module.fail_json(msg=str(e)) module.fail_json(msg=to_native(e), exception=traceback.format_exc())
except ValueError: except ValueError:
msg = '{path} contains invalid JSON'.format(path=path) msg = '{path} contains invalid JSON'.format(path=path)
module.fail_json(msg=msg) module.fail_json(msg=msg)
@ -349,9 +334,8 @@ def sensu_check(module, path, name, state='present', backup=False):
try: try:
stream = open(path, 'w') stream = open(path, 'w')
stream.write(json.dumps(config, indent=2) + '\n') stream.write(json.dumps(config, indent=2) + '\n')
except IOError: except IOError as e:
e = get_exception() module.fail_json(msg=to_native(e), exception=traceback.format_exc())
module.fail_json(msg=str(e))
finally: finally:
if stream: if stream:
stream.close() stream.close()
@ -404,8 +388,6 @@ def main():
module.exit_json(path=path, changed=changed, msg='OK', name=name, reasons=reasons) module.exit_json(path=path, changed=changed, msg='OK', name=name, reasons=reasons)
from ansible.module_utils.basic import *
from ansible.module_utils.pycompat24 import get_exception
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -171,10 +171,11 @@ file:
sample: "/etc/sensu/conf.d/client.json" sample: "/etc/sensu/conf.d/client.json"
''' '''
from ansible.module_utils.basic import AnsibleModule
import json import json
import os import os
from ansible.module_utils.basic import AnsibleModule
def main(): def main():
module = AnsibleModule( module = AnsibleModule(

View file

@ -172,10 +172,11 @@ name:
sample: "irc" sample: "irc"
''' '''
from ansible.module_utils.basic import AnsibleModule
import json import json
import os import os
from ansible.module_utils.basic import AnsibleModule
def main(): def main():
module = AnsibleModule( module = AnsibleModule(

View file

@ -2,21 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2017, Steven Bambling <smbambling@gmail.com> # (c) 2017, Steven Bambling <smbambling@gmail.com>
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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/>.
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -111,7 +101,6 @@ try:
except ImportError: except ImportError:
import simplejson as json import simplejson as json
# import module snippets
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import fetch_url from ansible.module_utils.urls import fetch_url

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2014, Anders Ingemann <aim@secoya.dk> # (c) 2014, Anders Ingemann <aim@secoya.dk>
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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/>.
#
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -75,6 +64,10 @@ EXAMPLES = '''
- name: unsubscribe from common checks - name: unsubscribe from common checks
sensu_subscription: name=common state=absent sensu_subscription: name=common state=absent
''' '''
import traceback
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
def sensu_subscription(module, path, name, state='present', backup=False): def sensu_subscription(module, path, name, state='present', backup=False):
@ -88,15 +81,14 @@ def sensu_subscription(module, path, name, state='present', backup=False):
try: try:
config = json.load(open(path)) config = json.load(open(path))
except IOError: except IOError as e:
e = get_exception()
if e.errno is 2: # File not found, non-fatal if e.errno is 2: # File not found, non-fatal
if state == 'absent': if state == 'absent':
reasons.append('file did not exist and state is `absent\'') reasons.append('file did not exist and state is `absent\'')
return changed, reasons return changed, reasons
config = {} config = {}
else: else:
module.fail_json(msg=str(e)) module.fail_json(msg=to_native(e), exception=traceback.format_exc())
except ValueError: except ValueError:
msg = '{path} contains invalid JSON'.format(path=path) msg = '{path} contains invalid JSON'.format(path=path)
module.fail_json(msg=msg) module.fail_json(msg=msg)
@ -135,9 +127,9 @@ def sensu_subscription(module, path, name, state='present', backup=False):
module.backup_local(path) module.backup_local(path)
try: try:
open(path, 'w').write(json.dumps(config, indent=2) + '\n') open(path, 'w').write(json.dumps(config, indent=2) + '\n')
except IOError: except IOError as e:
e = get_exception() module.fail_json(msg='Failed to write to file %s: %s' % (path, to_native(e)),
module.fail_json(msg='Failed to write to file %s: %s' % (path, str(e))) exception=traceback.format_exc())
return changed, reasons return changed, reasons
@ -146,7 +138,7 @@ def main():
arg_spec = {'name': {'type': 'str', 'required': True}, arg_spec = {'name': {'type': 'str', 'required': True},
'path': {'type': 'str', 'default': '/etc/sensu/conf.d/subscriptions.json'}, 'path': {'type': 'str', 'default': '/etc/sensu/conf.d/subscriptions.json'},
'state': {'type': 'str', 'default': 'present', 'choices': ['present', 'absent']}, 'state': {'type': 'str', 'default': 'present', 'choices': ['present', 'absent']},
'backup': {'type': 'str', 'default': 'no', 'type': 'bool'}, 'backup': {'type': 'bool', 'default': 'no'},
} }
module = AnsibleModule(argument_spec=arg_spec, module = AnsibleModule(argument_spec=arg_spec,
@ -161,6 +153,6 @@ def main():
module.exit_json(path=path, name=name, changed=changed, msg='OK', reasons=reasons) module.exit_json(path=path, name=name, changed=changed, msg='OK', reasons=reasons)
from ansible.module_utils.basic import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,20 +1,12 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# # Copyright: Ansible Project
# This file is part of Ansible # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
#
# Ansible is free software: you can redistribute it and/or modify from __future__ import absolute_import, division, print_function
# it under the terms of the GNU General Public License as published by __metaclass__ = type
# 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/>.
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
'supported_by': 'community'} 'supported_by': 'community'}
@ -110,17 +102,11 @@ EXAMPLES = '''
# Stackdriver module specific support methods. # Stackdriver module specific support methods.
# #
try: import json
import json import traceback
except ImportError:
try:
import simplejson as json
except ImportError:
# Let snippet from module_utils/basic.py return a proper error in this case
pass
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception from ansible.module_utils._text import to_native
from ansible.module_utils.urls import fetch_url from ansible.module_utils.urls import fetch_url
@ -216,18 +202,18 @@ def main():
module.fail_json(msg="revision_id required for deploy events") module.fail_json(msg="revision_id required for deploy events")
try: try:
send_deploy_event(module, key, revision_id, deployed_by, deployed_to, repository) send_deploy_event(module, key, revision_id, deployed_by, deployed_to, repository)
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg="unable to sent deploy event: %s" % to_native(e),
module.fail_json(msg="unable to sent deploy event: %s" % e) exception=traceback.format_exc())
if event == 'annotation': if event == 'annotation':
if not msg: if not msg:
module.fail_json(msg="msg required for annotation events") module.fail_json(msg="msg required for annotation events")
try: try:
send_annotation_event(module, key, msg, annotated_by, level, instance_id, event_epoch) send_annotation_event(module, key, msg, annotated_by, level, instance_id, event_epoch)
except Exception: except Exception as e:
e = get_exception() module.fail_json(msg="unable to sent annotation event: %s" % to_native(e),
module.fail_json(msg="unable to sent annotation event: %s" % e) exception=traceback.format_exc())
changed = True changed = True
module.exit_json(changed=changed, deployed_by=deployed_by) module.exit_json(changed=changed, deployed_by=deployed_by)

View file

@ -2,21 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2015, Benjamin Copeland (@bhcopeland) <ben@copeland.me.uk> # (c) 2015, Benjamin Copeland (@bhcopeland) <ben@copeland.me.uk>
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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/>.
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],

View file

@ -1,20 +1,12 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# # Copyright: Ansible Project
# This file is part of Ansible # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
#
# Ansible is free software: you can redistribute it and/or modify from __future__ import absolute_import, division, print_function
# it under the terms of the GNU General Public License as published by __metaclass__ = type
# 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/>.
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
'supported_by': 'community'} 'supported_by': 'community'}
@ -70,18 +62,12 @@ EXAMPLES = '''
state: started state: started
''' '''
try: import json
import json
except ImportError:
try:
import simplejson as json
except ImportError:
# Let snippet from module_utils/basic.py return a proper error in this case
pass
import time
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six.moves.urllib.parse import urlencode from ansible.module_utils.six.moves.urllib.parse import urlencode
from ansible.module_utils.urls import fetch_url
API_BASE = "http://api.uptimerobot.com/" API_BASE = "http://api.uptimerobot.com/"
@ -169,7 +155,5 @@ def main():
) )
from ansible.module_utils.basic import *
from ansible.module_utils.urls import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -2,21 +2,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# (c) 2013-2014, Epic Games, Inc. # (c) 2013-2014, Epic Games, Inc.
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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/>.
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
@ -120,6 +109,8 @@ try:
except ImportError: except ImportError:
HAS_ZABBIX_API = False HAS_ZABBIX_API = False
from ansible.module_utils.basic import AnsibleModule
class HostGroup(object): class HostGroup(object):
def __init__(self, module, zbx): def __init__(self, module, zbx):
@ -226,7 +217,6 @@ def main():
else: else:
module.exit_json(changed=False) module.exit_json(changed=False)
from ansible.module_utils.basic import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2013-2014, Epic Games, Inc. # (c) 2013-2014, Epic Games, Inc.
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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/>.
#
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -163,7 +152,6 @@ EXAMPLES = '''
proxy: a.zabbix.proxy proxy: a.zabbix.proxy
''' '''
import logging
import copy import copy
try: try:
@ -184,6 +172,9 @@ try:
except ImportError: except ImportError:
HAS_ZABBIX_API = False HAS_ZABBIX_API = False
from ansible.module_utils.basic import AnsibleModule
class Host(object): class Host(object):
def __init__(self, module, zbx): def __init__(self, module, zbx):
self._module = module self._module = module
@ -576,7 +567,6 @@ def main():
module.exit_json(changed=True, result="Successfully added host %s (%s) and linked with template '%s'" % ( module.exit_json(changed=True, result="Successfully added host %s (%s) and linked with template '%s'" % (
host_name, ip, link_templates)) host_name, ip, link_templates))
from ansible.module_utils.basic import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2013-2014, Epic Games, Inc. # (c) 2013-2014, Epic Games, Inc.
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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/>.
#
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'], 'status': ['preview'],
@ -102,9 +91,6 @@ EXAMPLES = '''
state: present state: present
''' '''
import logging
import copy
try: try:
from zabbix_api import ZabbixAPI, ZabbixAPISubClass from zabbix_api import ZabbixAPI, ZabbixAPISubClass
@ -118,6 +104,8 @@ try:
except ImportError: except ImportError:
HAS_ZABBIX_API = False HAS_ZABBIX_API = False
from ansible.module_utils.basic import AnsibleModule
class HostMacro(object): class HostMacro(object):
def __init__(self, module, zbx): def __init__(self, module, zbx):
@ -222,8 +210,6 @@ def main():
host_macro_class_obj = HostMacro(module, zbx) host_macro_class_obj = HostMacro(module, zbx)
changed = False
if host_name: if host_name:
host_id = host_macro_class_obj.get_host_id(host_name) host_id = host_macro_class_obj.get_host_id(host_name)
host_macro_obj = host_macro_class_obj.get_host_macro(macro_name, host_id) host_macro_obj = host_macro_class_obj.get_host_macro(macro_name, host_id)
@ -242,7 +228,6 @@ def main():
# update host macro # update host macro
host_macro_class_obj.update_host_macro(host_macro_obj, macro_name, macro_value) host_macro_class_obj.update_host_macro(host_macro_obj, macro_name, macro_value)
from ansible.module_utils.basic import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -2,21 +2,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2013, Alexander Bulimov <lazywolf0@gmail.com> # (c) 2013, Alexander Bulimov <lazywolf0@gmail.com>
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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/>.
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
@ -177,6 +166,8 @@ try:
except ImportError: except ImportError:
HAS_ZABBIX_API = False HAS_ZABBIX_API = False
from ansible.module_utils.basic import AnsibleModule
def create_maintenance(zbx, group_ids, host_ids, start_time, maintenance_type, period, name, desc): def create_maintenance(zbx, group_ids, host_ids, start_time, maintenance_type, period, name, desc):
end_time = start_time + period end_time = start_time + period
@ -383,7 +374,6 @@ def main():
module.exit_json(changed=changed) module.exit_json(changed=changed)
from ansible.module_utils.basic import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -2,22 +2,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2013-2014, Epic Games, Inc. # (c) 2013-2014, Epic Games, Inc.
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This file is part of Ansible
# from __future__ import absolute_import, division, print_function
# Ansible is free software: you can redistribute it and/or modify __metaclass__ = type
# 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/>.
#
ANSIBLE_METADATA = {'metadata_version': '1.0', ANSIBLE_METADATA = {'metadata_version': '1.0',
@ -165,6 +154,9 @@ try:
except ImportError: except ImportError:
HAS_ZABBIX_API = False HAS_ZABBIX_API = False
from ansible.module_utils.basic import AnsibleModule
class Screen(object): class Screen(object):
def __init__(self, module, zbx): def __init__(self, module, zbx):
self._module = module self._module = module
@ -291,7 +283,7 @@ class Screen(object):
h_size = 2 h_size = 2
else: else:
h_size = 3 h_size = 3
v_size = (v_size - 1) / h_size + 1 v_size = (v_size - 1) // h_size + 1
return h_size, v_size return h_size, v_size
# create screen_items # create screen_items
@ -313,7 +305,7 @@ class Screen(object):
if graph_id is not None: if graph_id is not None:
self._zapi.screenitem.create({'screenid': screen_id, 'resourcetype': 0, 'resourceid': graph_id, self._zapi.screenitem.create({'screenid': screen_id, 'resourcetype': 0, 'resourceid': graph_id,
'width': width, 'height': height, 'width': width, 'height': height,
'x': i % h_size, 'y': i / h_size, 'colspan': 1, 'rowspan': 1, 'x': i % h_size, 'y': i // h_size, 'colspan': 1, 'rowspan': 1,
'elements': 0, 'valign': 0, 'halign': 0, 'elements': 0, 'valign': 0, 'halign': 0,
'style': 0, 'dynamic': 0, 'sort_triggers': 0}) 'style': 0, 'dynamic': 0, 'sort_triggers': 0})
else: else:
@ -436,7 +428,6 @@ def main():
else: else:
module.exit_json(changed=False) module.exit_json(changed=False)
from ansible.module_utils.basic import *
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -24,7 +24,6 @@ metaclass3=$(find ./lib/ansible/modules -path ./lib/ansible/modules/windows -pru
-o -path ./lib/ansible/modules/cloud/openstack -prune \ -o -path ./lib/ansible/modules/cloud/openstack -prune \
-o -path ./lib/ansible/modules/cloud/cloudstack -prune \ -o -path ./lib/ansible/modules/cloud/cloudstack -prune \
-o -path ./lib/ansible/modules/cloud/amazon -prune \ -o -path ./lib/ansible/modules/cloud/amazon -prune \
-o -path ./lib/ansible/modules/monitoring -prune \
-o -path ./lib/ansible/modules/network/aos -prune \ -o -path ./lib/ansible/modules/network/aos -prune \
-o -path ./lib/ansible/modules/network/avi -prune \ -o -path ./lib/ansible/modules/network/avi -prune \
-o -path ./lib/ansible/modules/network/cloudengine -prune \ -o -path ./lib/ansible/modules/network/cloudengine -prune \
@ -44,7 +43,6 @@ future3=$(find ./lib/ansible/modules -path ./lib/ansible/modules/windows -prune
-o -path ./lib/ansible/modules/cloud/openstack -prune \ -o -path ./lib/ansible/modules/cloud/openstack -prune \
-o -path ./lib/ansible/modules/cloud/cloudstack -prune \ -o -path ./lib/ansible/modules/cloud/cloudstack -prune \
-o -path ./lib/ansible/modules/cloud/amazon -prune \ -o -path ./lib/ansible/modules/cloud/amazon -prune \
-o -path ./lib/ansible/modules/monitoring -prune \
-o -path ./lib/ansible/modules/network/aos -prune \ -o -path ./lib/ansible/modules/network/aos -prune \
-o -path ./lib/ansible/modules/network/avi -prune \ -o -path ./lib/ansible/modules/network/avi -prune \
-o -path ./lib/ansible/modules/network/cloudengine -prune \ -o -path ./lib/ansible/modules/network/cloudengine -prune \

View file

@ -9,7 +9,6 @@ get_exception=$(find . -path ./test/runner/.tox -prune \
-o -path ./lib/ansible/module_utils/basic.py -prune \ -o -path ./lib/ansible/module_utils/basic.py -prune \
-o -path ./lib/ansible/modules/storage/netapp -prune \ -o -path ./lib/ansible/modules/storage/netapp -prune \
-o -path ./lib/ansible/modules/packaging/os -prune \ -o -path ./lib/ansible/modules/packaging/os -prune \
-o -path ./lib/ansible/modules/monitoring -prune \
-o -path ./lib/ansible/modules/network/panos -prune \ -o -path ./lib/ansible/modules/network/panos -prune \
-o -path ./lib/ansible/modules/network/nxos -prune \ -o -path ./lib/ansible/modules/network/nxos -prune \
-o -path ./lib/ansible/modules/network/junos -prune \ -o -path ./lib/ansible/modules/network/junos -prune \

View file

@ -21,7 +21,6 @@ wildcard_imports=$(find . -path ./test/runner/.tox -prune \
-o -path ./lib/ansible/modules/cloud/amazon -prune \ -o -path ./lib/ansible/modules/cloud/amazon -prune \
-o -path ./lib/ansible/modules/cloud/openstack -prune \ -o -path ./lib/ansible/modules/cloud/openstack -prune \
-o -path ./lib/ansible/modules/cloud/cloudstack -prune \ -o -path ./lib/ansible/modules/cloud/cloudstack -prune \
-o -path ./lib/ansible/modules/monitoring -prune \
-o -path ./lib/ansible/modules/network/f5 -prune \ -o -path ./lib/ansible/modules/network/f5 -prune \
-o -path ./lib/ansible/modules/network/nxos -prune \ -o -path ./lib/ansible/modules/network/nxos -prune \
-o -path ./lib/ansible/modules/packaging/os -prune \ -o -path ./lib/ansible/modules/packaging/os -prune \

View file

@ -214,17 +214,14 @@ lib/ansible/modules/files/replace.py
lib/ansible/modules/files/synchronize.py lib/ansible/modules/files/synchronize.py
lib/ansible/modules/files/tempfile.py lib/ansible/modules/files/tempfile.py
lib/ansible/modules/files/xattr.py lib/ansible/modules/files/xattr.py
lib/ansible/modules/monitoring/airbrake_deployment.py
lib/ansible/modules/monitoring/bigpanda.py lib/ansible/modules/monitoring/bigpanda.py
lib/ansible/modules/monitoring/boundary_meter.py lib/ansible/modules/monitoring/boundary_meter.py
lib/ansible/modules/monitoring/circonus_annotation.py lib/ansible/modules/monitoring/circonus_annotation.py
lib/ansible/modules/monitoring/datadog_event.py lib/ansible/modules/monitoring/datadog_event.py
lib/ansible/modules/monitoring/honeybadger_deployment.py
lib/ansible/modules/monitoring/icinga2_feature.py lib/ansible/modules/monitoring/icinga2_feature.py
lib/ansible/modules/monitoring/librato_annotation.py lib/ansible/modules/monitoring/librato_annotation.py
lib/ansible/modules/monitoring/logentries.py lib/ansible/modules/monitoring/logentries.py
lib/ansible/modules/monitoring/logicmonitor.py lib/ansible/modules/monitoring/logicmonitor.py
lib/ansible/modules/monitoring/logstash_plugin.py
lib/ansible/modules/monitoring/nagios.py lib/ansible/modules/monitoring/nagios.py
lib/ansible/modules/monitoring/newrelic_deployment.py lib/ansible/modules/monitoring/newrelic_deployment.py
lib/ansible/modules/monitoring/pagerduty.py lib/ansible/modules/monitoring/pagerduty.py