diff --git a/lib/ansible/compat/tests/mock.py b/lib/ansible/compat/tests/mock.py
index c4bda61ccb..dd83e39167 100644
--- a/lib/ansible/compat/tests/mock.py
+++ b/lib/ansible/compat/tests/mock.py
@@ -30,9 +30,13 @@ import sys
# is the same as the python3 stdlib mock library
try:
+ # Allow wildcard import because we really do want to import all of mock's
+ # symbols into this compat shim
+ # pylint: disable=wildcard-import
from unittest.mock import *
except ImportError:
# Python 2
+ # pylint: disable=wildcard-import
try:
from mock import *
except ImportError:
diff --git a/lib/ansible/compat/tests/unittest.py b/lib/ansible/compat/tests/unittest.py
index a629849b31..e1fc7e7f5a 100644
--- a/lib/ansible/compat/tests/unittest.py
+++ b/lib/ansible/compat/tests/unittest.py
@@ -25,7 +25,9 @@ Compat module for Python2.7's unittest module
import sys
-# Python 2.6
+# Allow wildcard import because we really do want to import all of
+# unittests's symbols into this compat shim
+# pylint: disable=wildcard-import
if sys.version_info < (2, 7):
try:
# Need unittest2 on python2.6
diff --git a/lib/ansible/module_utils/f5_utils.py b/lib/ansible/module_utils/f5_utils.py
index 5a176fd29c..7b7aeaeba8 100644
--- a/lib/ansible/module_utils/f5_utils.py
+++ b/lib/ansible/module_utils/f5_utils.py
@@ -152,7 +152,7 @@ except ImportError:
HAS_F5SDK = False
-from ansible.module_utils.basic import *
+from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six import iteritems, with_metaclass
diff --git a/lib/ansible/modules/cloud/atomic/atomic_container.py b/lib/ansible/modules/cloud/atomic/atomic_container.py
index a673a48bc2..777c8e55a5 100644
--- a/lib/ansible/modules/cloud/atomic/atomic_container.py
+++ b/lib/ansible/modules/cloud/atomic/atomic_container.py
@@ -1,20 +1,12 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -109,8 +101,8 @@ msg:
# import module snippets
import traceback
-from ansible.module_utils._text import to_native
from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils._text import to_native
def do_install(module, mode, rootfs, container, image, values_list, backend):
@@ -206,7 +198,7 @@ def main():
)
if module.params['values'] is not None and module.params['mode'] == 'default':
- module.fail_json(msg="values is supported only with user or system mode", err=err)
+ module.fail_json(msg="values is supported only with user or system mode")
# Verify that the platform supports atomic command
rc, out, err = module.run_command('atomic -v', check_rc=False)
diff --git a/lib/ansible/modules/cloud/atomic/atomic_host.py b/lib/ansible/modules/cloud/atomic/atomic_host.py
index ca38443ef9..f34f085b9c 100644
--- a/lib/ansible/modules/cloud/atomic/atomic_host.py
+++ b/lib/ansible/modules/cloud/atomic/atomic_host.py
@@ -1,20 +1,12 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-# 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 licenses
-# along with Ansible. If not, see .
+# 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.0',
'status': ['preview'],
@@ -62,9 +54,11 @@ msg:
type: string
sample: 'Already on latest'
'''
+import os
+import traceback
-# import module snippets
-from ansible.module_utils.basic import AnsibleModule, os
+from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils._text import to_native
def core(module):
@@ -106,7 +100,7 @@ def main():
try:
core(module)
except Exception as e:
- module.fail_json(msg=str(e))
+ module.fail_json(msg=to_native(e), exception=traceback.format_exc())
if __name__ == '__main__':
diff --git a/lib/ansible/modules/cloud/atomic/atomic_image.py b/lib/ansible/modules/cloud/atomic/atomic_image.py
index 5199927da7..5ec0a113dc 100644
--- a/lib/ansible/modules/cloud/atomic/atomic_image.py
+++ b/lib/ansible/modules/cloud/atomic/atomic_image.py
@@ -1,20 +1,12 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -84,10 +76,10 @@ msg:
type: string
sample: [u'Using default tag: latest ...']
'''
+import traceback
-
-# import module snippets
from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils._text import to_native
def do_upgrade(module, image):
@@ -179,7 +171,7 @@ def main():
try:
core(module)
except Exception as e:
- module.fail_json(msg=str(e))
+ module.fail_json(msg=to_native(e), exception=traceback.format_exc())
if __name__ == '__main__':
diff --git a/lib/ansible/modules/cloud/cloudscale/cloudscale_server.py b/lib/ansible/modules/cloud/cloudscale/cloudscale_server.py
index 149dd2eddd..79158830ca 100644
--- a/lib/ansible/modules/cloud/cloudscale/cloudscale_server.py
+++ b/lib/ansible/modules/cloud/cloudscale/cloudscale_server.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
#
# (c) 2017, Gaudenz Steinlin
-#
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -221,15 +211,16 @@ anti_affinity_with:
sample: []
'''
-from datetime import datetime, timedelta
import json
import os
+from datetime import datetime, timedelta
from time import sleep
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six.moves.urllib.parse import urlencode
from ansible.module_utils.urls import fetch_url
+
API_URL = 'https://api.cloudscale.ch/v1/'
TIMEOUT_WAIT = 30
ALLOWED_STATES = ('running',
@@ -237,6 +228,7 @@ ALLOWED_STATES = ('running',
'absent',
)
+
class AnsibleCloudscaleServer(object):
def __init__(self, module, api_token):
diff --git a/lib/ansible/modules/cloud/dimensiondata/dimensiondata_network.py b/lib/ansible/modules/cloud/dimensiondata/dimensiondata_network.py
index 334246fde8..1691aac23e 100644
--- a/lib/ansible/modules/cloud/dimensiondata/dimensiondata_network.py
+++ b/lib/ansible/modules/cloud/dimensiondata/dimensiondata_network.py
@@ -2,25 +2,16 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016 Dimension Data
-#
-# 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
-# the Free Software Foundation, either version 3 of the License, or
-# (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 .
-#
# Authors:
# - Aimon Bustardo
# - Bert Diwa
# - Adam Friedman
#
+# 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.0',
'status': ['preview'],
@@ -117,11 +108,8 @@ network:
type: boolean
sample: false
'''
+import traceback
-
-from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.dimensiondata import DimensionDataModule, DimensionDataAPIException
-from ansible.module_utils.pycompat24 import get_exception
try:
from libcloud.compute.base import NodeLocation
@@ -129,6 +117,10 @@ try:
except ImportError:
HAS_LIBCLOUD = False
+from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils.dimensiondata import DimensionDataModule, DimensionDataAPIException
+from ansible.module_utils._text import to_native
+
class DimensionDataNetworkModule(DimensionDataModule):
"""
@@ -251,11 +243,10 @@ class DimensionDataNetworkModule(DimensionDataModule):
self.module.params['service_plan'],
description=self.description
)
- except DimensionDataAPIException:
- api_exception = get_exception()
+ except DimensionDataAPIException as e:
self.module.fail_json(
- msg="Failed to create new network: %s" % str(api_exception)
+ msg="Failed to create new network: %s" % to_native(e), exception=traceback.format_exc()
)
return None
@@ -282,11 +273,9 @@ class DimensionDataNetworkModule(DimensionDataModule):
"Unexpected failure deleting network with id %s", network.id
)
- except DimensionDataAPIException:
- api_exception = get_exception()
-
+ except DimensionDataAPIException as e:
self.module.fail_json(
- msg="Failed to delete network: %s" % str(api_exception)
+ msg="Failed to delete network: %s" % to_native(e), exception=traceback.format_exc()
)
def _wait_for_network_state(self, net_id, state_to_wait_for):
@@ -298,11 +287,10 @@ class DimensionDataNetworkModule(DimensionDataModule):
self.module.params['wait_time'],
net_id
)
- except DimensionDataAPIException:
- api_exception = get_exception()
-
+ except DimensionDataAPIException as e:
self.module.fail_json(
- msg='Network did not reach % state in time: %s' % (state_to_wait_for, api_exception.msg)
+ msg='Network did not reach % state in time: %s' % (state_to_wait_for, to_native(e)),
+ exception=traceback.format_exc()
)
diff --git a/lib/ansible/modules/cloud/linode/linode.py b/lib/ansible/modules/cloud/linode/linode.py
index 4b27f6a122..f07a44bb8e 100644
--- a/lib/ansible/modules/cloud/linode/linode.py
+++ b/lib/ansible/modules/cloud/linode/linode.py
@@ -1,18 +1,10 @@
#!/usr/bin/python
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -274,8 +266,8 @@ EXAMPLES = '''
state: restarted
'''
-import time
import os
+import time
try:
import pycurl
@@ -283,13 +275,14 @@ try:
except ImportError:
HAS_PYCURL = False
-
try:
from linode import api as linode_api
HAS_LINODE = True
except ImportError:
HAS_LINODE = False
+from ansible.module_utils.basic import AnsibleModule
+
def randompass():
'''
@@ -694,8 +687,6 @@ def main():
payment_term, password, private_ip, ssh_pub_key, swap, wait,
wait_timeout, watchdog, **kwargs)
-# import module snippets
-from ansible.module_utils.basic import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/cloud/lxc/lxc_container.py b/lib/ansible/modules/cloud/lxc/lxc_container.py
index b9ffea0dba..8ab7f27b53 100644
--- a/lib/ansible/modules/cloud/lxc/lxc_container.py
+++ b/lib/ansible/modules/cloud/lxc/lxc_container.py
@@ -2,21 +2,10 @@
# -*- coding: utf-8 -*-
# (c) 2014, Kevin Carter
-#
-# 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 .
+# 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.0',
@@ -446,7 +435,6 @@ except ImportError:
else:
HAS_LXC = True
-# import module bits
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.parsing.convert_bool import BOOLEANS_FALSE, BOOLEANS_TRUE
from ansible.module_utils.six.moves import xrange
diff --git a/lib/ansible/modules/cloud/lxd/lxd_container.py b/lib/ansible/modules/cloud/lxd/lxd_container.py
index 4c182239f3..ebe3075067 100644
--- a/lib/ansible/modules/cloud/lxd/lxd_container.py
+++ b/lib/ansible/modules/cloud/lxd/lxd_container.py
@@ -2,21 +2,10 @@
# -*- coding: utf-8 -*-
# (c) 2016, Hiroaki Nakamura
-#
-# 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 .
+# 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.0',
@@ -249,10 +238,14 @@ actions:
type: list
sample: '["create", "start"]'
'''
-
+import datetime
import os
+import time
+
+from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.lxd import LXDClient, LXDClientException
+
# LXD_ANSIBLE_STATES is a map of states that contain values of methods used
# when a particular state is evoked.
LXD_ANSIBLE_STATES = {
@@ -276,16 +269,6 @@ CONFIG_PARAMS = [
'architecture', 'config', 'devices', 'ephemeral', 'profiles', 'source'
]
-try:
- callable(all)
-except NameError:
- # For python <2.5
- # This definition is copied from https://docs.python.org/2/library/functions.html#all
- def all(iterable):
- for element in iterable:
- if not element:
- return False
- return True
class LXDContainerManagement(object):
def __init__(self, module):
@@ -389,7 +372,7 @@ class LXDContainerManagement(object):
@staticmethod
def _has_all_ipv4_addresses(addresses):
- return len(addresses) > 0 and all([len(v) > 0 for v in addresses.values()])
+ return len(addresses) > 0 and all(len(v) > 0 for v in addresses.values())
def _get_addresses(self):
try:
@@ -608,7 +591,6 @@ def main():
lxd_manage = LXDContainerManagement(module=module)
lxd_manage.run()
-# import module bits
-from ansible.module_utils.basic import *
+
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/cloud/lxd/lxd_profile.py b/lib/ansible/modules/cloud/lxd/lxd_profile.py
index fe566af697..518674aab4 100644
--- a/lib/ansible/modules/cloud/lxd/lxd_profile.py
+++ b/lib/ansible/modules/cloud/lxd/lxd_profile.py
@@ -2,21 +2,10 @@
# -*- coding: utf-8 -*-
# (c) 2016, Hiroaki Nakamura
-#
-# 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 .
+# 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.0',
@@ -177,8 +166,11 @@ actions:
'''
import os
+
+from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.lxd import LXDClient, LXDClientException
+
# PROFILE_STATES is a list for states supported
PROFILES_STATES = [
'present', 'absent'
@@ -189,6 +181,7 @@ CONFIG_PARAMS = [
'config', 'description', 'devices'
]
+
class LXDProfileManagement(object):
def __init__(self, module):
"""Management of LXC containers via Ansible.
@@ -371,7 +364,6 @@ def main():
lxd_manage = LXDProfileManagement(module=module)
lxd_manage.run()
-# import module bits
-from ansible.module_utils.basic import *
+
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/cloud/ovh/ovh_ip_loadbalancing_backend.py b/lib/ansible/modules/cloud/ovh/ovh_ip_loadbalancing_backend.py
index a15b336483..4b907f7357 100644
--- a/lib/ansible/modules/cloud/ovh/ovh_ip_loadbalancing_backend.py
+++ b/lib/ansible/modules/cloud/ovh/ovh_ip_loadbalancing_backend.py
@@ -1,18 +1,12 @@
#!/usr/bin/python
-# 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 .
+
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
@@ -113,6 +107,7 @@ RETURN = '''
'''
import time
+
try:
import ovh
import ovh.exceptions
@@ -121,6 +116,9 @@ try:
except ImportError:
HAS_OVH = False
+from ansible.module_utils.basic import AnsibleModule
+
+
def getOvhClient(ansibleModule):
endpoint = ansibleModule.params.get('endpoint')
application_key = ansibleModule.params.get('application_key')
@@ -309,8 +307,6 @@ def main():
module.exit_json(changed=moduleChanged)
-# import module snippets
-from ansible.module_utils.basic import AnsibleModule
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/cloud/packet/packet_device.py b/lib/ansible/modules/cloud/packet/packet_device.py
index 3ce4f2867e..5dd20fd6b9 100644
--- a/lib/ansible/modules/cloud/packet/packet_device.py
+++ b/lib/ansible/modules/cloud/packet/packet_device.py
@@ -3,20 +3,11 @@
# (c) 2016, Matt Baldwin
# (c) 2016, Thibaud Morel l'Horset
#
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -212,19 +203,18 @@ devices:
import os
+import re
import time
import uuid
-import re
-
-from ansible.module_utils.basic import AnsibleModule
HAS_PACKET_SDK = True
-
try:
import packet
except ImportError:
HAS_PACKET_SDK = False
+from ansible.module_utils.basic import AnsibleModule
+
NAME_RE = '({0}|{0}{1}*{0})'.format('[a-zA-Z0-9]','[a-zA-Z0-9\-]')
HOSTNAME_RE = '({0}\.)*{0}$'.format(NAME_RE)
@@ -567,6 +557,5 @@ def main():
module.fail_json(msg='failed to set machine state %s, error: %s' % (state,str(e)))
-
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/cloud/packet/packet_sshkey.py b/lib/ansible/modules/cloud/packet/packet_sshkey.py
index 180dffcde7..91c2d915f2 100644
--- a/lib/ansible/modules/cloud/packet/packet_sshkey.py
+++ b/lib/ansible/modules/cloud/packet/packet_sshkey.py
@@ -1,20 +1,10 @@
#!/usr/bin/python
# Copyright 2016 Tomas Karasek
-#
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -112,8 +102,6 @@ import uuid
from ansible.module_utils.basic import AnsibleModule
HAS_PACKET_SDK = True
-
-
try:
import packet
except ImportError:
diff --git a/lib/ansible/modules/cloud/profitbricks/profitbricks.py b/lib/ansible/modules/cloud/profitbricks/profitbricks.py
index 97334bf02d..0ab12f1a8c 100644
--- a/lib/ansible/modules/cloud/profitbricks/profitbricks.py
+++ b/lib/ansible/modules/cloud/profitbricks/profitbricks.py
@@ -1,18 +1,10 @@
#!/usr/bin/python
-# 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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/cloud/profitbricks/profitbricks_datacenter.py b/lib/ansible/modules/cloud/profitbricks/profitbricks_datacenter.py
index 8d6c696dc6..9957de3167 100644
--- a/lib/ansible/modules/cloud/profitbricks/profitbricks_datacenter.py
+++ b/lib/ansible/modules/cloud/profitbricks/profitbricks_datacenter.py
@@ -1,18 +1,10 @@
#!/usr/bin/python
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -87,17 +79,17 @@ EXAMPLES = '''
'''
import re
-import uuid
import time
-import sys
HAS_PB_SDK = True
-
try:
from profitbricks.client import ProfitBricksService, Datacenter
except ImportError:
HAS_PB_SDK = False
+from ansible.module_utils.basic import AnsibleModule
+
+
LOCATIONS = ['us/las',
'de/fra',
'de/fkb']
@@ -151,8 +143,6 @@ def create_datacenter(module, profitbricks):
description = module.params.get('description')
wait = module.params.get('wait')
wait_timeout = int(module.params.get('wait_timeout'))
- virtual_datacenters = []
-
i = Datacenter(
name=name,
@@ -260,7 +250,6 @@ def main():
except Exception as e:
module.fail_json(msg='failed to set datacenter state: %s' % str(e))
-from ansible.module_utils.basic import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/cloud/profitbricks/profitbricks_nic.py b/lib/ansible/modules/cloud/profitbricks/profitbricks_nic.py
index 2d7f6d8813..7ec6d2a9ee 100644
--- a/lib/ansible/modules/cloud/profitbricks/profitbricks_nic.py
+++ b/lib/ansible/modules/cloud/profitbricks/profitbricks_nic.py
@@ -1,18 +1,10 @@
#!/usr/bin/python
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -97,12 +89,14 @@ import uuid
import time
HAS_PB_SDK = True
-
try:
from profitbricks.client import ProfitBricksService, NIC
except ImportError:
HAS_PB_SDK = False
+from ansible.module_utils.basic import AnsibleModule
+
+
uuid_match = re.compile(
'[\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12}', re.I)
@@ -291,7 +285,6 @@ def main():
except Exception as e:
module.fail_json(msg='failed to set nic state: %s' % str(e))
-from ansible.module_utils.basic import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/cloud/profitbricks/profitbricks_volume.py b/lib/ansible/modules/cloud/profitbricks/profitbricks_volume.py
index e2ed3e536f..25f3cc523e 100644
--- a/lib/ansible/modules/cloud/profitbricks/profitbricks_volume.py
+++ b/lib/ansible/modules/cloud/profitbricks/profitbricks_volume.py
@@ -1,18 +1,10 @@
#!/usr/bin/python
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -144,7 +136,6 @@ import time
import traceback
HAS_PB_SDK = True
-
try:
from profitbricks.client import ProfitBricksService, Volume
except ImportError:
diff --git a/lib/ansible/modules/cloud/profitbricks/profitbricks_volume_attachments.py b/lib/ansible/modules/cloud/profitbricks/profitbricks_volume_attachments.py
index 6b8abf0787..5283ec9315 100644
--- a/lib/ansible/modules/cloud/profitbricks/profitbricks_volume_attachments.py
+++ b/lib/ansible/modules/cloud/profitbricks/profitbricks_volume_attachments.py
@@ -1,18 +1,10 @@
#!/usr/bin/python
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -91,16 +83,17 @@ EXAMPLES = '''
'''
import re
-import uuid
import time
HAS_PB_SDK = True
-
try:
- from profitbricks.client import ProfitBricksService, Volume
+ from profitbricks.client import ProfitBricksService
except ImportError:
HAS_PB_SDK = False
+from ansible.module_utils.basic import AnsibleModule
+
+
uuid_match = re.compile(
'[\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12}', re.I)
@@ -263,7 +256,6 @@ def main():
except Exception as e:
module.fail_json(msg='failed to set volume_attach state: %s' % str(e))
-from ansible.module_utils.basic import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/cloud/pubnub/pubnub_blocks.py b/lib/ansible/modules/cloud/pubnub/pubnub_blocks.py
index a2eddc6743..0f871626cd 100644
--- a/lib/ansible/modules/cloud/pubnub/pubnub_blocks.py
+++ b/lib/ansible/modules/cloud/pubnub/pubnub_blocks.py
@@ -6,18 +6,10 @@
# http://www.pubnub.com/
# http://www.pubnub.com/terms
#
-# 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
-# the Free Software Foundation, either version 3 of the License, or
-# (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, see .
+# 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.0',
@@ -232,11 +224,6 @@ module_cache:
import copy
import os
-# Import module snippets
-from ansible.module_utils.basic import AnsibleModule
-# noinspection PyProtectedMember
-from ansible.module_utils._text import *
-
try:
# Import PubNub BLOCKS client.
from pubnub_blocks_client import User, Account, Owner, Application, Keyset
@@ -254,6 +241,9 @@ except ImportError:
EventHandler = None
exceptions = None
+from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils._text import to_text
+
def pubnub_user(module):
"""Create and configure user model if it possible.
diff --git a/lib/ansible/modules/cloud/smartos/imgadm.py b/lib/ansible/modules/cloud/smartos/imgadm.py
index edb9a19b1b..dd686bb8e6 100644
--- a/lib/ansible/modules/cloud/smartos/imgadm.py
+++ b/lib/ansible/modules/cloud/smartos/imgadm.py
@@ -2,22 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2016, 2017 Jasper Lievisse Adriaanse
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
@@ -124,9 +113,10 @@ state:
sample: 'present'
'''
-from ansible.module_utils.basic import AnsibleModule
import re
+from ansible.module_utils.basic import AnsibleModule
+
# Shortcut for the imgadm(1M) command. While imgadm(1M) supports a
# -E option to return any errors in JSON, the generated JSON does not play well
# with the JSON parsers of Python. The returned message contains '\n' as part of
diff --git a/lib/ansible/modules/cloud/smartos/smartos_image_facts.py b/lib/ansible/modules/cloud/smartos/smartos_image_facts.py
index d10fad72cd..fccadbd2e7 100644
--- a/lib/ansible/modules/cloud/smartos/smartos_image_facts.py
+++ b/lib/ansible/modules/cloud/smartos/smartos_image_facts.py
@@ -2,22 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2015, Adam Števko
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
@@ -63,10 +52,9 @@ RETURN = '''
# this module returns ansible_facts
'''
-try:
- import json
-except ImportError:
- import simplejson as json
+import json
+
+from ansible.module_utils.basic import AnsibleModule
class ImageFacts(object):
@@ -118,7 +106,6 @@ def main():
module.exit_json(ansible_facts=data)
-from ansible.module_utils.basic import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/cloud/smartos/vmadm.py b/lib/ansible/modules/cloud/smartos/vmadm.py
index 19dd3bffd7..194954be1b 100644
--- a/lib/ansible/modules/cloud/smartos/vmadm.py
+++ b/lib/ansible/modules/cloud/smartos/vmadm.py
@@ -2,22 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2017, Jasper Lievisse Adriaanse
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
@@ -346,15 +335,12 @@ state:
sample: 'running'
'''
+import json
import os
import re
import tempfile
import traceback
-try:
- import json
-except ImportError:
- import simplejson as json
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
@@ -464,9 +450,8 @@ def new_vm(module, uuid, vm_state):
except Exception as e:
# Since the payload may contain sensitive information, fail hard
# if we cannot remove the file so the operator knows about it.
- module.fail_json(
- msg='Could not remove temporary JSON payload file {0}'.format(payload_file),
- exception=traceback.format_exc())
+ module.fail_json(msg='Could not remove temporary JSON payload file {0}: {1}'.format(payload_file, to_native(e)),
+ exception=traceback.format_exc())
return changed, vm_uuid
@@ -544,8 +529,7 @@ def create_payload(module, uuid):
fh.write(vmdef_json)
fh.close()
except Exception as e:
- module.fail_json(
- msg='Could not save JSON payload', exception=traceback.format_exc())
+ module.fail_json(msg='Could not save JSON payload: %s' % to_native(e), exception=traceback.format_exc())
return fname
diff --git a/lib/ansible/modules/cloud/softlayer/sl_vm.py b/lib/ansible/modules/cloud/softlayer/sl_vm.py
index 4edaf8eea6..58c4a2de53 100644
--- a/lib/ansible/modules/cloud/softlayer/sl_vm.py
+++ b/lib/ansible/modules/cloud/softlayer/sl_vm.py
@@ -1,18 +1,10 @@
#!/usr/bin/python
-# 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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/cloud/univention/udm_dns_record.py b/lib/ansible/modules/cloud/univention/udm_dns_record.py
index 0496144294..916c671ef3 100644
--- a/lib/ansible/modules/cloud/univention/udm_dns_record.py
+++ b/lib/ansible/modules/cloud/univention/udm_dns_record.py
@@ -3,22 +3,11 @@
# Copyright (c) 2016, Adfinis SyGroup AG
# Tobias Rueetschi
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
@@ -82,16 +71,6 @@ EXAMPLES = '''
RETURN = '''# '''
-from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.univention_umc import (
- umc_module_for_add,
- umc_module_for_edit,
- ldap_search,
- base_dn,
- config,
- uldap,
-)
-
HAVE_UNIVENTION = False
try:
from univention.admin.handlers.dns import (
@@ -102,6 +81,16 @@ try:
except ImportError:
pass
+from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils.univention_umc import (
+ umc_module_for_add,
+ umc_module_for_edit,
+ ldap_search,
+ base_dn,
+ config,
+ uldap,
+)
+
def main():
module = AnsibleModule(
diff --git a/lib/ansible/modules/cloud/univention/udm_dns_zone.py b/lib/ansible/modules/cloud/univention/udm_dns_zone.py
index 5be1ef2bd0..d8005948b4 100644
--- a/lib/ansible/modules/cloud/univention/udm_dns_zone.py
+++ b/lib/ansible/modules/cloud/univention/udm_dns_zone.py
@@ -3,22 +3,11 @@
# Copyright (c) 2016, Adfinis SyGroup AG
# Tobias Rueetschi
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/cloud/univention/udm_group.py b/lib/ansible/modules/cloud/univention/udm_group.py
index 1908bd3bf4..44c95cc2a6 100644
--- a/lib/ansible/modules/cloud/univention/udm_group.py
+++ b/lib/ansible/modules/cloud/univention/udm_group.py
@@ -3,22 +3,11 @@
# Copyright (c) 2016, Adfinis SyGroup AG
# Tobias Rueetschi
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/cloud/univention/udm_share.py b/lib/ansible/modules/cloud/univention/udm_share.py
index de84ac3f18..a5643b3a01 100644
--- a/lib/ansible/modules/cloud/univention/udm_share.py
+++ b/lib/ansible/modules/cloud/univention/udm_share.py
@@ -3,22 +3,11 @@
# Copyright (c) 2016, Adfinis SyGroup AG
# Tobias Rueetschi
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/cloud/univention/udm_user.py b/lib/ansible/modules/cloud/univention/udm_user.py
index 8846306212..4af21488e0 100644
--- a/lib/ansible/modules/cloud/univention/udm_user.py
+++ b/lib/ansible/modules/cloud/univention/udm_user.py
@@ -3,22 +3,11 @@
# Copyright (c) 2016, Adfinis SyGroup AG
# Tobias Rueetschi
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
@@ -344,8 +333,10 @@ EXAMPLES = '''
RETURN = '''# '''
-from datetime import date
import crypt
+from datetime import date
+from dateutil.relativedelta import relativedelta
+
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.univention_umc import (
umc_module_for_add,
@@ -353,7 +344,6 @@ from ansible.module_utils.univention_umc import (
ldap_search,
base_dn,
)
-from dateutil.relativedelta import relativedelta
def main():
diff --git a/lib/ansible/modules/remote_management/foreman/foreman.py b/lib/ansible/modules/remote_management/foreman/foreman.py
index 4a6105406d..c24e1f7776 100644
--- a/lib/ansible/modules/remote_management/foreman/foreman.py
+++ b/lib/ansible/modules/remote_management/foreman/foreman.py
@@ -1,21 +1,11 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2016, Eric D Helms
-#
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -71,15 +61,19 @@ EXAMPLES = '''
RETURN = '''# '''
-import datetime
+import traceback
try:
- from nailgun import entities, entity_fields
+ from nailgun import entities
from nailgun.config import ServerConfig
HAS_NAILGUN_PACKAGE = True
except:
HAS_NAILGUN_PACKAGE = False
+from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils._text import to_native
+
+
class NailGun(object):
def __init__(self, server, entities, module):
self._server = server
@@ -144,7 +138,8 @@ def main():
org = entities.Organization(server)
org.search()
except Exception as e:
- module.fail_json(msg="Failed to connect to Foreman server: %s " % e)
+ module.fail_json(msg="Failed to connect to Foreman server: %s " % to_native(e),
+ exception=traceback.format_exc())
if entity == 'organization':
ng.organization(params)
@@ -152,8 +147,6 @@ def main():
else:
module.fail_json(changed=False, result="Unsupported entity supplied")
-# import module snippets
-from ansible.module_utils.basic import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/remote_management/foreman/katello.py b/lib/ansible/modules/remote_management/foreman/katello.py
index b00691141d..3cb48eec6e 100644
--- a/lib/ansible/modules/remote_management/foreman/katello.py
+++ b/lib/ansible/modules/remote_management/foreman/katello.py
@@ -1,21 +1,11 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2016, Eric D Helms
-#
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -139,6 +129,8 @@ EXAMPLES = '''
RETURN = '''# '''
import datetime
+import os
+import traceback
try:
from nailgun import entities, entity_fields, entity_mixins
@@ -147,6 +139,9 @@ try:
except:
HAS_NAILGUN_PACKAGE = False
+from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils._text import to_native
+
class NailGun(object):
def __init__(self, server, entities, module):
@@ -242,13 +237,13 @@ class NailGun(object):
files={'content': content}
)
return True
- except Exception:
- e = get_exception()
+ except Exception as e:
if "Import is the same as existing data" in e.message:
return False
else:
- self._module.fail_json(msg="Manifest import failed with %s" % e)
+ self._module.fail_json(msg="Manifest import failed with %s" % to_native(e),
+ exception=traceback.format_exc())
def product(self, params):
org = self.find_organization(params['organization'])
@@ -519,8 +514,6 @@ def main():
module.exit_json(changed=result, result="%s updated" % entity)
-# import module snippets
-from ansible.module_utils.basic import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/remote_management/hpilo/hpilo_boot.py b/lib/ansible/modules/remote_management/hpilo/hpilo_boot.py
index 9e8797d68a..9e791340c6 100755
--- a/lib/ansible/modules/remote_management/hpilo/hpilo_boot.py
+++ b/lib/ansible/modules/remote_management/hpilo/hpilo_boot.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# Copyright 2012 Dag Wieers
-#
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -113,10 +103,8 @@ RETURN = '''
# Default return values
'''
-
import time
import warnings
-from ansible.module_utils.basic import AnsibleModule
try:
import hpilo
@@ -124,6 +112,8 @@ try:
except ImportError:
HAS_HPILO = False
+from ansible.module_utils.basic import AnsibleModule
+
# Suppress warnings from hpilo
warnings.simplefilter('ignore')
@@ -213,5 +203,6 @@ def main():
module.exit_json(changed=changed, power=power_status, **status)
+
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/remote_management/hpilo/hpilo_facts.py b/lib/ansible/modules/remote_management/hpilo/hpilo_facts.py
index 15f315a5b7..ce42f46181 100755
--- a/lib/ansible/modules/remote_management/hpilo/hpilo_facts.py
+++ b/lib/ansible/modules/remote_management/hpilo/hpilo_facts.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# Copyright 2012 Dag Wieers
-#
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -131,7 +121,6 @@ hw_uuid:
import re
import warnings
-from ansible.module_utils.basic import AnsibleModule
try:
import hpilo
@@ -139,6 +128,8 @@ try:
except ImportError:
HAS_HPILO = False
+from ansible.module_utils.basic import AnsibleModule
+
# Suppress warnings from hpilo
warnings.simplefilter('ignore')
diff --git a/lib/ansible/modules/remote_management/hpilo/hponcfg.py b/lib/ansible/modules/remote_management/hpilo/hponcfg.py
index 9a845cbd1b..09e9d7136a 100644
--- a/lib/ansible/modules/remote_management/hpilo/hponcfg.py
+++ b/lib/ansible/modules/remote_management/hpilo/hponcfg.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2012, Dag Wieers
-#
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -102,5 +92,6 @@ def main():
module.exit_json(changed=changed, stdout=stdout, stderr=stderr)
+
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/remote_management/imc/imc_xml.py b/lib/ansible/modules/remote_management/imc/imc_xml.py
index a6b7581bd7..ae33a2210f 100644
--- a/lib/ansible/modules/remote_management/imc/imc_xml.py
+++ b/lib/ansible/modules/remote_management/imc/imc_xml.py
@@ -1,21 +1,11 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2017, Dag Wieers
+# 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 .
ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'],
@@ -228,15 +218,10 @@ output:
errorDescr="XML PARSING ERROR: Element 'computeRackUnit', attribute 'admin_Power': The attribute 'admin_Power' is not allowed.\n"/>
'''
-
import atexit
import itertools
import os
-from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.pycompat24 import get_exception
-from ansible.module_utils.urls import fetch_url
-
try:
import lxml.etree
HAS_LXML_ETREE = True
@@ -249,6 +234,9 @@ try:
except ImportError:
HAS_XMLJSON_COBRA = False
+from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils.urls import fetch_url
+
def imc_response(module, rawoutput, rawinput=''):
''' Handle IMC returned data '''
diff --git a/lib/ansible/modules/remote_management/ipmi/ipmi_boot.py b/lib/ansible/modules/remote_management/ipmi/ipmi_boot.py
index bde86bbf00..afabb6ce8c 100644
--- a/lib/ansible/modules/remote_management/ipmi/ipmi_boot.py
+++ b/lib/ansible/modules/remote_management/ipmi/ipmi_boot.py
@@ -1,20 +1,12 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -126,7 +118,7 @@ try:
except ImportError:
command = None
-from ansible.module_utils.basic import *
+from ansible.module_utils.basic import AnsibleModule
def main():
diff --git a/lib/ansible/modules/remote_management/ipmi/ipmi_power.py b/lib/ansible/modules/remote_management/ipmi/ipmi_power.py
index cc71e00f40..1ff19a8d39 100644
--- a/lib/ansible/modules/remote_management/ipmi/ipmi_power.py
+++ b/lib/ansible/modules/remote_management/ipmi/ipmi_power.py
@@ -1,20 +1,12 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -90,7 +82,7 @@ try:
except ImportError:
command = None
-from ansible.module_utils.basic import *
+from ansible.module_utils.basic import AnsibleModule
def main():
diff --git a/lib/ansible/modules/remote_management/stacki/stacki_host.py b/lib/ansible/modules/remote_management/stacki/stacki_host.py
index 1b74628fab..ab287702d6 100644
--- a/lib/ansible/modules/remote_management/stacki/stacki_host.py
+++ b/lib/ansible/modules/remote_management/stacki/stacki_host.py
@@ -2,19 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2016, Hugh Ma
-#
-# 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
-# the Free Software Foundation, either version 3 of the License, or
-# (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 .
+# 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.0',
'status': ['preview'],
@@ -110,12 +102,10 @@ stdout_lines:
import json
import os
-import re
-import tempfile
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six.moves.urllib.parse import urlencode
-from ansible.module_utils.urls import fetch_url, ConnectionError
+from ansible.module_utils.urls import fetch_url
class StackiHost(object):
@@ -194,10 +184,10 @@ class StackiHost(object):
def stack_sync(self):
- res = self.do_request(self.module, self.endpoint, payload=json.dumps({ "cmd": "sync config"}),
+ self.do_request(self.module, self.endpoint, payload=json.dumps({ "cmd": "sync config"}),
headers=self.header, method="POST")
- res = self.do_request(self.module, self.endpoint, payload=json.dumps({"cmd": "sync host config"}),
+ self.do_request(self.module, self.endpoint, payload=json.dumps({"cmd": "sync host config"}),
headers=self.header, method="POST")
@@ -208,7 +198,7 @@ class StackiHost(object):
data['cmd'] = "set host boot {0} action=install" \
.format(self.hostname)
- res = self.do_request(self.module, self.endpoint, payload=json.dumps(data),
+ self.do_request(self.module, self.endpoint, payload=json.dumps(data),
headers=self.header, method="POST")
changed = True
@@ -224,7 +214,7 @@ class StackiHost(object):
data['cmd'] = "add host {0} rack={1} rank={2} appliance={3}"\
.format(self.hostname, self.rack, self.rank, self.appliance)
- res = self.do_request(self.module, self.endpoint, payload=json.dumps(data),
+ self.do_request(self.module, self.endpoint, payload=json.dumps(data),
headers=self.header, method="POST")
self.stack_sync()
@@ -239,7 +229,7 @@ class StackiHost(object):
data['cmd'] = "remove host {0}"\
.format(self.hostname)
- res = self.do_request(self.module, self.endpoint, payload=json.dumps(data),
+ self.do_request(self.module, self.endpoint, payload=json.dumps(data),
headers=self.header, method="POST")
self.stack_sync()
diff --git a/lib/ansible/modules/remote_management/wakeonlan.py b/lib/ansible/modules/remote_management/wakeonlan.py
index fcc045ff35..d2e7f4124d 100644
--- a/lib/ansible/modules/remote_management/wakeonlan.py
+++ b/lib/ansible/modules/remote_management/wakeonlan.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2016, Dag Wieers
-#
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -70,11 +60,12 @@ EXAMPLES = r'''
RETURN = r'''
# Default return values
'''
-
-from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.pycompat24 import get_exception
import socket
import struct
+import traceback
+
+from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils._text import to_native
def wakeonlan(module, mac, broadcast, port):
@@ -110,10 +101,9 @@ def wakeonlan(module, mac, broadcast, port):
try:
sock.sendto(data, (broadcast, port))
- except socket.error:
- e = get_exception()
+ except socket.error as e:
sock.close()
- module.fail_json(msg=str(e))
+ module.fail_json(msg=to_native(e), exception=traceback.format_exc())
sock.close()
diff --git a/lib/ansible/modules/storage/infinidat/infini_export.py b/lib/ansible/modules/storage/infinidat/infini_export.py
index 5d7e43982b..f025c9370b 100644
--- a/lib/ansible/modules/storage/infinidat/infini_export.py
+++ b/lib/ansible/modules/storage/infinidat/infini_export.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2016, Gregory Shulov (gregory.shulov@gmail.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 .
+# 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.0',
'status': ['preview'],
@@ -59,6 +49,8 @@ options:
required: true
extends_documentation_fragment:
- infinibox
+requirements:
+ - munch
'''
EXAMPLES = '''
@@ -91,15 +83,14 @@ EXAMPLES = '''
RETURN = '''
'''
-
-HAS_INFINISDK = True
try:
- from infinisdk import InfiniBox, core
+ from munch import unmunchify
+ HAS_MUNCH = True
except ImportError:
- HAS_INFINISDK = False
+ HAS_MUNCH = False
-from ansible.module_utils.infinibox import *
-from munch import unmunchify
+from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils.infinibox import HAS_INFINISDK, api_wrapper, get_system, infinibox_argument_spec
def transform(d):
@@ -178,6 +169,8 @@ def main():
if not HAS_INFINISDK:
module.fail_json(msg='infinisdk is required for this module')
+ if not HAS_MUNCH:
+ module.fail_json(msg='the python munch library is required for this module')
state = module.params['state']
system = get_system(module)
@@ -195,7 +188,5 @@ def main():
module.exit_json(changed=False)
-# Import Ansible Utilities
-from ansible.module_utils.basic import AnsibleModule
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/storage/infinidat/infini_export_client.py b/lib/ansible/modules/storage/infinidat/infini_export_client.py
index 721c08f927..9e1b7c7d09 100644
--- a/lib/ansible/modules/storage/infinidat/infini_export_client.py
+++ b/lib/ansible/modules/storage/infinidat/infini_export_client.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2016, Gregory Shulov (gregory.shulov@gmail.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 .
+# 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.0',
'status': ['preview'],
@@ -62,6 +52,8 @@ options:
required: true
extends_documentation_fragment:
- infinibox
+requirements:
+ - munch
'''
EXAMPLES = '''
@@ -92,14 +84,14 @@ EXAMPLES = '''
RETURN = '''
'''
-HAS_INFINISDK = True
try:
- from infinisdk import InfiniBox, core
+ from munch import Munch, unmunchify
+ HAS_MUNCH = True
except ImportError:
- HAS_INFINISDK = False
+ HAS_MUNCH = False
-from ansible.module_utils.infinibox import *
-from munch import Munch, unmunchify
+from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils.infinibox import HAS_INFINISDK, api_wrapper, get_system, infinibox_argument_spec
def transform(d):
@@ -195,6 +187,8 @@ def main():
if not HAS_INFINISDK:
module.fail_json(msg='infinisdk is required for this module')
+ if not HAS_MUNCH:
+ module.fail_json(msg='the python munch library is required for this module')
system = get_system(module)
export = get_export(module, system)
@@ -204,7 +198,6 @@ def main():
else:
delete_client(module, export)
-# Import Ansible Utilities
-from ansible.module_utils.basic import AnsibleModule
+
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/storage/infinidat/infini_fs.py b/lib/ansible/modules/storage/infinidat/infini_fs.py
index 258938cfd9..b79e890e10 100644
--- a/lib/ansible/modules/storage/infinidat/infini_fs.py
+++ b/lib/ansible/modules/storage/infinidat/infini_fs.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2016, Gregory Shulov (gregory.shulov@gmail.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 .
+# 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.0',
'status': ['preview'],
@@ -52,6 +42,8 @@ options:
required: true
extends_documentation_fragment:
- infinibox
+requirements:
+ - capacity
'''
EXAMPLES = '''
@@ -69,14 +61,14 @@ EXAMPLES = '''
RETURN = '''
'''
-HAS_INFINISDK = True
try:
- from infinisdk import InfiniBox, core
+ from capacity import KiB, Capacity
+ HAS_CAPACITY = True
except ImportError:
- HAS_INFINISDK = False
+ HAS_CAPACITY = False
-from ansible.module_utils.infinibox import *
-from capacity import KiB, Capacity
+from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils.infinibox import HAS_INFINISDK, api_wrapper, get_system, infinibox_argument_spec
@api_wrapper
@@ -145,6 +137,8 @@ def main():
if not HAS_INFINISDK:
module.fail_json(msg='infinisdk is required for this module')
+ if not HAS_CAPACITY:
+ module.fail_json(msg='The capacity python library is required for this module')
if module.params['size']:
try:
@@ -170,7 +164,5 @@ def main():
module.exit_json(changed=False)
-# Import Ansible Utilities
-from ansible.module_utils.basic import AnsibleModule
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/storage/infinidat/infini_host.py b/lib/ansible/modules/storage/infinidat/infini_host.py
index 844ec6bc95..f252059f20 100644
--- a/lib/ansible/modules/storage/infinidat/infini_host.py
+++ b/lib/ansible/modules/storage/infinidat/infini_host.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2016, Gregory Shulov (gregory.shulov@gmail.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 .
+# 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.0',
'status': ['preview'],
@@ -84,14 +74,8 @@ EXAMPLES = '''
RETURN = '''
'''
-HAS_INFINISDK = True
-try:
- from infinisdk import InfiniBox, core
-except ImportError:
- HAS_INFINISDK = False
-
-from ansible.module_utils.infinibox import *
-from collections import Counter
+from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils.infinibox import HAS_INFINISDK, api_wrapper, get_system, infinibox_argument_spec
@api_wrapper
@@ -125,7 +109,6 @@ def create_host(module, system):
@api_wrapper
def update_host(module, host):
changed = False
- name = module.params['name']
module.exit_json(changed=changed)
@@ -173,7 +156,5 @@ def main():
create_host(module, system)
-# Import Ansible Utilities
-from ansible.module_utils.basic import AnsibleModule
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/storage/infinidat/infini_pool.py b/lib/ansible/modules/storage/infinidat/infini_pool.py
index adbf1ff459..91b86c955d 100644
--- a/lib/ansible/modules/storage/infinidat/infini_pool.py
+++ b/lib/ansible/modules/storage/infinidat/infini_pool.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2016, Gregory Shulov (gregory.shulov@gmail.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 .
+# 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.0',
'status': ['preview'],
@@ -64,6 +54,8 @@ notes:
- Infinibox Admin level access is required for pool modifications
extends_documentation_fragment:
- infinibox
+requirements:
+ - capacity
'''
EXAMPLES = '''
@@ -88,14 +80,14 @@ EXAMPLES = '''
RETURN = '''
'''
-HAS_INFINISDK = True
try:
- from infinisdk import InfiniBox, core
+ from capacity import KiB, Capacity
+ HAS_CAPACITY = True
except ImportError:
- HAS_INFINISDK = False
+ HAS_CAPACITY = False
-from ansible.module_utils.infinibox import *
-from capacity import KiB, Capacity
+from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils.infinibox import HAS_INFINISDK, api_wrapper, get_system, infinibox_argument_spec
@api_wrapper
@@ -187,6 +179,8 @@ def main():
if not HAS_INFINISDK:
module.fail_json(msg='infinisdk is required for this module')
+ if not HAS_CAPACITY:
+ module.fail_json(msg='The capacity python library is required for this module')
if module.params['size']:
try:
@@ -214,7 +208,5 @@ def main():
module.exit_json(changed=False)
-# Import Ansible Utilities
-from ansible.module_utils.basic import AnsibleModule
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/storage/infinidat/infini_vol.py b/lib/ansible/modules/storage/infinidat/infini_vol.py
index 759d87cd5c..7625cade85 100644
--- a/lib/ansible/modules/storage/infinidat/infini_vol.py
+++ b/lib/ansible/modules/storage/infinidat/infini_vol.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2016, Gregory Shulov (gregory.shulov@gmail.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 .
+# 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.0',
'status': ['preview'],
@@ -52,6 +42,8 @@ options:
required: true
extends_documentation_fragment:
- infinibox
+requirements:
+ - capacity
'''
EXAMPLES = '''
@@ -69,14 +61,14 @@ EXAMPLES = '''
RETURN = '''
'''
-HAS_INFINISDK = True
try:
- from infinisdk import InfiniBox, core
+ from capacity import KiB, Capacity
+ HAS_CAPACITY = True
except ImportError:
- HAS_INFINISDK = False
+ HAS_CAPACITY = False
-from ansible.module_utils.infinibox import *
-from capacity import KiB, Capacity
+from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils.infinibox import HAS_INFINISDK, api_wrapper, get_system, infinibox_argument_spec
@api_wrapper
@@ -170,7 +162,5 @@ def main():
module.exit_json(changed=False)
-# Import Ansible Utilities
-from ansible.module_utils.basic import AnsibleModule
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/storage/netapp/na_cdot_aggregate.py b/lib/ansible/modules/storage/netapp/na_cdot_aggregate.py
index 34eeff90b8..82acb5b813 100644
--- a/lib/ansible/modules/storage/netapp/na_cdot_aggregate.py
+++ b/lib/ansible/modules/storage/netapp/na_cdot_aggregate.py
@@ -1,22 +1,12 @@
#!/usr/bin/python
# (c) 2017, NetApp, Inc
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
@@ -80,9 +70,10 @@ EXAMPLES = """
RETURN = """
"""
+import traceback
from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.pycompat24 import get_exception
+from ansible.module_utils._text import to_native
import ansible.module_utils.netapp as netapp_utils
@@ -140,13 +131,12 @@ class NetAppCDOTAggregate(object):
try:
result = self.server.invoke_successfully(aggr_get_iter,
enable_tunneling=False)
- except netapp_utils.zapi.NaApiError:
+ except netapp_utils.zapi.NaApiError as e:
# Error 13040 denotes an aggregate not being found.
- e = get_exception()
- if str(e.code) == "13040":
+ if to_native(e.code) == "13040":
return False
else:
- self.module.fail_json(exception=str(e))
+ self.module.fail_json(msg=to_native(e), exception=traceback.format_exc())
if (result.get_child_by_name('num-records') and
int(result.get_child_content('num-records')) >= 1):
@@ -162,10 +152,9 @@ class NetAppCDOTAggregate(object):
try:
self.server.invoke_successfully(aggr_create,
enable_tunneling=False)
- except netapp_utils.zapi.NaApiError:
- err = get_exception()
- self.module.fail_json(msg="Error provisioning aggregate %s." % self.name,
- exception=str(err))
+ except netapp_utils.zapi.NaApiError as e:
+ self.module.fail_json(msg="Error provisioning aggregate %s: %s" % (self.name, to_native(e)),
+ exception=traceback.format_exc())
def delete_aggr(self):
aggr_destroy = netapp_utils.zapi.NaElement.create_node_with_children(
@@ -174,10 +163,9 @@ class NetAppCDOTAggregate(object):
try:
self.server.invoke_successfully(aggr_destroy,
enable_tunneling=False)
- except netapp_utils.zapi.NaApiError:
- err = get_exception()
- self.module.fail_json(msg="Error removing aggregate %s." % self.name,
- exception=str(err))
+ except netapp_utils.zapi.NaApiError as e:
+ self.module.fail_json(msg="Error removing aggregate %s: %s" % (self.name, to_native(e)),
+ exception=traceback.format_exc())
def rename_aggregate(self):
aggr_rename = netapp_utils.zapi.NaElement.create_node_with_children(
@@ -188,10 +176,9 @@ class NetAppCDOTAggregate(object):
try:
self.server.invoke_successfully(aggr_rename,
enable_tunneling=False)
- except netapp_utils.zapi.NaApiError:
- err = get_exception()
- self.module.fail_json(msg="Error renaming aggregate %s." % self.name,
- exception=str(err))
+ except netapp_utils.zapi.NaApiError as e:
+ self.module.fail_json(msg="Error renaming aggregate %s: %s" % (self.name, to_native(e)),
+ exception=traceback.format_exc())
def apply(self):
changed = False
@@ -237,5 +224,6 @@ def main():
v = NetAppCDOTAggregate()
v.apply()
+
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/storage/netapp/na_cdot_license.py b/lib/ansible/modules/storage/netapp/na_cdot_license.py
index bb7c984755..31c6f894a6 100644
--- a/lib/ansible/modules/storage/netapp/na_cdot_license.py
+++ b/lib/ansible/modules/storage/netapp/na_cdot_license.py
@@ -1,22 +1,12 @@
#!/usr/bin/python
# (c) 2017, NetApp, Inc
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
@@ -135,11 +125,13 @@ EXAMPLES = """
RETURN = """
"""
+import traceback
from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.pycompat24 import get_exception
+from ansible.module_utils._text import to_native
import ansible.module_utils.netapp as netapp_utils
+
HAS_NETAPP_LIB = netapp_utils.has_netapp_lib()
@@ -184,10 +176,9 @@ class NetAppCDOTLicense(object):
try:
result = self.server.invoke_successfully(license_status,
enable_tunneling=False)
- except netapp_utils.zapi.NaApiError:
- err = get_exception()
- self.module.fail_json(msg="Error checking license status",
- exception=str(err))
+ except netapp_utils.zapi.NaApiError as e:
+ self.module.fail_json(msg="Error checking license status: %s" %
+ to_native(e), exception=traceback.format_exc())
return_dictionary = {}
license_v2_status = result.get_child_by_name('license-v2-status')
@@ -216,10 +207,9 @@ class NetAppCDOTLicense(object):
try:
self.server.invoke_successfully(license_delete,
enable_tunneling=False)
- except netapp_utils.zapi.NaApiError:
- err = get_exception()
- self.module.fail_json(msg="Error removing license",
- exception=str(err))
+ except netapp_utils.zapi.NaApiError as e:
+ self.module.fail_json(msg="Error removing license %s" %
+ to_native(e), exception=traceback.format_exc())
def remove_unused_licenses(self):
"""
@@ -229,10 +219,9 @@ class NetAppCDOTLicense(object):
try:
self.server.invoke_successfully(remove_unused,
enable_tunneling=False)
- except netapp_utils.zapi.NaApiError:
- err = get_exception()
- self.module.fail_json(msg="Error removing unused licenses",
- exception=str(err))
+ except netapp_utils.zapi.NaApiError as e:
+ self.module.fail_json(msg="Error removing unused licenses: %s" %
+ to_native(e), exception=traceback.format_exc())
def remove_expired_licenses(self):
"""
@@ -242,10 +231,9 @@ class NetAppCDOTLicense(object):
try:
self.server.invoke_successfully(remove_expired,
enable_tunneling=False)
- except netapp_utils.zapi.NaApiError:
- err = get_exception()
- self.module.fail_json(msg="Error removing expired licenses",
- exception=str(err))
+ except netapp_utils.zapi.NaApiError as e:
+ self.module.fail_json(msg="Error removing expired licenses: %s" %
+ to_native(e), exception=traceback.format_exc())
def update_licenses(self):
"""
@@ -281,10 +269,9 @@ class NetAppCDOTLicense(object):
try:
self.server.invoke_successfully(license_add,
enable_tunneling=False)
- except netapp_utils.zapi.NaApiError:
- err = get_exception()
- self.module.fail_json(msg="Error adding licenses",
- exception=str(err))
+ except netapp_utils.zapi.NaApiError as e:
+ self.module.fail_json(msg="Error adding licenses: %s" %
+ to_native(e), exception=traceback.format_exc())
def apply(self):
changed = False
diff --git a/lib/ansible/modules/storage/netapp/na_cdot_lun.py b/lib/ansible/modules/storage/netapp/na_cdot_lun.py
index 6d96fd1f32..aeae83d910 100644
--- a/lib/ansible/modules/storage/netapp/na_cdot_lun.py
+++ b/lib/ansible/modules/storage/netapp/na_cdot_lun.py
@@ -1,22 +1,12 @@
#!/usr/bin/python
# (c) 2017, NetApp, Inc
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
@@ -119,9 +109,10 @@ EXAMPLES = """
RETURN = """
"""
+import traceback
from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.pycompat24 import get_exception
+from ansible.module_utils._text import to_native
import ansible.module_utils.netapp as netapp_utils
HAS_NETAPP_LIB = netapp_utils.has_netapp_lib()
@@ -273,10 +264,9 @@ class NetAppCDOTLUN(object):
try:
self.server.invoke_successfully(lun_create, enable_tunneling=True)
- except netapp_utils.zapi.NaApiError:
- err = get_exception()
- self.module.fail_json(msg="Error provisioning lun %s of size %s" % (self.name, self.size),
- exception=str(err))
+ except netapp_utils.zapi.NaApiError as e:
+ self.module.fail_json(msg="Error provisioning lun %s of size %s: %s" % (self.name, self.size, to_native(e)),
+ exception=traceback.format_exc())
def delete_lun(self):
"""
@@ -292,10 +282,9 @@ class NetAppCDOTLUN(object):
try:
self.server.invoke_successfully(lun_delete, enable_tunneling=True)
- except netapp_utils.zapi.NaApiError:
- err = get_exception()
- self.module.fail_json(msg="Error deleting lun %s" % path,
- exception=str(err))
+ except netapp_utils.zapi.NaApiError as e:
+ self.module.fail_json(msg="Error deleting lun %s: %s" % (path, to_native(e)),
+ exception=traceback.format_exc())
def resize_lun(self):
"""
@@ -312,9 +301,8 @@ class NetAppCDOTLUN(object):
'force': str(self.force_resize)})
try:
self.server.invoke_successfully(lun_resize, enable_tunneling=True)
- except netapp_utils.zapi.NaApiError:
- e = get_exception()
- if str(e.code) == "9042":
+ except netapp_utils.zapi.NaApiError as e:
+ if to_native(e.code) == "9042":
# Error 9042 denotes the new LUN size being the same as the
# old LUN size. This happens when there's barely any difference
# in the two sizes. For example, from 8388608 bytes to
@@ -323,9 +311,8 @@ class NetAppCDOTLUN(object):
# larger unit (MB/GB/TB).
return False
else:
- err = get_exception()
- self.module.fail_json(msg="Error resizing lun %s" % path,
- exception=str(err))
+ self.module.fail_json(msg="Error resizing lun %s: %s" % (path, to_native(e)),
+ exception=traceback.format_exc())
return True
@@ -381,5 +368,6 @@ def main():
v = NetAppCDOTLUN()
v.apply()
+
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/storage/netapp/na_cdot_qtree.py b/lib/ansible/modules/storage/netapp/na_cdot_qtree.py
index dbd8c606f2..2ef0a93649 100644
--- a/lib/ansible/modules/storage/netapp/na_cdot_qtree.py
+++ b/lib/ansible/modules/storage/netapp/na_cdot_qtree.py
@@ -1,22 +1,12 @@
#!/usr/bin/python
# (c) 2017, NetApp, Inc
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
@@ -84,11 +74,13 @@ EXAMPLES = """
RETURN = """
"""
+import traceback
from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.pycompat24 import get_exception
+from ansible.module_utils._text import to_native
import ansible.module_utils.netapp as netapp_utils
+
HAS_NETAPP_LIB = netapp_utils.has_netapp_lib()
@@ -161,10 +153,9 @@ class NetAppCDOTQTree(object):
try:
self.server.invoke_successfully(qtree_create,
enable_tunneling=True)
- except netapp_utils.zapi.NaApiError:
- err = get_exception()
- self.module.fail_json(msg="Error provisioning qtree %s." % self.name,
- exception=str(err))
+ except netapp_utils.zapi.NaApiError as e:
+ self.module.fail_json(msg="Error provisioning qtree %s: %s" % (self.name, to_native(e)),
+ exception=traceback.format_exc())
def delete_qtree(self):
path = '/vol/%s/%s' % (self.flexvol_name, self.name)
@@ -174,10 +165,9 @@ class NetAppCDOTQTree(object):
try:
self.server.invoke_successfully(qtree_delete,
enable_tunneling=True)
- except netapp_utils.zapi.NaApiError:
- err = get_exception()
- self.module.fail_json(msg="Error deleting qtree %s." % path,
- exception=str(err))
+ except netapp_utils.zapi.NaApiError as e:
+ self.module.fail_json(msg="Error deleting qtree %s: %s" % (path, to_native(e)),
+ exception=traceback.format_exc())
def rename_qtree(self):
path = '/vol/%s/%s' % (self.flexvol_name, self.name)
@@ -189,10 +179,9 @@ class NetAppCDOTQTree(object):
try:
self.server.invoke_successfully(qtree_rename,
enable_tunneling=True)
- except netapp_utils.zapi.NaApiError:
- err = get_exception()
- self.module.fail_json(msg="Error renaming qtree %s." % self.name,
- exception=str(err))
+ except netapp_utils.zapi.NaApiError as e:
+ self.module.fail_json(msg="Error renaming qtree %s: %s" % (self.name, to_native(e)),
+ exception=traceback.format_exc())
def apply(self):
changed = False
@@ -240,5 +229,6 @@ def main():
v = NetAppCDOTQTree()
v.apply()
+
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/storage/netapp/na_cdot_svm.py b/lib/ansible/modules/storage/netapp/na_cdot_svm.py
index ef462dd10e..84c4949942 100644
--- a/lib/ansible/modules/storage/netapp/na_cdot_svm.py
+++ b/lib/ansible/modules/storage/netapp/na_cdot_svm.py
@@ -1,22 +1,12 @@
#!/usr/bin/python
# (c) 2017, NetApp, Inc
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
@@ -88,11 +78,13 @@ EXAMPLES = """
RETURN = """
"""
+import traceback
from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.pycompat24 import get_exception
+from ansible.module_utils._text import to_native
import ansible.module_utils.netapp as netapp_utils
+
HAS_NETAPP_LIB = netapp_utils.has_netapp_lib()
@@ -182,11 +174,10 @@ class NetAppCDOTSVM(object):
try:
self.server.invoke_successfully(vserver_create,
enable_tunneling=False)
- except netapp_utils.zapi.NaApiError:
- err = get_exception()
- self.module.fail_json(msg='Error provisioning SVM %s with root volume %s on aggregate %s'
- % (self.name, self.root_volume, self.root_volume_aggregate),
- exception=str(err))
+ except netapp_utils.zapi.NaApiError as e:
+ self.module.fail_json(msg='Error provisioning SVM %s with root volume %s on aggregate %s: %s'
+ % (self.name, self.root_volume, self.root_volume_aggregate, to_native(e)),
+ exception=traceback.format_exc())
def delete_vserver(self):
vserver_delete = netapp_utils.zapi.NaElement.create_node_with_children(
@@ -195,11 +186,10 @@ class NetAppCDOTSVM(object):
try:
self.server.invoke_successfully(vserver_delete,
enable_tunneling=False)
- except netapp_utils.zapi.NaApiError:
- err = get_exception()
- self.module.fail_json(msg='Error deleting SVM %s with root volume %s on aggregate %s'
- % (self.name, self.root_volume, self.root_volume_aggregate),
- exception=str(err))
+ except netapp_utils.zapi.NaApiError as e:
+ self.module.fail_json(msg='Error deleting SVM %s with root volume %s on aggregate %s: %s'
+ % (self.name, self.root_volume, self.root_volume_aggregate, to_native(e)),
+ exception=traceback.format_exc())
def rename_vserver(self):
vserver_rename = netapp_utils.zapi.NaElement.create_node_with_children(
@@ -209,9 +199,9 @@ class NetAppCDOTSVM(object):
try:
self.server.invoke_successfully(vserver_rename,
enable_tunneling=False)
- except netapp_utils.zapi.NaApiError:
- err = get_exception()
- self.module.fail_json(msg='Error renaming SVM %s' % self.name, exception=str(err))
+ except netapp_utils.zapi.NaApiError as e:
+ self.module.fail_json(msg='Error renaming SVM %s: %s' % (self.name, to_native(e)),
+ exception=traceback.format_exc())
def apply(self):
changed = False
diff --git a/lib/ansible/modules/storage/netapp/na_cdot_user.py b/lib/ansible/modules/storage/netapp/na_cdot_user.py
index b8bd254e04..c782f0cf8e 100644
--- a/lib/ansible/modules/storage/netapp/na_cdot_user.py
+++ b/lib/ansible/modules/storage/netapp/na_cdot_user.py
@@ -1,22 +1,12 @@
#!/usr/bin/python
# (c) 2017, NetApp, Inc
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
@@ -110,11 +100,13 @@ EXAMPLES = """
RETURN = """
"""
+import traceback
from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.pycompat24 import get_exception
+from ansible.module_utils._text import to_native
import ansible.module_utils.netapp as netapp_utils
+
HAS_NETAPP_LIB = netapp_utils.has_netapp_lib()
@@ -199,13 +191,13 @@ class NetAppCDOTUser(object):
else:
return False
- except netapp_utils.zapi.NaApiError:
- e = get_exception()
+ except netapp_utils.zapi.NaApiError as e:
# Error 16034 denotes a user not being found.
- if str(e.code) == "16034":
+ if to_native(e.code) == "16034":
return False
else:
- self.module.fail_json(msg='Error getting user %s' % self.name, exception=str(e))
+ self.module.fail_json(msg='Error getting user %s: %s' % (self.name, to_native(e)),
+ exception=traceback.format_exc())
def create_user(self):
user_create = netapp_utils.zapi.NaElement.create_node_with_children(
@@ -221,9 +213,9 @@ class NetAppCDOTUser(object):
try:
self.server.invoke_successfully(user_create,
enable_tunneling=False)
- except netapp_utils.zapi.NaApiError:
- err = get_exception()
- self.module.fail_json(msg='Error creating user %s' % self.name, exception=str(err))
+ except netapp_utils.zapi.NaApiError as e:
+ self.module.fail_json(msg='Error creating user %s: %s' % (self.name, to_native(e)),
+ exception=traceback.format_exc())
def delete_user(self):
user_delete = netapp_utils.zapi.NaElement.create_node_with_children(
@@ -236,9 +228,9 @@ class NetAppCDOTUser(object):
try:
self.server.invoke_successfully(user_delete,
enable_tunneling=False)
- except netapp_utils.zapi.NaApiError:
- err = get_exception()
- self.module.fail_json(msg='Error removing user %s' % self.name, exception=str(err))
+ except netapp_utils.zapi.NaApiError as e:
+ self.module.fail_json(msg='Error removing user %s: %s' % (self.name, to_native(e)),
+ exception=traceback.format_exc())
def change_password(self):
"""
@@ -257,13 +249,12 @@ class NetAppCDOTUser(object):
try:
self.server.invoke_successfully(modify_password,
enable_tunneling=True)
- except netapp_utils.zapi.NaApiError:
- e = get_exception()
- if str(e.code) == '13114':
+ except netapp_utils.zapi.NaApiError as e:
+ if to_native(e.code) == '13114':
return False
else:
- err = get_exception()
- self.module.fail_json(msg='Error setting password for user %s' % self.name, exception=str(err))
+ self.module.fail_json(msg='Error setting password for user %s: %s' % (self.name, to_native(e)),
+ exception=traceback.format_exc())
self.server.set_vserver(None)
return True
diff --git a/lib/ansible/modules/storage/netapp/na_cdot_user_role.py b/lib/ansible/modules/storage/netapp/na_cdot_user_role.py
index 5adcc361ed..0c0319615a 100644
--- a/lib/ansible/modules/storage/netapp/na_cdot_user_role.py
+++ b/lib/ansible/modules/storage/netapp/na_cdot_user_role.py
@@ -1,22 +1,12 @@
#!/usr/bin/python
# (c) 2017, NetApp, Inc
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
@@ -84,11 +74,13 @@ EXAMPLES = """
RETURN = """
"""
+import traceback
from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.pycompat24 import get_exception
+from ansible.module_utils._text import to_native
import ansible.module_utils.netapp as netapp_utils
+
HAS_NETAPP_LIB = netapp_utils.has_netapp_lib()
@@ -153,13 +145,13 @@ class NetAppCDOTUserRole(object):
try:
result = self.server.invoke_successfully(
security_login_role_get_iter, enable_tunneling=False)
- except netapp_utils.zapi.NaApiError:
- e = get_exception()
+ except netapp_utils.zapi.NaApiError as e:
# Error 16031 denotes a role not being found.
- if str(e.code) == "16031":
+ if to_native(e.code) == "16031":
return False
else:
- self.module.fail_json(msg='Error getting role %s' % self.name, exception=str(e))
+ self.module.fail_json(msg='Error getting role %s: %s' % (self.name, to_native(e)),
+ exception=traceback.format_exc())
if (result.get_child_by_name('num-records') and
int(result.get_child_content('num-records')) >= 1):
@@ -179,9 +171,9 @@ class NetAppCDOTUserRole(object):
try:
self.server.invoke_successfully(role_create,
enable_tunneling=False)
- except netapp_utils.zapi.NaApiError:
- err = get_exception()
- self.module.fail_json(msg='Error creating role %s' % self.name, exception=str(err))
+ except netapp_utils.zapi.NaApiError as e:
+ self.module.fail_json(msg='Error creating role %s: %s' % (self.name, to_native(e)),
+ exception=traceback.format_exc())
def delete_role(self):
role_delete = netapp_utils.zapi.NaElement.create_node_with_children(
@@ -193,9 +185,9 @@ class NetAppCDOTUserRole(object):
try:
self.server.invoke_successfully(role_delete,
enable_tunneling=False)
- except netapp_utils.zapi.NaApiError:
- err = get_exception()
- self.module.fail_json(msg='Error removing role %s' % self.name, exception=str(err))
+ except netapp_utils.zapi.NaApiError as e:
+ self.module.fail_json(msg='Error removing role %s: %s' % (self.name, to_native(e)),
+ exception=traceback.format_exc())
def apply(self):
changed = False
diff --git a/lib/ansible/modules/storage/netapp/na_cdot_volume.py b/lib/ansible/modules/storage/netapp/na_cdot_volume.py
index bb655b3938..42f856759e 100644
--- a/lib/ansible/modules/storage/netapp/na_cdot_volume.py
+++ b/lib/ansible/modules/storage/netapp/na_cdot_volume.py
@@ -1,22 +1,12 @@
#!/usr/bin/python
# (c) 2017, NetApp, Inc
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
@@ -114,11 +104,13 @@ RETURN = """
"""
+import traceback
from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.pycompat24 import get_exception
+from ansible.module_utils._text import to_native
import ansible.module_utils.netapp as netapp_utils
+
HAS_NETAPP_LIB = netapp_utils.has_netapp_lib()
@@ -243,10 +235,9 @@ class NetAppCDOTVolume(object):
try:
self.server.invoke_successfully(volume_create,
enable_tunneling=True)
- except netapp_utils.zapi.NaApiError:
- err = get_exception()
- self.module.fail_json(msg='Error provisioning volume %s of size %s' % (self.name, self.size),
- exception=str(err))
+ except netapp_utils.zapi.NaApiError as e:
+ self.module.fail_json(msg='Error provisioning volume %s of size %s: %s' % (self.name, self.size, to_native(e)),
+ exception=traceback.format_exc())
def delete_volume(self):
if self.is_infinite:
@@ -260,10 +251,9 @@ class NetAppCDOTVolume(object):
try:
self.server.invoke_successfully(volume_delete,
enable_tunneling=True)
- except netapp_utils.zapi.NaApiError:
- err = get_exception()
- self.module.fail_json(msg='Error deleting volume %s' % self.name,
- exception=str(err))
+ except netapp_utils.zapi.NaApiError as e:
+ self.module.fail_json(msg='Error deleting volume %s: %s' % (self.name, to_native(e)),
+ exception=traceback.format_exc())
def rename_volume(self):
"""
@@ -284,10 +274,9 @@ class NetAppCDOTVolume(object):
try:
self.server.invoke_successfully(volume_rename,
enable_tunneling=True)
- except netapp_utils.zapi.NaApiError:
- err = get_exception()
- self.module.fail_json(msg='Error renaming volume %s' % self.name,
- exception=str(err))
+ except netapp_utils.zapi.NaApiError as e:
+ self.module.fail_json(msg='Error renaming volume %s: %s' % (self.name, to_native(e)),
+ exception=traceback.format_exc())
def resize_volume(self):
"""
@@ -308,10 +297,9 @@ class NetAppCDOTVolume(object):
try:
self.server.invoke_successfully(volume_resize,
enable_tunneling=True)
- except netapp_utils.zapi.NaApiError:
- err = get_exception()
- self.module.fail_json(msg='Error re-sizing volume %s' % self.name,
- exception=str(err))
+ except netapp_utils.zapi.NaApiError as e:
+ self.module.fail_json(msg='Error re-sizing volume %s: %s' % (self.name, to_native(e)),
+ exception=traceback.format_exc())
def change_volume_state(self):
"""
@@ -346,10 +334,10 @@ class NetAppCDOTVolume(object):
try:
self.server.invoke_successfully(volume_change_state,
enable_tunneling=True)
- except netapp_utils.zapi.NaApiError:
- err = get_exception()
- self.module.fail_json(msg='Error changing the state of volume %s to %s' % (self.name, state_requested),
- exception=str(err))
+ except netapp_utils.zapi.NaApiError as e:
+ self.module.fail_json(msg='Error changing the state of volume %s to %s: %s' %
+ (self.name, state_requested, to_native(e)),
+ exception=traceback.format_exc())
def apply(self):
changed = False
diff --git a/lib/ansible/modules/storage/netapp/netapp_e_amg.py b/lib/ansible/modules/storage/netapp/netapp_e_amg.py
index 3ba5495c3f..adb1e18119 100644
--- a/lib/ansible/modules/storage/netapp/netapp_e_amg.py
+++ b/lib/ansible/modules/storage/netapp/netapp_e_amg.py
@@ -1,21 +1,11 @@
#!/usr/bin/python
# (c) 2016, NetApp, Inc
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
@@ -122,15 +112,19 @@ msg:
""" # NOQA
import json
+import traceback
-from ansible.module_utils.basic import AnsibleModule, get_exception
+from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils._text import to_native
from ansible.module_utils.netapp import request, eseries_host_argument_spec
+
HEADERS = {
"Content-Type": "application/json",
"Accept": "application/json",
}
+
def has_match(module, ssid, api_url, api_pwd, api_usr, body):
compare_keys = ['syncIntervalMinutes', 'syncWarnThresholdMinutes',
'recoveryWarnThresholdMinutes', 'repoUtilizationWarnThreshold']
@@ -145,9 +139,8 @@ def has_match(module, ssid, api_url, api_pwd, api_usr, body):
url = api_url + endpoint
try:
rc, data = request(url, url_username=api_usr, url_password=api_pwd, headers=HEADERS)
- except Exception:
- error = get_exception()
- module.exit_json(exception="Error finding a match. Message: %s" % str(error))
+ except Exception as e:
+ module.exit_json(msg="Error finding a match. Message: %s" % to_native(e), exception=traceback.format_exc())
for async_group in data:
if async_group['label'] == desired_name:
@@ -174,9 +167,9 @@ def create_async(module, ssid, api_url, api_pwd, api_usr, body):
try:
rc, data = request(url, data=post_data, method='POST', url_username=api_usr, url_password=api_pwd,
headers=HEADERS)
- except Exception:
- error = get_exception()
- module.exit_json(exception="Exception while creating aysnc mirror group. Message: %s" % str(error))
+ except Exception as e:
+ module.exit_json(msg="Exception while creating aysnc mirror group. Message: %s" % to_native(e),
+ exception=traceback.format_exc())
return data
@@ -195,9 +188,9 @@ def update_async(module, ssid, api_url, pwd, user, body, new_name, async_id):
try:
rc, data = request(url, data=post_data, method='POST', headers=HEADERS,
url_username=user, url_password=pwd)
- except Exception:
- error = get_exception()
- module.exit_json(exception="Exception while updating async mirror group. Message: %s" % str(error))
+ except Exception as e:
+ module.exit_json(msg="Exception while updating async mirror group. Message: %s" % to_native(e),
+ exception=traceback.format_exc())
return data
@@ -208,9 +201,9 @@ def remove_amg(module, ssid, api_url, pwd, user, async_id):
try:
rc, data = request(url, method='DELETE', url_username=user, url_password=pwd,
headers=HEADERS)
- except Exception:
- error = get_exception()
- module.exit_json(exception="Exception while removing async mirror group. Message: %s" % str(error))
+ except Exception as e:
+ module.exit_json(msg="Exception while removing async mirror group. Message: %s" % to_native(e),
+ exception=traceback.format_exc())
return
diff --git a/lib/ansible/modules/storage/netapp/netapp_e_amg_role.py b/lib/ansible/modules/storage/netapp/netapp_e_amg_role.py
index a029e3ffa8..ed28a2ff6a 100644
--- a/lib/ansible/modules/storage/netapp/netapp_e_amg_role.py
+++ b/lib/ansible/modules/storage/netapp/netapp_e_amg_role.py
@@ -1,22 +1,12 @@
#!/usr/bin/python
# (c) 2016, NetApp, Inc
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
@@ -90,13 +80,14 @@ msg:
sample: "No Async Mirror Group with the name."
"""
import json
+import traceback
from ansible.module_utils.api import basic_auth_argument_spec
from ansible.module_utils.basic import AnsibleModule
-
-from ansible.module_utils.pycompat24 import get_exception
-from ansible.module_utils.urls import open_url
from ansible.module_utils.six.moves.urllib.error import HTTPError
+from ansible.module_utils._text import to_native
+from ansible.module_utils.urls import open_url
+
HEADERS = {
"Content-Type": "application/json",
@@ -112,9 +103,8 @@ def request(url, data=None, headers=None, method='GET', use_proxy=True,
force=force, last_mod_time=last_mod_time, timeout=timeout, validate_certs=validate_certs,
url_username=url_username, url_password=url_password, http_agent=http_agent,
force_basic_auth=force_basic_auth)
- except HTTPError:
- err = get_exception()
- r = err.fp
+ except HTTPError as e:
+ r = e.fp
try:
raw_data = r.read()
@@ -167,21 +157,21 @@ def update_amg(module, ssid, api_url, api_usr, api_pwd, body, amg_id):
try:
request(url, data=post_data, method='POST', url_username=api_usr,
url_password=api_pwd, headers=HEADERS)
- except:
- err = get_exception()
+ except Exception as e:
module.fail_json(
- msg="Failed to change role of AMG. Id [%s]. AMG Id [%s]. Error [%s]" % (ssid, amg_id, str(err)))
+ msg="Failed to change role of AMG. Id [%s]. AMG Id [%s]. Error [%s]" % (ssid, amg_id, to_native(e)),
+ exception=traceback.format_exc())
status_endpoint = 'storage-systems/%s/async-mirrors/%s' % (ssid, amg_id)
status_url = api_url + status_endpoint
try:
rc, status = request(status_url, method='GET', url_username=api_usr,
url_password=api_pwd, headers=HEADERS)
- except:
- err = get_exception()
+ except Exception as e:
module.fail_json(
- msg="Failed to check status of AMG after role reversal. " +
- "Id [%s]. AMG Id [%s]. Error [%s]" % (ssid, amg_id, str(err)))
+ msg="Failed to check status of AMG after role reversal. "
+ "Id [%s]. AMG Id [%s]. Error [%s]" % (ssid, amg_id, to_native(e)),
+ exception=traceback.format_exc())
# Here we wait for the role reversal to complete
if 'roleChangeProgress' in status:
@@ -189,11 +179,11 @@ def update_amg(module, ssid, api_url, api_usr, api_pwd, body, amg_id):
try:
rc, status = request(status_url, method='GET',
url_username=api_usr, url_password=api_pwd, headers=HEADERS)
- except:
- err = get_exception()
+ except Exception as e:
module.fail_json(
- msg="Failed to check status of AMG after role reversal. " +
- "Id [%s]. AMG Id [%s]. Error [%s]" % (ssid, amg_id, str(err)))
+ msg="Failed to check status of AMG after role reversal. "
+ "Id [%s]. AMG Id [%s]. Error [%s]" % (ssid, amg_id, to_native(e)),
+ exception=traceback.format_exc())
return status
diff --git a/lib/ansible/modules/storage/netapp/netapp_e_amg_sync.py b/lib/ansible/modules/storage/netapp/netapp_e_amg_sync.py
index 5a26aecff3..1af17c0daa 100644
--- a/lib/ansible/modules/storage/netapp/netapp_e_amg_sync.py
+++ b/lib/ansible/modules/storage/netapp/netapp_e_amg_sync.py
@@ -1,22 +1,12 @@
#!/usr/bin/python
# (c) 2016, NetApp, Inc
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
@@ -133,10 +123,8 @@ import json
from ansible.module_utils.api import basic_auth_argument_spec
from ansible.module_utils.basic import AnsibleModule
-
-from ansible.module_utils.pycompat24 import get_exception
-from ansible.module_utils.urls import open_url
from ansible.module_utils.six.moves.urllib.error import HTTPError
+from ansible.module_utils.urls import open_url
def request(url, data=None, headers=None, method='GET', use_proxy=True,
@@ -147,9 +135,8 @@ def request(url, data=None, headers=None, method='GET', use_proxy=True,
force=force, last_mod_time=last_mod_time, timeout=timeout, validate_certs=validate_certs,
url_username=url_username, url_password=url_password, http_agent=http_agent,
force_basic_auth=force_basic_auth)
- except HTTPError:
- err = get_exception()
- r = err.fp
+ except HTTPError as e:
+ r = e.fp
try:
raw_data = r.read()
diff --git a/lib/ansible/modules/storage/netapp/netapp_e_auth.py b/lib/ansible/modules/storage/netapp/netapp_e_auth.py
index e36cf53d6a..52513b18d3 100644
--- a/lib/ansible/modules/storage/netapp/netapp_e_auth.py
+++ b/lib/ansible/modules/storage/netapp/netapp_e_auth.py
@@ -1,22 +1,12 @@
#!/usr/bin/python
# (c) 2016, NetApp, Inc
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
@@ -96,13 +86,13 @@ msg:
sample: "Password Updated Successfully"
'''
import json
+import traceback
from ansible.module_utils.api import basic_auth_argument_spec
from ansible.module_utils.basic import AnsibleModule
-
-from ansible.module_utils.pycompat24 import get_exception
-from ansible.module_utils.urls import open_url
from ansible.module_utils.six.moves.urllib.error import HTTPError
+from ansible.module_utils._text import to_native
+from ansible.module_utils.urls import open_url
HEADERS = {
@@ -119,9 +109,8 @@ def request(url, data=None, headers=None, method='GET', use_proxy=True,
force=force, last_mod_time=last_mod_time, timeout=timeout, validate_certs=validate_certs,
url_username=url_username, url_password=url_password, http_agent=http_agent,
force_basic_auth=force_basic_auth)
- except HTTPError:
- err = get_exception()
- r = err.fp
+ except HTTPError as e:
+ r = e.fp
try:
raw_data = r.read()
@@ -173,10 +162,9 @@ def get_pwd_status(module, ssid, api_url, user, pwd):
try:
rc, data = request(url, headers=HEADERS, url_username=user, url_password=pwd)
return data['readOnlyPasswordSet'], data['adminPasswordSet']
- except HTTPError:
- error = get_exception()
+ except HTTPError as e:
module.fail_json(msg="There was an issue with connecting, please check that your "
- "endpoint is properly defined and your credentials are correct: %s" % str(error))
+ "endpoint is properly defined and your credentials are correct: %s" % to_native(e))
def update_storage_system_pwd(module, ssid, pwd, api_url, api_usr, api_pwd):
@@ -186,9 +174,8 @@ def update_storage_system_pwd(module, ssid, pwd, api_url, api_usr, api_pwd):
try:
rc, data = request(url, data=post_body, method='POST', headers=HEADERS, url_username=api_usr,
url_password=api_pwd)
- except:
- err = get_exception()
- module.fail_json(msg="Failed to update system password. Id [%s]. Error [%s]" % (ssid, str(err)))
+ except Exception as e:
+ module.fail_json(msg="Failed to update system password. Id [%s]. Error [%s]" % (ssid, to_native(e)))
return data
@@ -205,15 +192,14 @@ def set_password(module, ssid, api_url, user, pwd, current_password=None, new_pa
try:
rc, data = request(url, method='POST', data=post_body, headers=HEADERS, url_username=user, url_password=pwd,
ignore_errors=True)
- except:
- err = get_exception()
- module.fail_json(msg="Failed to set system password. Id [%s]. Error [%s]" % (ssid, str(err)))
+ except Exception as e:
+ module.fail_json(msg="Failed to set system password. Id [%s]. Error [%s]" % (ssid, to_native(e)), exception=traceback.format_exc())
if rc == 422:
post_body = json.dumps(dict(currentAdminPassword='', adminPassword=set_admin, newPassword=new_password))
try:
rc, data = request(url, method='POST', data=post_body, headers=HEADERS, url_username=user, url_password=pwd)
- except Exception:
+ except:
module.fail_json(msg="Wrong or no admin password supplied. Please update your playbook and try again")
update_data = update_storage_system_pwd(module, ssid, new_password, api_url, user, pwd)
diff --git a/lib/ansible/modules/storage/netapp/netapp_e_facts.py b/lib/ansible/modules/storage/netapp/netapp_e_facts.py
index 2b67a796cf..e462edf699 100644
--- a/lib/ansible/modules/storage/netapp/netapp_e_facts.py
+++ b/lib/ansible/modules/storage/netapp/netapp_e_facts.py
@@ -1,22 +1,12 @@
#!/usr/bin/python
# (c) 2016, NetApp, Inc
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
@@ -75,7 +65,8 @@ msg:
import json
from ansible.module_utils.api import basic_auth_argument_spec
-from ansible.module_utils.basic import AnsibleModule, get_exception
+from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils._text import to_native
from ansible.module_utils.urls import open_url
from ansible.module_utils.six.moves.urllib.error import HTTPError
@@ -88,9 +79,8 @@ def request(url, data=None, headers=None, method='GET', use_proxy=True,
force=force, last_mod_time=last_mod_time, timeout=timeout, validate_certs=validate_certs,
url_username=url_username, url_password=url_password, http_agent=http_agent,
force_basic_auth=force_basic_auth)
- except HTTPError:
- err = get_exception()
- r = err.fp
+ except HTTPError as e:
+ r = e.fp
try:
raw_data = r.read()
@@ -141,10 +131,9 @@ def main():
(rc, resp) = request(api_url + "/storage-systems/%s/graph" % ssid,
headers=dict(Accept="application/json"),
url_username=api_usr, url_password=api_pwd, validate_certs=validate_certs)
- except:
- error = get_exception()
+ except Exception as e:
module.fail_json(
- msg="Failed to obtain facts from storage array with id [%s]. Error [%s]" % (ssid, str(error)))
+ msg="Failed to obtain facts from storage array with id [%s]. Error [%s]" % (ssid, to_native(e)))
facts['snapshot_images'] = [
dict(
diff --git a/lib/ansible/modules/storage/netapp/netapp_e_flashcache.py b/lib/ansible/modules/storage/netapp/netapp_e_flashcache.py
index 8281ad07c1..9da95c1b39 100644
--- a/lib/ansible/modules/storage/netapp/netapp_e_flashcache.py
+++ b/lib/ansible/modules/storage/netapp/netapp_e_flashcache.py
@@ -1,22 +1,12 @@
#!/usr/bin/python
# (c) 2016, NetApp, Inc
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
diff --git a/lib/ansible/modules/storage/netapp/netapp_e_host.py b/lib/ansible/modules/storage/netapp/netapp_e_host.py
index acba79c7fa..e323c5086b 100644
--- a/lib/ansible/modules/storage/netapp/netapp_e_host.py
+++ b/lib/ansible/modules/storage/netapp/netapp_e_host.py
@@ -1,22 +1,12 @@
#!/usr/bin/python
# (c) 2016, NetApp, Inc
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
diff --git a/lib/ansible/modules/storage/netapp/netapp_e_hostgroup.py b/lib/ansible/modules/storage/netapp/netapp_e_hostgroup.py
index 083783936d..68f7d1f13a 100644
--- a/lib/ansible/modules/storage/netapp/netapp_e_hostgroup.py
+++ b/lib/ansible/modules/storage/netapp/netapp_e_hostgroup.py
@@ -2,23 +2,12 @@
# -*- coding: utf-8 -*-
# (c) 2016, NetApp, Inc
-#
-# 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 .
-#
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
@@ -139,10 +128,9 @@ HEADERS = {
import json
from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.pycompat24 import get_exception
-
-from ansible.module_utils.urls import open_url
from ansible.module_utils.six.moves.urllib.error import HTTPError
+from ansible.module_utils._text import to_native
+from ansible.module_utils.urls import open_url
def request(url, data=None, headers=None, method='GET', use_proxy=True,
@@ -153,9 +141,8 @@ def request(url, data=None, headers=None, method='GET', use_proxy=True,
force=force, last_mod_time=last_mod_time, timeout=timeout, validate_certs=validate_certs,
url_username=url_username, url_password=url_password, http_agent=http_agent,
force_basic_auth=force_basic_auth)
- except HTTPError:
- err = get_exception()
- r = err.fp
+ except HTTPError as e:
+ r = e.fp
try:
raw_data = r.read()
@@ -194,9 +181,8 @@ def get_hostgroups(module, ssid, api_url, user, pwd):
try:
rc, data = request(url, headers=HEADERS, url_username=user, url_password=pwd)
return rc, data
- except HTTPError:
- err = get_exception()
- module.fail_json(msg="Failed to get host groups. Id [%s]. Error [%s]." % (ssid, str(err)))
+ except HTTPError as e:
+ module.fail_json(msg="Failed to get host groups. Id [%s]. Error [%s]." % (ssid, to_native(e)))
def get_hostref(module, ssid, name, api_url, user, pwd):
@@ -204,9 +190,8 @@ def get_hostref(module, ssid, name, api_url, user, pwd):
url = api_url + all_hosts
try:
rc, data = request(url, method='GET', headers=HEADERS, url_username=user, url_password=pwd)
- except Exception:
- err = get_exception()
- module.fail_json(msg="Failed to get hosts. Id [%s]. Error [%s]." % (ssid, str(err)))
+ except Exception as e:
+ module.fail_json(msg="Failed to get hosts. Id [%s]. Error [%s]." % (ssid, to_native(e)))
for host in data:
if host['name'] == name:
@@ -230,9 +215,8 @@ def create_hostgroup(module, ssid, name, api_url, user, pwd, hosts=None):
post_data = json.dumps(dict(name=name, hosts=hostrefs))
try:
rc, data = request(url, method='POST', data=post_data, headers=HEADERS, url_username=user, url_password=pwd)
- except Exception:
- err = get_exception()
- module.fail_json(msg="Failed to create host group. Id [%s]. Error [%s]." % (ssid, str(err)))
+ except Exception as e:
+ module.fail_json(msg="Failed to create host group. Id [%s]. Error [%s]." % (ssid, to_native(e)))
return rc, data
@@ -255,10 +239,9 @@ def update_hostgroup(module, ssid, name, api_url, user, pwd, hosts=None, new_nam
try:
rc, data = request(url, method='POST', data=post_data, headers=HEADERS, url_username=user, url_password=pwd)
- except Exception:
- err = get_exception()
+ except Exception as e:
module.fail_json(msg="Failed to update host group. Group [%s]. Id [%s]. Error [%s]." % (gid, ssid,
- str(err)))
+ to_native(e)))
return rc, data
@@ -269,9 +252,8 @@ def delete_hostgroup(module, ssid, group_id, api_url, user, pwd):
# TODO: Loop through hosts, do mapping to href, make new list to pass to data
try:
rc, data = request(url, method='DELETE', headers=HEADERS, url_username=user, url_password=pwd)
- except Exception:
- err = get_exception()
- module.fail_json(msg="Failed to delete host group. Group [%s]. Id [%s]. Error [%s]." % (group_id, ssid, str(err)))
+ except Exception as e:
+ module.fail_json(msg="Failed to delete host group. Group [%s]. Id [%s]. Error [%s]." % (group_id, ssid, to_native(e)))
return rc, data
@@ -294,24 +276,22 @@ def get_hosts_in_group(module, ssid, group_name, api_url, user, pwd):
g_url = api_url + all_groups
try:
g_rc, g_data = request(g_url, method='GET', headers=HEADERS, url_username=user, url_password=pwd)
- except Exception:
- err = get_exception()
+ except Exception as e:
module.fail_json(
msg="Failed in first step getting hosts from group. Group: [%s]. Id [%s]. Error [%s]." % (group_name,
ssid,
- str(err)))
+ to_native(e)))
all_hosts = 'storage-systems/%s/hosts' % ssid
h_url = api_url + all_hosts
try:
h_rc, h_data = request(h_url, method='GET', headers=HEADERS, url_username=user, url_password=pwd)
- except Exception:
- err = get_exception()
+ except Exception as e:
module.fail_json(
msg="Failed in second step getting hosts from group. Group: [%s]. Id [%s]. Error [%s]." % (
group_name,
ssid,
- str(err)))
+ to_native(e)))
hosts_in_group = []
@@ -371,9 +351,8 @@ def main():
if not exists:
try:
rc, data = create_hostgroup(module, ssid, name, api_url, user, pwd, hosts)
- except Exception:
- err = get_exception()
- module.fail_json(msg="Failed to create a host group. Id [%s]. Error [%s]." % (ssid, str(err)))
+ except Exception as e:
+ module.fail_json(msg="Failed to create a host group. Id [%s]. Error [%s]." % (ssid, to_native(e)))
hosts = get_hosts_in_group(module, ssid, name, api_url, user, pwd)
module.exit_json(changed=True, hosts=hosts, **data)
@@ -389,10 +368,9 @@ def main():
if set(current_hosts) != set(hosts):
try:
rc, data = update_hostgroup(module, ssid, name, api_url, user, pwd, hosts, new_name)
- except Exception:
- err = get_exception()
+ except Exception as e:
module.fail_json(
- msg="Failed to update host group. Group: [%s]. Id [%s]. Error [%s]." % (name, ssid, str(err)))
+ msg="Failed to update host group. Group: [%s]. Id [%s]. Error [%s]." % (name, ssid, to_native(e)))
module.exit_json(changed=True, hosts=hosts, **data)
else:
for group in group_data:
@@ -404,10 +382,9 @@ def main():
hg_id = get_hostgroup_id(module, ssid, name, api_url, user, pwd)
try:
rc, data = delete_hostgroup(module, ssid, hg_id, api_url, user, pwd)
- except Exception:
- err = get_exception()
+ except Exception as e:
module.fail_json(
- msg="Failed to delete host group. Group: [%s]. Id [%s]. Error [%s]." % (name, ssid, str(err)))
+ msg="Failed to delete host group. Group: [%s]. Id [%s]. Error [%s]." % (name, ssid, to_native(e)))
module.exit_json(changed=True, msg="Host Group deleted")
else:
diff --git a/lib/ansible/modules/storage/netapp/netapp_e_lun_mapping.py b/lib/ansible/modules/storage/netapp/netapp_e_lun_mapping.py
index 192c0f44b2..c05805c3d8 100644
--- a/lib/ansible/modules/storage/netapp/netapp_e_lun_mapping.py
+++ b/lib/ansible/modules/storage/netapp/netapp_e_lun_mapping.py
@@ -1,22 +1,11 @@
#!/usr/bin/python
# (c) 2016, NetApp, Inc
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
diff --git a/lib/ansible/modules/storage/netapp/netapp_e_snapshot_group.py b/lib/ansible/modules/storage/netapp/netapp_e_snapshot_group.py
index 8d0ded067c..c52ecea79a 100644
--- a/lib/ansible/modules/storage/netapp/netapp_e_snapshot_group.py
+++ b/lib/ansible/modules/storage/netapp/netapp_e_snapshot_group.py
@@ -1,22 +1,12 @@
#!/usr/bin/python
# (c) 2016, NetApp, Inc
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
diff --git a/lib/ansible/modules/storage/netapp/netapp_e_snapshot_images.py b/lib/ansible/modules/storage/netapp/netapp_e_snapshot_images.py
index b55e5ced8e..36e43080e1 100644
--- a/lib/ansible/modules/storage/netapp/netapp_e_snapshot_images.py
+++ b/lib/ansible/modules/storage/netapp/netapp_e_snapshot_images.py
@@ -1,22 +1,12 @@
#!/usr/bin/python
# (c) 2016, NetApp, Inc
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
diff --git a/lib/ansible/modules/storage/netapp/netapp_e_snapshot_volume.py b/lib/ansible/modules/storage/netapp/netapp_e_snapshot_volume.py
index f5d3d1a5c1..544963aaa2 100644
--- a/lib/ansible/modules/storage/netapp/netapp_e_snapshot_volume.py
+++ b/lib/ansible/modules/storage/netapp/netapp_e_snapshot_volume.py
@@ -1,22 +1,12 @@
#!/usr/bin/python
# (c) 2016, NetApp, Inc
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
diff --git a/lib/ansible/modules/storage/netapp/netapp_e_storage_system.py b/lib/ansible/modules/storage/netapp/netapp_e_storage_system.py
index 70705a48f6..08ade891b3 100644
--- a/lib/ansible/modules/storage/netapp/netapp_e_storage_system.py
+++ b/lib/ansible/modules/storage/netapp/netapp_e_storage_system.py
@@ -1,22 +1,12 @@
#!/usr/bin/python
# (c) 2016, NetApp, Inc
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
diff --git a/lib/ansible/modules/storage/netapp/netapp_e_storagepool.py b/lib/ansible/modules/storage/netapp/netapp_e_storagepool.py
index dab5c9ed5e..6772e55800 100644
--- a/lib/ansible/modules/storage/netapp/netapp_e_storagepool.py
+++ b/lib/ansible/modules/storage/netapp/netapp_e_storagepool.py
@@ -1,21 +1,11 @@
#!/usr/bin/python
# (c) 2016, NetApp, Inc
-#
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -409,7 +399,7 @@ class NetAppESeriesStoragePool(object):
if raid_level in [None, 'raid0']:
return disk_size_bytes * disk_count
if raid_level == 'raid1':
- return (disk_size_bytes * disk_count) / 2
+ return (disk_size_bytes * disk_count) // 2
if raid_level in ['raid3', 'raid5']:
return (disk_size_bytes * disk_count) - disk_size_bytes
if raid_level in ['raid6', 'raidDiskPool']:
diff --git a/lib/ansible/modules/storage/netapp/netapp_e_volume.py b/lib/ansible/modules/storage/netapp/netapp_e_volume.py
index 3bc6f7e76d..318e1fa9f2 100644
--- a/lib/ansible/modules/storage/netapp/netapp_e_volume.py
+++ b/lib/ansible/modules/storage/netapp/netapp_e_volume.py
@@ -1,22 +1,11 @@
#!/usr/bin/python
# (c) 2016, NetApp, Inc
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/storage/netapp/netapp_e_volume_copy.py b/lib/ansible/modules/storage/netapp/netapp_e_volume_copy.py
index 69b144d60b..ba7a9e15db 100644
--- a/lib/ansible/modules/storage/netapp/netapp_e_volume_copy.py
+++ b/lib/ansible/modules/storage/netapp/netapp_e_volume_copy.py
@@ -1,22 +1,12 @@
#!/usr/bin/python
# (c) 2016, NetApp, Inc
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
diff --git a/lib/ansible/modules/storage/netapp/sf_account_manager.py b/lib/ansible/modules/storage/netapp/sf_account_manager.py
index 253269916c..9d17dcbf45 100644
--- a/lib/ansible/modules/storage/netapp/sf_account_manager.py
+++ b/lib/ansible/modules/storage/netapp/sf_account_manager.py
@@ -1,22 +1,12 @@
#!/usr/bin/python
# (c) 2017, NetApp, Inc
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
@@ -115,11 +105,13 @@ EXAMPLES = """
RETURN = """
"""
+import traceback
from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.pycompat24 import get_exception
+from ansible.module_utils._text import to_native
import ansible.module_utils.netapp as netapp_utils
+
HAS_SF_SDK = netapp_utils.has_sf_sdk()
@@ -188,17 +180,17 @@ class SolidFireAccount(object):
initiator_secret=self.initiator_secret,
target_secret=self.target_secret,
attributes=self.attributes)
- except:
- err = get_exception()
- self.module.fail_json(msg='Error creating account %s' % self.name, exception=str(err))
+ except Exception as e:
+ self.module.fail_json(msg='Error creating account %s: %s)' % (self.name, to_native(e)),
+ exception=traceback.format_exc())
def delete_account(self):
try:
self.sfe.remove_account(account_id=self.account_id)
- except:
- err = get_exception()
- self.module.fail_json(msg='Error deleting account %s' % self.account_id, exception=str(err))
+ except Exception as e:
+ self.module.fail_json(msg='Error deleting account %s: %s' % (self.account_id, to_native(e)),
+ exception=traceback.format_exc())
def update_account(self):
try:
@@ -209,9 +201,9 @@ class SolidFireAccount(object):
target_secret=self.target_secret,
attributes=self.attributes)
- except:
- err = get_exception()
- self.module.fail_json(msg='Error updating account %s' % self.account_id, exception=str(err))
+ except Exception as e:
+ self.module.fail_json(msg='Error updating account %s: %s' % (self.account_id, to_native(e)),
+ exception=traceback.format_exc())
def apply(self):
changed = False
diff --git a/lib/ansible/modules/storage/netapp/sf_check_connections.py b/lib/ansible/modules/storage/netapp/sf_check_connections.py
index a2616b7f97..7a1e739aac 100644
--- a/lib/ansible/modules/storage/netapp/sf_check_connections.py
+++ b/lib/ansible/modules/storage/netapp/sf_check_connections.py
@@ -1,22 +1,12 @@
#!/usr/bin/python
# (c) 2017, NetApp, Inc
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
@@ -72,11 +62,13 @@ EXAMPLES = """
RETURN = """
"""
+import traceback
from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.pycompat24 import get_exception
+from ansible.module_utils._text import to_native
import ansible.module_utils.netapp as netapp_utils
+
HAS_SF_SDK = netapp_utils.has_sf_sdk()
@@ -120,9 +112,8 @@ class SolidFireConnection(object):
# Todo - Log details about the test
return result
- except:
- err = get_exception()
- self.module.fail_json(msg='Error checking connection to MVIP', exception=str(err))
+ except Exception as e:
+ self.module.fail_json(msg='Error checking connection to MVIP: %s' % to_native(e), exception=traceback.format_exc())
return False
def check_svip_connection(self):
@@ -138,9 +129,8 @@ class SolidFireConnection(object):
# Todo - Log details about the test
return result
- except:
- err = get_exception()
- self.module.fail_json(msg='Error checking connection to SVIP', exception=str(err))
+ except Exception as e:
+ self.module.fail_json(msg='Error checking connection to SVIP: %s' % to_native(e), exception=traceback.format_exc())
return False
def check(self):
diff --git a/lib/ansible/modules/storage/netapp/sf_snapshot_schedule_manager.py b/lib/ansible/modules/storage/netapp/sf_snapshot_schedule_manager.py
index 269c957e91..4b6c0dd25c 100644
--- a/lib/ansible/modules/storage/netapp/sf_snapshot_schedule_manager.py
+++ b/lib/ansible/modules/storage/netapp/sf_snapshot_schedule_manager.py
@@ -1,21 +1,11 @@
#!/usr/bin/python
# (c) 2017, NetApp, Inc
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
@@ -141,13 +131,16 @@ schedule_id:
returned: success
type: string
"""
+import traceback
from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.pycompat24 import get_exception
+from ansible.module_utils._text import to_native
import ansible.module_utils.netapp as netapp_utils
+
HAS_SF_SDK = netapp_utils.has_sf_sdk()
+
class SolidFireSnapShotSchedule(object):
def __init__(self):
@@ -249,9 +242,9 @@ class SolidFireSnapShotSchedule(object):
self.create_schedule_result = self.sfe.create_schedule(schedule=sched)
- except:
- err = get_exception()
- self.module.fail_json(msg='Error creating schedule %s' % self.name, exception=str(err))
+ except Exception as e:
+ self.module.fail_json(msg='Error creating schedule %s: %s' % (self.name, to_native(e)),
+ exception=traceback.format_exc())
def delete_schedule(self):
@@ -261,9 +254,9 @@ class SolidFireSnapShotSchedule(object):
sched.to_be_deleted = True
self.sfe.modify_schedule(schedule=sched)
- except:
- err = get_exception()
- self.module.fail_json(msg='Error deleting schedule %s' % self.name, exception=str(err))
+ except Exception as e:
+ self.module.fail_json(msg='Error deleting schedule %s: %s' % (self.name, to_native(e)),
+ exception=traceback.format_exc())
def update_schedule(self):
@@ -300,9 +293,9 @@ class SolidFireSnapShotSchedule(object):
# Make API call
self.sfe.modify_schedule(schedule=sched)
- except:
- err = get_exception()
- self.module.fail_json(msg='Error updating schedule %s' % self.name, exception=str(err))
+ except Exception as e:
+ self.module.fail_json(msg='Error updating schedule %s: %s' % (self.name, to_native(e)),
+ exception=traceback.format_exc())
def apply(self):
changed = False
diff --git a/lib/ansible/modules/storage/netapp/sf_volume_access_group_manager.py b/lib/ansible/modules/storage/netapp/sf_volume_access_group_manager.py
index d6249e6717..875a1d633c 100644
--- a/lib/ansible/modules/storage/netapp/sf_volume_access_group_manager.py
+++ b/lib/ansible/modules/storage/netapp/sf_volume_access_group_manager.py
@@ -1,22 +1,12 @@
#!/usr/bin/python
# (c) 2017, NetApp, Inc
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
@@ -117,10 +107,10 @@ RETURN = """
"""
-
+import traceback
from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.pycompat24 import get_exception
+from ansible.module_utils._text import to_native
import ansible.module_utils.netapp as netapp_utils
HAS_SF_SDK = netapp_utils.has_sf_sdk()
@@ -188,19 +178,18 @@ class SolidFireVolumeAccessGroup(object):
virtual_network_id=self.virtual_network_id,
virtual_network_tags=self.virtual_network_tags,
attributes=self.attributes)
- except:
- err = get_exception()
- self.module.fail_json(msg="Error creating volume access group %s" % self.name,
- exception=str(err))
+ except Exception as e:
+ self.module.fail_json(msg="Error creating volume access group %s: %s" %
+ (self.name, to_native(e)), exception=traceback.format_exc())
def delete_volume_access_group(self):
try:
self.sfe.delete_volume_access_group(volume_access_group_id=self.volume_access_group_id)
- except:
- err = get_exception()
- self.module.fail_json(msg="Error deleting volume access group %s" % self.volume_access_group_id,
- exception=str(err))
+ except Exception as e:
+ self.module.fail_json(msg="Error deleting volume access group %s: %s" %
+ (self.volume_access_group_id, to_native(e)),
+ exception=traceback.format_exc())
def update_volume_access_group(self):
try:
@@ -211,10 +200,9 @@ class SolidFireVolumeAccessGroup(object):
initiators=self.initiators,
volumes=self.volumes,
attributes=self.attributes)
- except:
- err = get_exception()
- self.module.fail_json(msg="Error updating volume access group %s" % self.volume_access_group_id,
- exception=str(err))
+ except Exception as e:
+ self.module.fail_json(msg="Error updating volume access group %s: %s" %
+ (self.volume_access_group_id, to_native(e)), exception=traceback.format_exc())
def apply(self):
changed = False
diff --git a/lib/ansible/modules/storage/netapp/sf_volume_manager.py b/lib/ansible/modules/storage/netapp/sf_volume_manager.py
index db96af3e29..f4bfa05a9a 100644
--- a/lib/ansible/modules/storage/netapp/sf_volume_manager.py
+++ b/lib/ansible/modules/storage/netapp/sf_volume_manager.py
@@ -1,22 +1,12 @@
#!/usr/bin/python
# (c) 2017, NetApp, Inc
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
diff --git a/lib/ansible/modules/storage/purestorage/purefa_host.py b/lib/ansible/modules/storage/purestorage/purefa_host.py
index 53c44a9596..c5dbee5932 100644
--- a/lib/ansible/modules/storage/purestorage/purefa_host.py
+++ b/lib/ansible/modules/storage/purestorage/purefa_host.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2017, Simon Dodsley (simon@purestorage.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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/storage/purestorage/purefa_volume.py b/lib/ansible/modules/storage/purestorage/purefa_volume.py
index f2b2ea7f6e..c9c9aa8e65 100644
--- a/lib/ansible/modules/storage/purestorage/purefa_volume.py
+++ b/lib/ansible/modules/storage/purestorage/purefa_volume.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2017, Simon Dodsley (simon@purestorage.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 .
+# 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.0',
'status': ['preview'],
@@ -84,16 +74,15 @@ EXAMPLES = '''
RETURN = '''
'''
-from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.pure import get_system, purefa_argument_spec
-
-
HAS_PURESTORAGE = True
try:
from purestorage import purestorage
except ImportError:
HAS_PURESTORAGE = False
+from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils.pure import get_system, purefa_argument_spec
+
def human_to_bytes(size):
"""Given a human-readable byte string (e.g. 2G, 30M),
diff --git a/lib/ansible/modules/storage/zfs/zfs.py b/lib/ansible/modules/storage/zfs/zfs.py
index 6fd8c61e94..cab60a4155 100644
--- a/lib/ansible/modules/storage/zfs/zfs.py
+++ b/lib/ansible/modules/storage/zfs/zfs.py
@@ -2,22 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2013, Johan Wiren
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
@@ -93,9 +82,10 @@ EXAMPLES = '''
state: absent
'''
-
import os
+from ansible.module_utils.basic import AnsibleModule
+
class Zfs(object):
@@ -275,8 +265,6 @@ def main():
result['changed'] = zfs.changed
module.exit_json(**result)
-# import module snippets
-from ansible.module_utils.basic import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/storage/zfs/zfs_facts.py b/lib/ansible/modules/storage/zfs/zfs_facts.py
index 43f52b7b9c..81301b8ba5 100644
--- a/lib/ansible/modules/storage/zfs/zfs_facts.py
+++ b/lib/ansible/modules/storage/zfs/zfs_facts.py
@@ -2,22 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2016, Adam Števko
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
@@ -171,10 +160,11 @@ zfs_datasets:
}
'''
-import os
from collections import defaultdict
-from ansible.module_utils.six import iteritems
+
from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils.six import iteritems
+
SUPPORTED_TYPES = ['all', 'filesystem', 'volume', 'snapshot', 'bookmark']
diff --git a/lib/ansible/modules/storage/zfs/zpool_facts.py b/lib/ansible/modules/storage/zfs/zpool_facts.py
index 32a683de99..92fca3f777 100644
--- a/lib/ansible/modules/storage/zfs/zpool_facts.py
+++ b/lib/ansible/modules/storage/zfs/zpool_facts.py
@@ -2,22 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2016, Adam Števko
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
@@ -123,11 +112,12 @@ zfs_pools:
}
'''
-import os
from collections import defaultdict
+
from ansible.module_utils.six import iteritems
from ansible.module_utils.basic import AnsibleModule
+
class ZPoolFacts(object):
def __init__(self, module):
diff --git a/lib/ansible/modules/system/aix_inittab.py b/lib/ansible/modules/system/aix_inittab.py
index ac80c9ec33..0b12e79cd4 100644
--- a/lib/ansible/modules/system/aix_inittab.py
+++ b/lib/ansible/modules/system/aix_inittab.py
@@ -2,22 +2,12 @@
# -*- coding: utf-8 -*-
# (c) 2017, Joris Weijters
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
diff --git a/lib/ansible/modules/system/aix_lvol.py b/lib/ansible/modules/system/aix_lvol.py
index 7c8a9be6a9..816372b596 100644
--- a/lib/ansible/modules/system/aix_lvol.py
+++ b/lib/ansible/modules/system/aix_lvol.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2016, Alain Dejoux
-#
-# 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 .
+# 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 = {'status': ['preview'],
'supported_by': 'community',
diff --git a/lib/ansible/modules/system/alternatives.py b/lib/ansible/modules/system/alternatives.py
index a9571db063..05f336f72a 100644
--- a/lib/ansible/modules/system/alternatives.py
+++ b/lib/ansible/modules/system/alternatives.py
@@ -1,26 +1,13 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-"""
-Ansible module to manage symbolic link alternatives.
-(c) 2014, Gabe Mulley
-(c) 2015, David Wittman
+# (c) 2014, Gabe Mulley
+# (c) 2015, David Wittman
+# 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
+__metaclass__ = type
-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 .
-"""
ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/system/at.py b/lib/ansible/modules/system/at.py
index 9fb5b914a5..d61afcdcf4 100644
--- a/lib/ansible/modules/system/at.py
+++ b/lib/ansible/modules/system/at.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
#
# (c) 2014, Richard Isaacson
-#
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -90,6 +80,8 @@ EXAMPLES = '''
import os
import tempfile
+from ansible.module_utils.basic import AnsibleModule
+
def add_job(module, result, at_cmd, count, units, command, script_file):
at_command = "%s -f %s now + %s %s" % (at_cmd, script_file, count, units)
@@ -209,8 +201,6 @@ def main():
module.exit_json(**result)
-# import module snippets
-from ansible.module_utils.basic import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/system/authorized_key.py b/lib/ansible/modules/system/authorized_key.py
index c329ba5adc..c13c1e88d7 100644
--- a/lib/ansible/modules/system/authorized_key.py
+++ b/lib/ansible/modules/system/authorized_key.py
@@ -1,25 +1,12 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-"""
-Ansible module to add authorized_keys for ssh logins.
-(c) 2012, Brad Olson
+# (c) 2012, Brad Olson
+# 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
+__metaclass__ = type
-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 .
-"""
ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/system/awall.py b/lib/ansible/modules/system/awall.py
index 02c52564b8..a38d3ea4a2 100644
--- a/lib/ansible/modules/system/awall.py
+++ b/lib/ansible/modules/system/awall.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
#
# (c) 2017, Ted Trask
-#
-# This file is part of Ansible
-#
-# 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
-# the Free Software Foundation, either version 3 of the License, or
-# (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 .
+# 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.0',
'status': ['stableinterface'],
diff --git a/lib/ansible/modules/system/beadm.py b/lib/ansible/modules/system/beadm.py
index fc9d03428e..481a2deaa3 100644
--- a/lib/ansible/modules/system/beadm.py
+++ b/lib/ansible/modules/system/beadm.py
@@ -2,22 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2016, Adam Števko
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/system/capabilities.py b/lib/ansible/modules/system/capabilities.py
index bade4da021..04ce359aee 100644
--- a/lib/ansible/modules/system/capabilities.py
+++ b/lib/ansible/modules/system/capabilities.py
@@ -2,22 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2014, Nate Coraor
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
@@ -72,14 +61,11 @@ EXAMPLES = '''
state: absent
'''
+from ansible.module_utils.basic import AnsibleModule
+
OPS = ( '=', '-', '+' )
-# ==============================================================
-
-import os
-import tempfile
-import re
class CapabilitiesModule(object):
@@ -192,8 +178,5 @@ def main():
CapabilitiesModule(module)
-# import module snippets
-from ansible.module_utils.basic import *
-
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/system/cron.py b/lib/ansible/modules/system/cron.py
index 90d5c4d6aa..ccab574d72 100644
--- a/lib/ansible/modules/system/cron.py
+++ b/lib/ansible/modules/system/cron.py
@@ -7,29 +7,11 @@
# (c) 2015, Evan Kaufman
# (c) 2015, Luca Berruti
#
-# 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 .
-#
-# Cron Plugin: The goal of this plugin is to provide an idempotent method for
-# setting up cron jobs on a host. The script will play well with other manually
-# entered crons. Each cron job entered will be preceded with a comment
-# describing the job so that it can be found later, which is required to be
-# present in order for this plugin to find/modify the job.
-#
-# This module is based on python-crontab by Martin Owens.
-#
+# 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.0',
'status': ['preview'],
@@ -235,17 +217,23 @@ EXAMPLES = '''
'''
import os
-import pwd
-import re
-import tempfile
import platform
import pipes
+import pwd
+import re
+import sys
+import tempfile
+
+from ansible.module_utils.basic import AnsibleModule, get_platform
+
CRONCMD = "/usr/bin/crontab"
+
class CronTabError(Exception):
pass
+
class CronTab(object):
"""
CronTab object to write time based crontab file
@@ -785,8 +773,6 @@ def main():
# --- should never get here
module.exit_json(msg="Unable to execute cron task.")
-# import module snippets
-from ansible.module_utils.basic import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/system/cronvar.py b/lib/ansible/modules/system/cronvar.py
index d63c73c891..58049825a6 100644
--- a/lib/ansible/modules/system/cronvar.py
+++ b/lib/ansible/modules/system/cronvar.py
@@ -3,18 +3,8 @@
#
# 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 .
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+
#
# Cronvar Plugin: The goal of this plugin is to provide an idempotent
# method for set cron variable values. It should play well with the
@@ -26,6 +16,10 @@
# This module is based on the crontab module.
#
+from __future__ import absolute_import, division, print_function
+__metaclass__ = type
+
+
ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'],
'supported_by': 'community'}
@@ -113,19 +107,24 @@ EXAMPLES = '''
'''
import os
-import re
-import tempfile
-import platform
import pipes
+import platform
+import pwd
+import re
import shlex
-from ansible.module_utils.basic import *
-from ansible.module_utils.pycompat24 import get_exception
+import sys
+import tempfile
+
+from ansible.module_utils.basic import AnsibleModule
+
CRONCMD = "/usr/bin/crontab"
+
class CronVarError(Exception):
pass
+
class CronVar(object):
"""
CronVar object to write variables to crontabs.
@@ -160,7 +159,6 @@ class CronVar(object):
self.lines = f.read().splitlines()
f.close()
except IOError:
- e = get_exception()
# cron file does not exist
return
except:
@@ -217,7 +215,6 @@ class CronVar(object):
os.unlink(self.cron_file)
return True
except OSError:
- e = get_exception()
# cron file does not exist
return False
except:
@@ -234,7 +231,6 @@ class CronVar(object):
raise CronVarError("Not a variable.")
def find_variable(self, name):
- comment = None
for l in self.lines:
try:
(varname, value) = self.parse_for_var(l)
@@ -436,9 +432,6 @@ def main():
module.exit_json(**res_args)
- # --- should never get here
- module.exit_json(msg="Unable to execute cronvar task.")
-
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/system/crypttab.py b/lib/ansible/modules/system/crypttab.py
index 45249ed948..323a755fa2 100644
--- a/lib/ansible/modules/system/crypttab.py
+++ b/lib/ansible/modules/system/crypttab.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2014, Steve
-#
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -95,8 +85,11 @@ EXAMPLES = '''
when: "'/dev/mapper/luks-' in {{ item.device }}"
'''
-from ansible.module_utils.basic import *
-from ansible.module_utils.pycompat24 import get_exception
+import os
+import traceback
+
+from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils._text import to_native
def main():
@@ -142,10 +135,9 @@ def main():
try:
crypttab = Crypttab(path)
existing_line = crypttab.match(name)
- except Exception:
- e = get_exception()
- module.fail_json(msg="failed to open and parse crypttab file: %s" % e,
- **module.params)
+ except Exception as e:
+ module.fail_json(msg="failed to open and parse crypttab file: %s" % to_native(e),
+ exception=traceback.format_exc(), **module.params)
if 'present' in state and existing_line is None and backing_device is None:
module.fail_json(msg="'backing_device' required to add a new entry",
@@ -375,5 +367,6 @@ class Options(dict):
ret.append('%s=%s' % (k, v))
return ','.join(ret)
+
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/system/dconf.py b/lib/ansible/modules/system/dconf.py
index 76b6fe4cda..204ed90e94 100644
--- a/lib/ansible/modules/system/dconf.py
+++ b/lib/ansible/modules/system/dconf.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2017, Branko Majic
-#
-# 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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/system/debconf.py b/lib/ansible/modules/system/debconf.py
index 7520ec6a26..3d3ecc4bf5 100644
--- a/lib/ansible/modules/system/debconf.py
+++ b/lib/ansible/modules/system/debconf.py
@@ -1,25 +1,12 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-"""
-Ansible module to configure .deb packages.
-(c) 2014, Brian Coca
+# (c) 2014, Brian Coca
+# 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
+__metaclass__ = type
-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 .
-"""
ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['stableinterface'],
@@ -103,6 +90,9 @@ EXAMPLES = '''
name: tzdata
'''
+from ansible.module_utils.basic import AnsibleModule
+
+
def get_selections(module, pkg):
cmd = [module.get_bin_path('debconf-show', True), pkg]
rc, out, err = module.run_command(' '.join(cmd))
@@ -191,8 +181,6 @@ def main():
module.exit_json(changed=changed, msg=msg, current=prev)
-# import module snippets
-from ansible.module_utils.basic import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/system/facter.py b/lib/ansible/modules/system/facter.py
index 4ef900e8e9..a780d432d6 100644
--- a/lib/ansible/modules/system/facter.py
+++ b/lib/ansible/modules/system/facter.py
@@ -2,22 +2,10 @@
# -*- coding: utf-8 -*-
# (c) 2012, Michael DeHaan
-#
-# 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 .
-#
+# 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.0',
@@ -46,6 +34,10 @@ EXAMPLES = '''
# Example command-line invocation
ansible www.example.net -m facter
'''
+import json
+
+from ansible.module_utils.basic import AnsibleModule
+
def main():
module = AnsibleModule(
@@ -59,8 +51,6 @@ def main():
rc, out, err = module.run_command(cmd, check_rc=True)
module.exit_json(**json.loads(out))
-# import module snippets
-from ansible.module_utils.basic import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/system/filesystem.py b/lib/ansible/modules/system/filesystem.py
index 5fec91707a..f031f2f260 100644
--- a/lib/ansible/modules/system/filesystem.py
+++ b/lib/ansible/modules/system/filesystem.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2013, Alexander Bulimov
-#
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -73,6 +63,10 @@ EXAMPLES = '''
dev: /dev/sdb1
opts: -cc
'''
+import os
+
+from ansible.module_utils.basic import AnsibleModule
+
def _get_dev_size(dev, module):
""" Return size in bytes of device. Returns int """
@@ -264,7 +258,6 @@ def main():
module.exit_json(changed=changed)
-# import module snippets
-from ansible.module_utils.basic import *
+
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/system/firewalld.py b/lib/ansible/modules/system/firewalld.py
index db495a5755..cdc266e53b 100644
--- a/lib/ansible/modules/system/firewalld.py
+++ b/lib/ansible/modules/system/firewalld.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2013, Adam Miller (maxamillion@fedoraproject.org)
-#
-# 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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/system/gconftool2.py b/lib/ansible/modules/system/gconftool2.py
index 8d8a232eb7..a7703b4de1 100644
--- a/lib/ansible/modules/system/gconftool2.py
+++ b/lib/ansible/modules/system/gconftool2.py
@@ -3,20 +3,11 @@
# (c) 2016, Kenneth D. Evensen
# (c) 2017, Abhijeet Kasurde
#
-# This file is part of Ansible (sort of)
-#
-# 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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/system/getent.py b/lib/ansible/modules/system/getent.py
index 0348f8f381..faeced92ad 100644
--- a/lib/ansible/modules/system/getent.py
+++ b/lib/ansible/modules/system/getent.py
@@ -3,21 +3,10 @@
# (c) 2014, Brian Coca
#
-# 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 .
-#
+# 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.0',
@@ -100,9 +89,11 @@ EXAMPLES = '''
var: getent_shadow
'''
+import traceback
+
+from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils._text import to_native
-from ansible.module_utils.basic import *
-from ansible.module_utils.pycompat24 import get_exception
def main():
module = AnsibleModule(
@@ -134,9 +125,8 @@ def main():
try:
rc, out, err = module.run_command(cmd)
- except Exception:
- e = get_exception()
- module.fail_json(msg=str(e))
+ except Exception as e:
+ module.fail_json(msg=to_native(e), exception=traceback.format_exc())
msg = "Unexpected failure!"
dbtree = 'getent_%s' % database
diff --git a/lib/ansible/modules/system/gluster_volume.py b/lib/ansible/modules/system/gluster_volume.py
index cb6849a981..60b8a2892e 100644
--- a/lib/ansible/modules/system/gluster_volume.py
+++ b/lib/ansible/modules/system/gluster_volume.py
@@ -2,21 +2,10 @@
# -*- coding: utf-8 -*-
# (c) 2014, Taneli Leppä
-#
-# This file is part of Ansible (sort of)
-#
-# 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 .
+# 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.0',
@@ -182,14 +171,18 @@ EXAMPLES = """
run_once: true
"""
-import shutil
-import time
+import re
import socket
-from ansible.module_utils.pycompat24 import get_exception
-from ansible.module_utils.basic import *
+import time
+import traceback
+
+from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils._text import to_native
+
glusterbin = ''
+
def run_gluster(gargs, **kwargs):
global glusterbin
global module
@@ -198,10 +191,11 @@ def run_gluster(gargs, **kwargs):
try:
rc, out, err = module.run_command(args, **kwargs)
if rc != 0:
- module.fail_json(msg='error running gluster (%s) command (rc=%d): %s' % (' '.join(args), rc, out or err))
- except Exception:
- e = get_exception()
- module.fail_json(msg='error running gluster (%s) command: %s' % (' '.join(args), str(e)))
+ module.fail_json(msg='error running gluster (%s) command (rc=%d): %s' %
+ (' '.join(args), rc, out or err), exception=traceback.format_exc())
+ except Exception as e:
+ module.fail_json(msg='error running gluster (%s) command: %s' % (' '.join(args),
+ to_native(e)), exception=traceback.format_exc())
return out
def run_gluster_nofail(gargs, **kwargs):
@@ -226,7 +220,6 @@ def run_gluster_yes(gargs):
def get_peers():
out = run_gluster([ 'peer', 'status'])
- i = 0
peers = {}
hostname = None
uuid = None
@@ -319,7 +312,6 @@ def probe(host, myhostname):
out = run_gluster([ 'peer', 'probe', host ])
if out.find('localhost') == -1 and not wait_for_peer(host):
module.fail_json(msg='failed to probe peer %s on %s' % (host, myhostname))
- changed = True
def probe_all_peers(hosts, peers, myhostname):
for host in hosts:
@@ -543,5 +535,6 @@ def main():
module.exit_json(changed=changed, ansible_facts=facts)
+
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/system/group.py b/lib/ansible/modules/system/group.py
index 0e68a65321..b677e69570 100644
--- a/lib/ansible/modules/system/group.py
+++ b/lib/ansible/modules/system/group.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2012, Stephen Fromm
-#
-# 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 .
+# 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.0',
'status': ['stableinterface'],
@@ -66,7 +56,9 @@ EXAMPLES = '''
'''
import grp
-import platform
+
+from ansible.module_utils.basic import AnsibleModule, load_platform_subclass
+
class Group(object):
"""
@@ -355,7 +347,6 @@ class OpenBsdGroup(Group):
def group_mod(self, **kwargs):
cmd = [self.module.get_bin_path('groupmod', True)]
info = self.group_info()
- cmd_len = len(cmd)
if self.gid is not None and int(self.gid) != info[2]:
cmd.append('-g')
cmd.append('%d' % int(self.gid))
@@ -397,7 +388,6 @@ class NetBsdGroup(Group):
def group_mod(self, **kwargs):
cmd = [self.module.get_bin_path('groupmod', True)]
info = self.group_info()
- cmd_len = len(cmd)
if self.gid is not None and int(self.gid) != info[2]:
cmd.append('-g')
cmd.append('%d' % int(self.gid))
@@ -471,8 +461,6 @@ def main():
module.exit_json(**result)
-# import module snippets
-from ansible.module_utils.basic import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/system/hostname.py b/lib/ansible/modules/system/hostname.py
index 67a4ac373b..99db491f68 100644
--- a/lib/ansible/modules/system/hostname.py
+++ b/lib/ansible/modules/system/hostname.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2013, Hiroaki Nakamura
-#
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -48,13 +38,19 @@ EXAMPLES = '''
name: web01
'''
+import os
import socket
+import traceback
from distutils.version import LooseVersion
-# import module snippets
-from ansible.module_utils.basic import *
+from ansible.module_utils.basic import (AnsibleModule,
+ get_distribution,
+ get_distribution_version,
+ get_platform,
+ load_platform_subclass,
+ )
from ansible.module_utils.facts.system.service_mgr import ServiceMgrFactCollector
-from ansible.module_utils._text import to_bytes, to_native
+from ansible.module_utils._text import to_native
class UnimplementedStrategy(object):
@@ -203,20 +199,18 @@ class DebianStrategy(GenericStrategy):
if not os.path.isfile(self.HOSTNAME_FILE):
try:
open(self.HOSTNAME_FILE, "a").write("")
- except IOError:
- err = get_exception()
+ except IOError as e:
self.module.fail_json(msg="failed to write file: %s" %
- str(err))
+ to_native(e), exception=traceback.format_exc())
try:
f = open(self.HOSTNAME_FILE)
try:
return f.read().strip()
finally:
f.close()
- except Exception:
- err = get_exception()
+ except Exception as e:
self.module.fail_json(msg="failed to read hostname: %s" %
- str(err))
+ to_native(e), exception=traceback.format_exc())
def set_permanent_hostname(self, name):
try:
@@ -225,10 +219,9 @@ class DebianStrategy(GenericStrategy):
f.write("%s\n" % name)
finally:
f.close()
- except Exception:
- err = get_exception()
+ except Exception as e:
self.module.fail_json(msg="failed to update hostname: %s" %
- str(err))
+ to_native(e), exception=traceback.format_exc())
# ===========================================
@@ -243,20 +236,18 @@ class SLESStrategy(GenericStrategy):
if not os.path.isfile(self.HOSTNAME_FILE):
try:
open(self.HOSTNAME_FILE, "a").write("")
- except IOError:
- err = get_exception()
+ except IOError as e:
self.module.fail_json(msg="failed to write file: %s" %
- str(err))
+ to_native(e), exception=traceback.format_exc())
try:
f = open(self.HOSTNAME_FILE)
try:
return f.read().strip()
finally:
f.close()
- except Exception:
- err = get_exception()
+ except Exception as e:
self.module.fail_json(msg="failed to read hostname: %s" %
- str(err))
+ to_native(e), exception=traceback.format_exc())
def set_permanent_hostname(self, name):
try:
@@ -265,10 +256,9 @@ class SLESStrategy(GenericStrategy):
f.write("%s\n" % name)
finally:
f.close()
- except Exception:
- err = get_exception()
+ except Exception as e:
self.module.fail_json(msg="failed to update hostname: %s" %
- str(err))
+ to_native(e), exception=traceback.format_exc())
# ===========================================
@@ -289,10 +279,9 @@ class RedHatStrategy(GenericStrategy):
return v.strip()
finally:
f.close()
- except Exception:
- err = get_exception()
+ except Exception as e:
self.module.fail_json(msg="failed to read hostname: %s" %
- str(err))
+ to_native(e), exception=traceback.format_exc())
def set_permanent_hostname(self, name):
try:
@@ -315,10 +304,9 @@ class RedHatStrategy(GenericStrategy):
f.writelines(lines)
finally:
f.close()
- except Exception:
- err = get_exception()
+ except Exception as e:
self.module.fail_json(msg="failed to update hostname: %s" %
- str(err))
+ to_native(e), exception=traceback.format_exc())
# ===========================================
@@ -339,20 +327,18 @@ class AlpineStrategy(GenericStrategy):
if not os.path.isfile(self.HOSTNAME_FILE):
try:
open(self.HOSTNAME_FILE, "a").write("")
- except IOError:
- err = get_exception()
+ except IOError as e:
self.module.fail_json(msg="failed to write file: %s" %
- str(err))
+ to_native(e), exception=traceback.format_exc())
try:
f = open(self.HOSTNAME_FILE)
try:
return f.read().strip()
finally:
f.close()
- except Exception:
- err = get_exception()
+ except Exception as e:
self.module.fail_json(msg="failed to read hostname: %s" %
- str(err))
+ to_native(e), exception=traceback.format_exc())
def set_permanent_hostname(self, name):
try:
@@ -361,10 +347,9 @@ class AlpineStrategy(GenericStrategy):
f.write("%s\n" % name)
finally:
f.close()
- except Exception:
- err = get_exception()
+ except Exception as e:
self.module.fail_json(msg="failed to update hostname: %s" %
- str(err))
+ to_native(e), exception=traceback.format_exc())
def set_current_hostname(self, name):
cmd = [self.hostname_cmd, '-F', self.HOSTNAME_FILE]
@@ -440,9 +425,9 @@ class OpenRCStrategy(GenericStrategy):
line = line.strip()
if line.startswith('hostname='):
return line[10:].strip('"')
- except Exception:
- err = get_exception()
- self.module.fail_json(msg="failed to read hostname: %s" % str(err))
+ except Exception as e:
+ self.module.fail_json(msg="failed to read hostname: %s" %
+ to_native(e), exception=traceback.format_exc())
finally:
f.close()
@@ -462,9 +447,9 @@ class OpenRCStrategy(GenericStrategy):
f = open(self.HOSTNAME_FILE, 'w')
f.write('\n'.join(lines) + '\n')
- except Exception:
- err = get_exception()
- self.module.fail_json(msg="failed to update hostname: %s" % str(err))
+ except Exception as e:
+ self.module.fail_json(msg="failed to update hostname: %s" %
+ to_native(e), exception=traceback.format_exc())
finally:
f.close()
@@ -482,20 +467,18 @@ class OpenBSDStrategy(GenericStrategy):
if not os.path.isfile(self.HOSTNAME_FILE):
try:
open(self.HOSTNAME_FILE, "a").write("")
- except IOError:
- err = get_exception()
+ except IOError as e:
self.module.fail_json(msg="failed to write file: %s" %
- str(err))
+ to_native(e), exception=traceback.format_exc())
try:
f = open(self.HOSTNAME_FILE)
try:
return f.read().strip()
finally:
f.close()
- except Exception:
- err = get_exception()
+ except Exception as e:
self.module.fail_json(msg="failed to read hostname: %s" %
- str(err))
+ to_native(e), exception=traceback.format_exc())
def set_permanent_hostname(self, name):
try:
@@ -504,10 +487,9 @@ class OpenBSDStrategy(GenericStrategy):
f.write("%s\n" % name)
finally:
f.close()
- except Exception:
- err = get_exception()
+ except Exception as e:
self.module.fail_json(msg="failed to update hostname: %s" %
- str(err))
+ to_native(e), exception=traceback.format_exc())
# ===========================================
@@ -557,10 +539,9 @@ class FreeBSDStrategy(GenericStrategy):
if not os.path.isfile(self.HOSTNAME_FILE):
try:
open(self.HOSTNAME_FILE, "a").write("hostname=temporarystub\n")
- except IOError:
- err = get_exception()
+ except IOError as e:
self.module.fail_json(msg="failed to write file: %s" %
- str(err))
+ to_native(e), exception=traceback.format_exc())
try:
try:
f = open(self.HOSTNAME_FILE, 'r')
@@ -568,9 +549,9 @@ class FreeBSDStrategy(GenericStrategy):
line = line.strip()
if line.startswith('hostname='):
return line[10:].strip('"')
- except Exception:
- err = get_exception()
- self.module.fail_json(msg="failed to read hostname: %s" % str(err))
+ except Exception as e:
+ self.module.fail_json(msg="failed to read hostname: %s" %
+ to_native(e), exception=traceback.format_exc())
finally:
f.close()
@@ -590,9 +571,9 @@ class FreeBSDStrategy(GenericStrategy):
f = open(self.HOSTNAME_FILE, 'w')
f.write('\n'.join(lines) + '\n')
- except Exception:
- err = get_exception()
- self.module.fail_json(msg="failed to update hostname: %s" % str(err))
+ except Exception as e:
+ self.module.fail_json(msg="failed to update hostname: %s" %
+ to_native(e), exception=traceback.format_exc())
finally:
f.close()
@@ -772,5 +753,6 @@ def main():
ansible_fqdn=socket.getfqdn(),
ansible_domain='.'.join(socket.getfqdn().split('.')[1:])))
+
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/system/iptables.py b/lib/ansible/modules/system/iptables.py
index 7a857fe479..fe905a74a3 100644
--- a/lib/ansible/modules/system/iptables.py
+++ b/lib/ansible/modules/system/iptables.py
@@ -2,31 +2,11 @@
# -*- coding: utf-8 -*-
#
# (c) 2015, Linus Unnebäck
-#
-# This file is part of Ansible
-#
-# 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
-# the Free Software Foundation, either version 3 of the License, or
-# (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 .
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-BINS = dict(
- ipv4='iptables',
- ipv6='ip6tables',
-)
+from __future__ import absolute_import, division, print_function
+__metaclass__ = type
-ICMP_TYPE_OPTIONS = dict(
- ipv4='--icmp-type',
- ipv6='--icmpv6-type',
-)
ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'],
@@ -355,9 +335,20 @@ EXAMPLES = '''
import re
-# import module snippets
from ansible.module_utils.basic import AnsibleModule
+
+BINS = dict(
+ ipv4='iptables',
+ ipv6='ip6tables',
+)
+
+ICMP_TYPE_OPTIONS = dict(
+ ipv4='--icmp-type',
+ ipv6='--icmpv6-type',
+)
+
+
def append_param(rule, param, flag, is_list):
if is_list:
for item in param:
diff --git a/lib/ansible/modules/system/java_cert.py b/lib/ansible/modules/system/java_cert.py
index 5e65777519..74a7ae812f 100644
--- a/lib/ansible/modules/system/java_cert.py
+++ b/lib/ansible/modules/system/java_cert.py
@@ -1,21 +1,11 @@
#!/usr/bin/python
#
# (c) 2013, RSD Services S.A
-#
-# 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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/system/kernel_blacklist.py b/lib/ansible/modules/system/kernel_blacklist.py
index 14fdaae8b0..cc8d5efc1f 100644
--- a/lib/ansible/modules/system/kernel_blacklist.py
+++ b/lib/ansible/modules/system/kernel_blacklist.py
@@ -2,21 +2,11 @@
# encoding: utf-8 -*-
# (c) 2013, Matthias Vogelgesang
-#
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -61,6 +51,8 @@ EXAMPLES = '''
import os
import re
+from ansible.module_utils.basic import AnsibleModule
+
class Blacklist(object):
def __init__(self, module, filename, checkmode):
@@ -163,8 +155,6 @@ def main():
module.exit_json(**args)
-# import module snippets
-from ansible.module_utils.basic import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/system/known_hosts.py b/lib/ansible/modules/system/known_hosts.py
index bc50f78113..e50663d60a 100644
--- a/lib/ansible/modules/system/known_hosts.py
+++ b/lib/ansible/modules/system/known_hosts.py
@@ -1,22 +1,11 @@
#!/usr/bin/python
-"""
-Ansible module to manage the ssh known_hosts file.
-Copyright(c) 2014, Matthew Vernon
+# Copyright(c) 2014, Matthew Vernon
+# 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
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
+from __future__ import absolute_import, division, print_function
+__metaclass__ = type
-This module 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 module. If not, see .
-"""
ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/system/locale_gen.py b/lib/ansible/modules/system/locale_gen.py
index 902fffd165..3cad57e67d 100644
--- a/lib/ansible/modules/system/locale_gen.py
+++ b/lib/ansible/modules/system/locale_gen.py
@@ -1,20 +1,11 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
-# 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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/system/lvg.py b/lib/ansible/modules/system/lvg.py
index ea89b419d3..0fdd9529ef 100644
--- a/lib/ansible/modules/system/lvg.py
+++ b/lib/ansible/modules/system/lvg.py
@@ -3,21 +3,11 @@
# (c) 2013, Alexander Bulimov
# based on lvol module by Jeroen Hoekx
-#
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -90,6 +80,10 @@ EXAMPLES = '''
vg: vg.services
state: absent
'''
+import os
+
+from ansible.module_utils.basic import AnsibleModule
+
def parse_vgs(data):
vgs = []
@@ -263,8 +257,6 @@ def main():
module.exit_json(changed=changed)
-# import module snippets
-from ansible.module_utils.basic import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/system/lvol.py b/lib/ansible/modules/system/lvol.py
index 2b410c4b6f..a9a4524ab9 100644
--- a/lib/ansible/modules/system/lvol.py
+++ b/lib/ansible/modules/system/lvol.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2013, Jeroen Hoekx , Alexander Bulimov
-#
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -204,8 +194,12 @@ EXAMPLES = '''
import re
+from ansible.module_utils.basic import AnsibleModule
+
+
decimal_point = re.compile(r"(\d+)")
+
def mkversion(major, minor, patch):
return (1000 * 1000 * int(major)) + (1000 * int(minor)) + int(patch)
@@ -493,8 +487,6 @@ def main():
module.exit_json(changed=changed, msg=msg)
-# import module snippets
-from ansible.module_utils.basic import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/system/make.py b/lib/ansible/modules/system/make.py
index 6a760c7e64..3aef1f4d57 100644
--- a/lib/ansible/modules/system/make.py
+++ b/lib/ansible/modules/system/make.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2015, Linus Unnebäck
-#
-# This file is part of Ansible
-#
-# 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
-# the Free Software Foundation, either version 3 of the License, or
-# (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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/system/modprobe.py b/lib/ansible/modules/system/modprobe.py
index b2d7f95f94..ffc3eca38a 100644
--- a/lib/ansible/modules/system/modprobe.py
+++ b/lib/ansible/modules/system/modprobe.py
@@ -2,21 +2,10 @@
#coding: utf-8 -*-
# (c) 2013, David Stygstra
-#
-# This file is part of Ansible
-#
-# 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
-# the Free Software Foundation, either version 3 of the License, or
-# (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 .
+# 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.0',
@@ -68,9 +57,11 @@ EXAMPLES = '''
params: 'numdummies=2'
'''
-from ansible.module_utils.basic import *
-from ansible.module_utils.pycompat24 import get_exception
import shlex
+import traceback
+
+from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils._text import to_native
def main():
@@ -100,9 +91,8 @@ def main():
present = True
break
modules.close()
- except IOError:
- e = get_exception()
- module.fail_json(msg=str(e), **args)
+ except IOError as e:
+ module.fail_json(msg=to_native(e), exception=traceback.format_exc(), **args)
# Check only; don't modify
if module.check_mode:
@@ -132,5 +122,6 @@ def main():
module.exit_json(**args)
+
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/system/mount.py b/lib/ansible/modules/system/mount.py
index 6ca86408c2..10764d6747 100644
--- a/lib/ansible/modules/system/mount.py
+++ b/lib/ansible/modules/system/mount.py
@@ -4,21 +4,10 @@
# (c) 2012, Red Hat, inc
# Written by Seth Vidal
# based on the mount modules from salt and puppet
-#
-# 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 .
+# 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.0',
diff --git a/lib/ansible/modules/system/ohai.py b/lib/ansible/modules/system/ohai.py
index 6135ccb6d8..ca95513c02 100644
--- a/lib/ansible/modules/system/ohai.py
+++ b/lib/ansible/modules/system/ohai.py
@@ -2,22 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2012, Michael DeHaan
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
@@ -46,6 +35,10 @@ EXAMPLES = '''
# Retrieve (ohai) data from all Web servers and store in one-file per host
ansible webservers -m ohai --tree=/tmp/ohaidata
'''
+import json
+
+from ansible.module_utils.basic import AnsibleModule
+
def main():
module = AnsibleModule(
@@ -55,8 +48,6 @@ def main():
rc, out, err = module.run_command(cmd, check_rc=True)
module.exit_json(**json.loads(out))
-# import module snippets
-from ansible.module_utils.basic import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/system/open_iscsi.py b/lib/ansible/modules/system/open_iscsi.py
index 2e1574dcea..065f6d5dc3 100644
--- a/lib/ansible/modules/system/open_iscsi.py
+++ b/lib/ansible/modules/system/open_iscsi.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2013, Serge van Ginderachter
-#
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -118,8 +108,12 @@ EXAMPLES = '''
'''
import glob
+import os
import time
+from ansible.module_utils.basic import AnsibleModule
+
+
ISCSIADM = 'iscsiadm'
@@ -383,8 +377,5 @@ def main():
module.exit_json(**result)
-# import module snippets
-from ansible.module_utils.basic import *
-
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/system/openwrt_init.py b/lib/ansible/modules/system/openwrt_init.py
index 858a7f10dc..20a9be545d 100644
--- a/lib/ansible/modules/system/openwrt_init.py
+++ b/lib/ansible/modules/system/openwrt_init.py
@@ -1,21 +1,11 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2016, Andrew Gaffney
-#
-# 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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/system/osx_defaults.py b/lib/ansible/modules/system/osx_defaults.py
index b53e5aadc8..b1358c0c6a 100644
--- a/lib/ansible/modules/system/osx_defaults.py
+++ b/lib/ansible/modules/system/osx_defaults.py
@@ -2,19 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2014, GeekChimp - Franck Nijhof
-#
-# 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 .
+# 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.0',
'status': ['stableinterface'],
diff --git a/lib/ansible/modules/system/pam_limits.py b/lib/ansible/modules/system/pam_limits.py
index f524126744..2977ef3468 100644
--- a/lib/ansible/modules/system/pam_limits.py
+++ b/lib/ansible/modules/system/pam_limits.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2014, Sebastien Rohaut
-#
-# 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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/system/pamd.py b/lib/ansible/modules/system/pamd.py
index d1d9a3615d..1f72dfa92c 100644
--- a/lib/ansible/modules/system/pamd.py
+++ b/lib/ansible/modules/system/pamd.py
@@ -1,21 +1,11 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2016, Kenneth D. Evensen
-#
-# This file is part of Ansible (sort of)
-#
-# 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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/system/parted.py b/lib/ansible/modules/system/parted.py
index 632aad118d..faaec7ab29 100644
--- a/lib/ansible/modules/system/parted.py
+++ b/lib/ansible/modules/system/parted.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2016, Fabrizio Colonna
-#
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -355,7 +345,7 @@ def format_disk_size(size_bytes, unit):
elif unit in units_iec:
multiplier = 1024.0 ** units_iec.index(unit)
- output = size_bytes / multiplier * (1 + 1E-16)
+ output = size_bytes // multiplier * (1 + 1E-16)
# Corrections to round up as per IEEE754 standard
if output < 10:
diff --git a/lib/ansible/modules/system/ping.py b/lib/ansible/modules/system/ping.py
index 9b0a61b92d..9b9fdda9a5 100644
--- a/lib/ansible/modules/system/ping.py
+++ b/lib/ansible/modules/system/ping.py
@@ -3,21 +3,10 @@
# (c) 2012, Michael DeHaan
# (c) 2016, Toshio Kuratomi
-#
-# 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 .
+# 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.0',
diff --git a/lib/ansible/modules/system/puppet.py b/lib/ansible/modules/system/puppet.py
index 7d33ea43e2..c147407334 100644
--- a/lib/ansible/modules/system/puppet.py
+++ b/lib/ansible/modules/system/puppet.py
@@ -1,19 +1,11 @@
#!/usr/bin/python
# Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
-#
-# 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
-# the Free Software Foundation, either version 3 of the License, or
-# (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 .
+# 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.0',
'status': ['stableinterface'],
@@ -120,18 +112,12 @@ EXAMPLES = '''
tags: update,nginx
'''
+import json
import os
import pipes
import stat
-try:
- 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
+from ansible.module_utils.basic import AnsibleModule
def _get_facter_dir():
@@ -295,8 +281,6 @@ def main():
rc=rc, msg="%s failed with return code: %d" % (cmd, rc),
stdout=stdout, stderr=stderr)
-# import module snippets
-from ansible.module_utils.basic import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/system/runit.py b/lib/ansible/modules/system/runit.py
index c30b675f5f..9a03eb1b4d 100644
--- a/lib/ansible/modules/system/runit.py
+++ b/lib/ansible/modules/system/runit.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
#
# (c) 2015, Brian Coca
-#
-# 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
+# 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.0',
'status': ['stableinterface'],
@@ -98,10 +88,13 @@ EXAMPLES = '''
service_dir: /run/service
'''
-import platform
-import shlex
-from ansible.module_utils.pycompat24 import get_exception
-from ansible.module_utils.basic import *
+import os
+import re
+import traceback
+
+from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils._text import to_native
+
def _load_dist_subclass(cls, *args, **kwargs):
'''
@@ -164,9 +157,8 @@ class Sv(object):
if os.path.exists(self.src_full):
try:
os.symlink(self.src_full, self.svc_full)
- except OSError:
- e = get_exception()
- self.module.fail_json(path=self.src_full, msg='Error while linking: %s' % str(e))
+ except OSError as e:
+ self.module.fail_json(path=self.src_full, msg='Error while linking: %s' % to_native(e))
else:
self.module.fail_json(msg="Could not find source for service to enable (%s)." % self.src_full)
@@ -174,9 +166,8 @@ class Sv(object):
self.execute_command([self.svc_cmd,'force-stop',self.src_full])
try:
os.unlink(self.svc_full)
- except OSError:
- e = get_exception()
- self.module.fail_json(path=self.svc_full, msg='Error while unlinking: %s' % str(e))
+ except OSError as e:
+ self.module.fail_json(path=self.svc_full, msg='Error while unlinking: %s' % to_native(e))
def get_status(self):
(rc, out, err) = self.execute_command([self.svstat_cmd, 'status', self.svc_full])
@@ -238,9 +229,8 @@ class Sv(object):
def execute_command(self, cmd):
try:
(rc, out, err) = self.module.run_command(' '.join(cmd))
- except Exception:
- e = get_exception()
- self.module.fail_json(msg="failed to execute: %s" % str(e))
+ except Exception as e:
+ self.module.fail_json(msg="failed to execute: %s" % to_native(e), exception=traceback.format_exc())
return (rc, out, err)
def report(self):
@@ -283,9 +273,8 @@ def main():
sv.enable()
else:
sv.disable()
- except (OSError, IOError):
- e = get_exception()
- module.fail_json(msg="Could not change service link: %s" % str(e))
+ except (OSError, IOError) as e:
+ module.fail_json(msg="Could not change service link: %s" % to_native(e), exception=traceback.format_exc())
if state is not None and state != sv.state:
changed = True
@@ -295,7 +284,5 @@ def main():
module.exit_json(changed=changed, sv=sv.report())
-
-
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/system/seboolean.py b/lib/ansible/modules/system/seboolean.py
index 833456e10a..d9c02cce35 100644
--- a/lib/ansible/modules/system/seboolean.py
+++ b/lib/ansible/modules/system/seboolean.py
@@ -1,21 +1,11 @@
#!/usr/bin/python
# (c) 2012, Stephen Fromm
-#
-# 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 .
+# 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.0',
'status': ['stableinterface'],
diff --git a/lib/ansible/modules/system/sefcontext.py b/lib/ansible/modules/system/sefcontext.py
index ab26e56e0a..af18740fb9 100644
--- a/lib/ansible/modules/system/sefcontext.py
+++ b/lib/ansible/modules/system/sefcontext.py
@@ -1,21 +1,11 @@
#!/usr/bin/python
# (c) 2016, Dag Wieers
-#
-# 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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/system/selinux.py b/lib/ansible/modules/system/selinux.py
index e705ba8806..c5f9fa795d 100644
--- a/lib/ansible/modules/system/selinux.py
+++ b/lib/ansible/modules/system/selinux.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2012, Derek Carter
-#
-# 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 .
+# 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.0',
'status': ['stableinterface'],
diff --git a/lib/ansible/modules/system/selinux_permissive.py b/lib/ansible/modules/system/selinux_permissive.py
index 75291925ef..2668dc7358 100644
--- a/lib/ansible/modules/system/selinux_permissive.py
+++ b/lib/ansible/modules/system/selinux_permissive.py
@@ -3,21 +3,11 @@
# (c) 2015, Michael Scherer
# inspired by code of github.com/dandiker/
-#
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -66,14 +56,17 @@ EXAMPLES = '''
permissive: true
'''
+import traceback
+
HAVE_SEOBJECT = False
try:
import seobject
HAVE_SEOBJECT = True
except ImportError:
pass
-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._text import to_native
def main():
@@ -99,9 +92,8 @@ def main():
try:
permissive_domains = seobject.permissiveRecords(store)
- except ValueError:
- e = get_exception()
- module.fail_json(domain=domain, msg=str(e))
+ except ValueError as e:
+ module.fail_json(domain=domain, msg=to_native(e), exception=traceback.format_exc())
# not supported on EL 6
if 'set_reload' in dir(permissive_domains):
@@ -109,27 +101,24 @@ def main():
try:
all_domains = permissive_domains.get_all()
- except ValueError:
- e = get_exception()
- module.fail_json(domain=domain, msg=str(e))
+ except ValueError as e:
+ module.fail_json(domain=domain, msg=to_native(e), exception=traceback.format_exc())
if permissive:
if domain not in all_domains:
if not module.check_mode:
try:
permissive_domains.add(domain)
- except ValueError:
- e = get_exception()
- module.fail_json(domain=domain, msg=str(e))
+ except ValueError as e:
+ module.fail_json(domain=domain, msg=to_native(e), exception=traceback.format_exc())
changed = True
else:
if domain in all_domains:
if not module.check_mode:
try:
permissive_domains.delete(domain)
- except ValueError:
- e = get_exception()
- module.fail_json(domain=domain, msg=str(e))
+ except ValueError as e:
+ module.fail_json(domain=domain, msg=to_native(e), exception=traceback.format_exc())
changed = True
module.exit_json(changed=changed, store=store,
diff --git a/lib/ansible/modules/system/seport.py b/lib/ansible/modules/system/seport.py
index 0fd12cf1e1..34d84e84d1 100644
--- a/lib/ansible/modules/system/seport.py
+++ b/lib/ansible/modules/system/seport.py
@@ -1,21 +1,11 @@
#!/usr/bin/python
# (c) 2014, Dan Keder
-#
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -87,6 +77,8 @@ EXAMPLES = '''
state: present
'''
+import traceback
+
try:
import selinux
HAVE_SELINUX=True
@@ -99,8 +91,8 @@ try:
except ImportError:
HAVE_SEOBJECT=False
-from ansible.module_utils.basic import *
-from ansible.module_utils.pycompat24 import get_exception
+from ansible.module_utils.basic import AnsibleModule, HAVE_SELINUX
+from ansible.module_utils._text import to_native
def semanage_port_get_ports(seport, setype, proto):
@@ -191,21 +183,8 @@ def semanage_port_add(module, ports, proto, setype, do_reload, serange='s0', ses
elif port_type is not None and not module.check_mode:
seport.modify(port, proto, serange, setype)
- except ValueError:
- e = get_exception()
- module.fail_json(msg="%s: %s\n" % (e.__class__.__name__, str(e)))
- except IOError:
- e = get_exception()
- module.fail_json(msg="%s: %s\n" % (e.__class__.__name__, str(e)))
- except KeyError:
- e = get_exception()
- module.fail_json(msg="%s: %s\n" % (e.__class__.__name__, str(e)))
- except OSError:
- e = get_exception()
- module.fail_json(msg="%s: %s\n" % (e.__class__.__name__, str(e)))
- except RuntimeError:
- e = get_exception()
- module.fail_json(msg="%s: %s\n" % (e.__class__.__name__, str(e)))
+ except (ValueError, IOError, KeyError, OSError, RuntimeError) as e:
+ module.fail_json(msg="%s: %s\n" % (e.__class__.__name__, to_native(e)), exception=traceback.format_exc())
return change
@@ -245,21 +224,8 @@ def semanage_port_del(module, ports, proto, setype, do_reload, sestore=''):
if not module.check_mode:
seport.delete(port, proto)
- except ValueError:
- e = get_exception()
- module.fail_json(msg="%s: %s\n" % (e.__class__.__name__, str(e)))
- except IOError:
- e = get_exception()
- module.fail_json(msg="%s: %s\n" % (e.__class__.__name__, str(e)))
- except KeyError:
- e = get_exception()
- module.fail_json(msg="%s: %s\n" % (e.__class__.__name__, str(e)))
- except OSError:
- e = get_exception()
- module.fail_json(msg="%s: %s\n" % (e.__class__.__name__, str(e)))
- except RuntimeError:
- e = get_exception()
- module.fail_json(msg="%s: %s\n" % (e.__class__.__name__, str(e)))
+ except (ValueError, IOError, KeyError, OSError, RuntimeError) as e:
+ module.fail_json(msg="%s: %s\n" % (e.__class__.__name__, to_native(e)), exception=traceback.format_exc())
return change
diff --git a/lib/ansible/modules/system/service.py b/lib/ansible/modules/system/service.py
index 8f27cb97ab..0afe11cce7 100644
--- a/lib/ansible/modules/system/service.py
+++ b/lib/ansible/modules/system/service.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2012, Michael DeHaan
-#
-# 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 .
+# 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.0',
'status': ['stableinterface'],
diff --git a/lib/ansible/modules/system/setup.py b/lib/ansible/modules/system/setup.py
index e194783edb..346b557700 100644
--- a/lib/ansible/modules/system/setup.py
+++ b/lib/ansible/modules/system/setup.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2012, Michael DeHaan
-#
-# 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 .
+# 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.0',
'status': ['stableinterface'],
diff --git a/lib/ansible/modules/system/solaris_zone.py b/lib/ansible/modules/system/solaris_zone.py
index fcebcb80d1..548a4d4ee6 100644
--- a/lib/ansible/modules/system/solaris_zone.py
+++ b/lib/ansible/modules/system/solaris_zone.py
@@ -1,21 +1,11 @@
#!/usr/bin/python
# (c) 2015, Paul Markham
-#
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -155,10 +145,12 @@ EXAMPLES = '''
attach_options: -u
'''
-import sys
import os
import platform
import tempfile
+import time
+
+from ansible.module_utils.basic import AnsibleModule
class Zone(object):
@@ -482,7 +474,6 @@ def main():
module.exit_json(changed=zone.changed, msg=', '.join(zone.msg))
-from ansible.module_utils.basic import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/system/svc.py b/lib/ansible/modules/system/svc.py
index c26bc563c5..445462b4e2 100644
--- a/lib/ansible/modules/system/svc.py
+++ b/lib/ansible/modules/system/svc.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
#
# (c) 2015, Brian Coca
-#
-# 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
+# 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.0',
'status': ['stableinterface'],
@@ -103,10 +93,13 @@ EXAMPLES = '''
service_dir: /var/service
'''
-import platform
-import shlex
-from ansible.module_utils.pycompat24 import get_exception
-from ansible.module_utils.basic import *
+import os
+import re
+import traceback
+
+from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils._text import to_native
+
def _load_dist_subclass(cls, *args, **kwargs):
'''
@@ -172,18 +165,16 @@ class Svc(object):
if os.path.exists(self.src_full):
try:
os.symlink(self.src_full, self.svc_full)
- except OSError:
- e = get_exception()
- self.module.fail_json(path=self.src_full, msg='Error while linking: %s' % str(e))
+ except OSError as e:
+ self.module.fail_json(path=self.src_full, msg='Error while linking: %s' % to_native(e))
else:
self.module.fail_json(msg="Could not find source for service to enable (%s)." % self.src_full)
def disable(self):
try:
os.unlink(self.svc_full)
- except OSError:
- e = get_exception()
- self.module.fail_json(path=self.svc_full, msg='Error while unlinking: %s' % str(e))
+ except OSError as e:
+ self.module.fail_json(path=self.svc_full, msg='Error while unlinking: %s' % to_native(e))
self.execute_command([self.svc_cmd,'-dx',self.src_full])
src_log = '%s/log' % self.src_full
@@ -243,9 +234,8 @@ class Svc(object):
def execute_command(self, cmd):
try:
(rc, out, err) = self.module.run_command(' '.join(cmd))
- except Exception:
- e = get_exception()
- self.module.fail_json(msg="failed to execute: %s" % str(e))
+ except Exception as e:
+ self.module.fail_json(msg="failed to execute: %s" % to_native(e), exception=traceback.format_exc())
return (rc, out, err)
def report(self):
@@ -290,9 +280,8 @@ def main():
svc.enable()
else:
svc.disable()
- except (OSError, IOError):
- e = get_exception()
- module.fail_json(msg="Could change service link: %s" % str(e))
+ except (OSError, IOError) as e:
+ module.fail_json(msg="Could change service link: %s" % to_native(e))
if state is not None and state != svc.state:
changed = True
@@ -308,9 +297,8 @@ def main():
open(d_file, "a").close()
else:
os.unlink(d_file)
- except (OSError, IOError):
- e = get_exception()
- module.fail_json(msg="Could change downed file: %s " % (str(e)))
+ except (OSError, IOError) as e:
+ module.fail_json(msg="Could change downed file: %s " % (to_native(e)))
module.exit_json(changed=changed, svc=svc.report())
diff --git a/lib/ansible/modules/system/sysctl.py b/lib/ansible/modules/system/sysctl.py
index 78fe8572c9..e259a955fe 100644
--- a/lib/ansible/modules/system/sysctl.py
+++ b/lib/ansible/modules/system/sysctl.py
@@ -3,22 +3,11 @@
# (c) 2012, David "DaviXX" CHANIAL
# (c) 2014, James Tanner
-#
-# 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 .
-#
+# 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.0',
'status': ['stableinterface'],
diff --git a/lib/ansible/modules/system/systemd.py b/lib/ansible/modules/system/systemd.py
index a35d2bccb5..c3604ff6c5 100644
--- a/lib/ansible/modules/system/systemd.py
+++ b/lib/ansible/modules/system/systemd.py
@@ -1,21 +1,11 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2016, Brian Coca
-#
-# 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 .
+# 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.0',
'status': ['stableinterface'],
diff --git a/lib/ansible/modules/system/timezone.py b/lib/ansible/modules/system/timezone.py
index 652fe93298..3a26700e9d 100644
--- a/lib/ansible/modules/system/timezone.py
+++ b/lib/ansible/modules/system/timezone.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2016, Shinichi TAMURA (@tmshn)
-#
-# 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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/system/ufw.py b/lib/ansible/modules/system/ufw.py
index 797b28dcb6..705dde7dc6 100644
--- a/lib/ansible/modules/system/ufw.py
+++ b/lib/ansible/modules/system/ufw.py
@@ -6,20 +6,11 @@
# (c) 2013, Aleksey Ovcharenko
# (c) 2013, James Martin
#
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -235,8 +226,11 @@ EXAMPLES = '''
dest: 4.5.6.0/24
'''
+import re
from operator import itemgetter
+from ansible.module_utils.basic import AnsibleModule
+
def main():
module = AnsibleModule(
@@ -370,8 +364,6 @@ def main():
return module.exit_json(changed=changed, commands=cmds, msg=post_state.rstrip())
-# import module snippets
-from ansible.module_utils.basic import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/system/user.py b/lib/ansible/modules/system/user.py
index cbaf5b9b4f..1ec325f532 100644
--- a/lib/ansible/modules/system/user.py
+++ b/lib/ansible/modules/system/user.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2012, Stephen Fromm
-#
-# 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 .
+# 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.0',
'status': ['stableinterface'],
@@ -809,7 +799,7 @@ class FreeBsdUser(User):
cmd.append(self.login_class)
if self.expires:
- days =( time.mktime(self.expires) - time.time() ) / 86400
+ days =( time.mktime(self.expires) - time.time() ) // 86400
cmd.append('-e')
cmd.append(str(int(days)))
@@ -907,7 +897,7 @@ class FreeBsdUser(User):
cmd.append(','.join(new_groups))
if self.expires:
- days = ( time.mktime(self.expires) - time.time() ) / 86400
+ days = ( time.mktime(self.expires) - time.time() ) // 86400
cmd.append('-e')
cmd.append(str(int(days)))
@@ -1363,7 +1353,7 @@ class SunOS(User):
lines.append(line)
continue
fields[1] = self.password
- fields[2] = str(int(time.time() / 86400))
+ fields[2] = str(int(time.time() // 86400))
if minweeks:
fields[3] = str(int(minweeks) * 7)
if maxweeks:
@@ -1457,7 +1447,7 @@ class SunOS(User):
lines.append(line)
continue
fields[1] = self.password
- fields[2] = str(int(time.time() / 86400))
+ fields[2] = str(int(time.time() // 86400))
if minweeks:
fields[3] = str(int(minweeks) * 7)
if maxweeks:
diff --git a/lib/ansible/modules/utilities/helper/_accelerate.py b/lib/ansible/modules/utilities/helper/_accelerate.py
index 54e3406b96..325b85f5cd 100644
--- a/lib/ansible/modules/utilities/helper/_accelerate.py
+++ b/lib/ansible/modules/utilities/helper/_accelerate.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2013, James Cammarata
-#
-# 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 .
+# 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.0',
'status': ['deprecated'],
@@ -109,7 +99,7 @@ from threading import Thread, Lock
# import module snippets
# we must import this here at the top so we can use get_module_path()
-from ansible.module_utils.basic import *
+from ansible.module_utils.basic import AnsibleModule, get_module_path
# the chunk size to read and send, assuming mtu 1500 and
# leaving room for base64 (+33%) encoding and header (100 bytes)
@@ -172,8 +162,7 @@ def daemonize_self(module, password, port, minutes, pid_file):
vvv("exiting pid %s" % pid)
# exit first parent
module.exit_json(msg="daemonized accelerate on port %s for %s minutes with pid %s" % (port, minutes, str(pid)))
- except OSError:
- e = get_exception()
+ except OSError as e:
message = "fork #1 failed: %d (%s)" % (e.errno, e.strerror)
module.fail_json(msg=message)
@@ -192,8 +181,7 @@ def daemonize_self(module, password, port, minutes, pid_file):
pid_file.close()
vvv("pid file written")
sys.exit(0)
- except OSError:
- e = get_exception()
+ except OSError as e:
log('fork #2 failed: %d (%s)' % (e.errno, e.strerror))
sys.exit(1)
@@ -266,8 +254,7 @@ class LocalSocketThread(Thread):
self.server.last_event = datetime.datetime.now()
finally:
self.server.last_event_lock.release()
- except Exception:
- e = get_exception()
+ except Exception as e:
vv("key loaded locally was invalid, ignoring (%s)" % e)
conn.sendall("BADKEY\n")
finally:
@@ -527,8 +514,7 @@ class ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler):
if response.get('failed',False):
log("got a failed response from the master")
return dict(failed=True, stderr="Master reported failure, aborting transfer")
- except Exception:
- e = get_exception()
+ except Exception as e:
fd.close()
tb = traceback.format_exc()
log("failed to fetch the file: %s" % tb)
@@ -626,8 +612,7 @@ def daemonize(module, password, port, timeout, minutes, use_ipv6, pid_file):
server = ThreadedTCPServer(address, ThreadedTCPRequestHandler, module, password, timeout, use_ipv6=use_ipv6)
server.allow_reuse_address = True
break
- except Exception:
- e = get_exception()
+ except Exception as e:
vv("Failed to create the TCP server (tries left = %d) (error: %s) " % (tries,e))
tries -= 1
time.sleep(0.2)
@@ -650,8 +635,7 @@ def daemonize(module, password, port, timeout, minutes, use_ipv6, pid_file):
v("server thread terminated, exiting!")
sys.exit(0)
- except Exception:
- e = get_exception()
+ except Exception as e:
tb = traceback.format_exc()
log("exception caught, exiting accelerated mode: %s\n%s" % (e, tb))
sys.exit(0)
@@ -697,8 +681,7 @@ def main():
# process, other than tell the calling program
# whether other signals can be sent
os.kill(daemon_pid, 0)
- except OSError:
- e = get_exception()
+ except OSError as e:
message = 'the accelerate daemon appears to be running'
message += 'as a different user that this user cannot access'
message += 'pid=%s' % daemon_pid
diff --git a/lib/ansible/modules/utilities/helper/meta.py b/lib/ansible/modules/utilities/helper/meta.py
index 00ed8943d6..9709cbc41e 100644
--- a/lib/ansible/modules/utilities/helper/meta.py
+++ b/lib/ansible/modules/utilities/helper/meta.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2016, Ansible, a Red Hat company
-#
-# 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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/utilities/logic/assert.py b/lib/ansible/modules/utilities/logic/assert.py
index 3aceaf1e32..70fb4802da 100644
--- a/lib/ansible/modules/utilities/logic/assert.py
+++ b/lib/ansible/modules/utilities/logic/assert.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# Copyright 2012 Dag Wieers
-#
-# 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 .
+# 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.0',
'status': ['stableinterface'],
diff --git a/lib/ansible/modules/utilities/logic/async_status.py b/lib/ansible/modules/utilities/logic/async_status.py
index 409b212d24..6c7c248a29 100644
--- a/lib/ansible/modules/utilities/logic/async_status.py
+++ b/lib/ansible/modules/utilities/logic/async_status.py
@@ -2,22 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2012, Michael DeHaan , and others
-#
-# 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 .
-#
+# 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.0',
'status': ['stableinterface'],
@@ -51,10 +40,13 @@ author:
- "Michael DeHaan"
'''
-import datetime
-import traceback
+import json
+import os
+
+from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six import iteritems
+
def main():
module = AnsibleModule(argument_spec=dict(
@@ -103,8 +95,6 @@ def main():
module.exit_json(**data)
-# import module snippets
-from ansible.module_utils.basic import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/utilities/logic/async_wrapper.py b/lib/ansible/modules/utilities/logic/async_wrapper.py
index a1f493c17a..db18c944eb 100644
--- a/lib/ansible/modules/utilities/logic/async_wrapper.py
+++ b/lib/ansible/modules/utilities/logic/async_wrapper.py
@@ -2,22 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2012, Michael DeHaan , and others
-#
-# 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 .
-#
+# 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
+
try:
import json
diff --git a/lib/ansible/modules/utilities/logic/debug.py b/lib/ansible/modules/utilities/logic/debug.py
index ba79138062..9b7ec37217 100644
--- a/lib/ansible/modules/utilities/logic/debug.py
+++ b/lib/ansible/modules/utilities/logic/debug.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# Copyright 2012 Dag Wieers
-#
-# 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 .
+# 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.0',
'status': ['stableinterface'],
diff --git a/lib/ansible/modules/utilities/logic/fail.py b/lib/ansible/modules/utilities/logic/fail.py
index 09d60c75ab..03212d625d 100644
--- a/lib/ansible/modules/utilities/logic/fail.py
+++ b/lib/ansible/modules/utilities/logic/fail.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# Copyright 2012 Dag Wieers
-#
-# 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 .
+# 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.0',
'status': ['stableinterface'],
diff --git a/lib/ansible/modules/utilities/logic/include.py b/lib/ansible/modules/utilities/logic/include.py
index 9010809cc8..7509e4ba05 100644
--- a/lib/ansible/modules/utilities/logic/include.py
+++ b/lib/ansible/modules/utilities/logic/include.py
@@ -1,12 +1,11 @@
#!/usr/bin/python
-# -*- mode: python -*-
-# 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 .
+# -*- 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/utilities/logic/include_role.py b/lib/ansible/modules/utilities/logic/include_role.py
index 01ae3bcf8d..2a1496fc40 100644
--- a/lib/ansible/modules/utilities/logic/include_role.py
+++ b/lib/ansible/modules/utilities/logic/include_role.py
@@ -1,12 +1,11 @@
#!/usr/bin/python
-# -*- mode: python -*-
-# 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 .
+# -*- 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/utilities/logic/include_vars.py b/lib/ansible/modules/utilities/logic/include_vars.py
index 17f4303d98..71a8add59b 100644
--- a/lib/ansible/modules/utilities/logic/include_vars.py
+++ b/lib/ansible/modules/utilities/logic/include_vars.py
@@ -1,12 +1,9 @@
-# -*- mode: python -*-
+# -*- coding: utf-8 -*-
+# 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 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 .
ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['stableinterface'],
diff --git a/lib/ansible/modules/utilities/logic/pause.py b/lib/ansible/modules/utilities/logic/pause.py
index 7e577faba9..0ed75127ff 100644
--- a/lib/ansible/modules/utilities/logic/pause.py
+++ b/lib/ansible/modules/utilities/logic/pause.py
@@ -1,19 +1,9 @@
-# -*- mode: python -*-
+# -*- coding: utf-8 -*-
+# 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 .
ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['stableinterface'],
diff --git a/lib/ansible/modules/utilities/logic/set_fact.py b/lib/ansible/modules/utilities/logic/set_fact.py
index 3c7f4b300d..d8c3d83600 100644
--- a/lib/ansible/modules/utilities/logic/set_fact.py
+++ b/lib/ansible/modules/utilities/logic/set_fact.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# Copyright 2013 Dag Wieers
-#
-# 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 .
+# 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.0',
'status': ['stableinterface'],
diff --git a/lib/ansible/modules/utilities/logic/set_stats.py b/lib/ansible/modules/utilities/logic/set_stats.py
index 7e33341f02..dfdd6a9af2 100644
--- a/lib/ansible/modules/utilities/logic/set_stats.py
+++ b/lib/ansible/modules/utilities/logic/set_stats.py
@@ -1,21 +1,11 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright 2016 Ansible RedHat, Inc
-#
-# 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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/utilities/logic/wait_for.py b/lib/ansible/modules/utilities/logic/wait_for.py
index 0499683f0b..5381feb578 100644
--- a/lib/ansible/modules/utilities/logic/wait_for.py
+++ b/lib/ansible/modules/utilities/logic/wait_for.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2012, Jeroen Hoekx
-#
-# 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 .
+# 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.0',
'status': ['stableinterface'],
@@ -185,7 +175,6 @@ import time
from ansible.module_utils.basic import AnsibleModule, load_platform_subclass
from ansible.module_utils._text import to_native
-from ansible.module_utils.pycompat24 import get_exception
HAS_PSUTIL = False
@@ -516,8 +505,7 @@ def main():
if path:
try:
os.stat(path)
- except OSError:
- e = get_exception()
+ except OSError as e:
# If anything except file not present, throw an error
if e.errno != 2:
elapsed = datetime.datetime.utcnow() - start
diff --git a/lib/ansible/modules/utilities/logic/wait_for_connection.py b/lib/ansible/modules/utilities/logic/wait_for_connection.py
index 8d0a57bb0c..61dd59dc00 100644
--- a/lib/ansible/modules/utilities/logic/wait_for_connection.py
+++ b/lib/ansible/modules/utilities/logic/wait_for_connection.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2017, Dag Wieers
-#
-# 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 .
+# 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.0',
'status': ['stableinterface'],
diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py
index 7f87b1d622..dc54b7e174 100644
--- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py
+++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py
@@ -2,19 +2,11 @@
# coding: utf-8 -*-
# (c) 2017, Wayne Witzel III
-#
-# 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
-# the Free Software Foundation, either version 3 of the License, or
-# (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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_group.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_group.py
index bc36a7f878..eb66ba1660 100644
--- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_group.py
+++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_group.py
@@ -2,19 +2,11 @@
# coding: utf-8 -*-
# (c) 2017, Wayne Witzel III
-#
-# 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
-# the Free Software Foundation, either version 3 of the License, or
-# (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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_host.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_host.py
index 65dfa6eecd..e317f7d38f 100644
--- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_host.py
+++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_host.py
@@ -2,19 +2,11 @@
# coding: utf-8 -*-
# (c) 2017, Wayne Witzel III
-#
-# 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
-# the Free Software Foundation, either version 3 of the License, or
-# (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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_inventory.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_inventory.py
index 0ab5704894..753351a3db 100644
--- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_inventory.py
+++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_inventory.py
@@ -2,19 +2,11 @@
# coding: utf-8 -*-
# (c) 2017, Wayne Witzel III
-#
-# 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
-# the Free Software Foundation, either version 3 of the License, or
-# (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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_cancel.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_cancel.py
index 0d99242f5e..569b81313a 100644
--- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_cancel.py
+++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_cancel.py
@@ -2,19 +2,11 @@
# coding: utf-8 -*-
# (c) 2017, Wayne Witzel III
-#
-# 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
-# the Free Software Foundation, either version 3 of the License, or
-# (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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_launch.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_launch.py
index 648e260632..c5204f2aa4 100644
--- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_launch.py
+++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_launch.py
@@ -2,19 +2,11 @@
# coding: utf-8 -*-
# (c) 2017, Wayne Witzel III
-#
-# 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
-# the Free Software Foundation, either version 3 of the License, or
-# (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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_list.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_list.py
index bdc1a272c9..cd23abb479 100644
--- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_list.py
+++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_list.py
@@ -2,19 +2,11 @@
# coding: utf-8 -*-
# (c) 2017, Wayne Witzel III
-#
-# 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
-# the Free Software Foundation, either version 3 of the License, or
-# (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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_template.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_template.py
index 2158c5c729..0535e22b70 100644
--- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_template.py
+++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_template.py
@@ -2,19 +2,11 @@
# coding: utf-8 -*-
# (c) 2017, Wayne Witzel III
-#
-# 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
-# the Free Software Foundation, either version 3 of the License, or
-# (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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_wait.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_wait.py
index f36784261b..5ac4731f22 100644
--- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_wait.py
+++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_job_wait.py
@@ -2,19 +2,11 @@
# coding: utf-8 -*-
# (c) 2017, Wayne Witzel III
-#
-# 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
-# the Free Software Foundation, either version 3 of the License, or
-# (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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_label.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_label.py
index fd1a296b97..3cf3ac7b09 100644
--- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_label.py
+++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_label.py
@@ -2,19 +2,11 @@
# coding: utf-8 -*-
# (c) 2017, Wayne Witzel III
-#
-# 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
-# the Free Software Foundation, either version 3 of the License, or
-# (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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_organization.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_organization.py
index 65741860cc..a334c1f1f1 100644
--- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_organization.py
+++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_organization.py
@@ -2,19 +2,11 @@
# coding: utf-8 -*-
# (c) 2017, Wayne Witzel III
-#
-# 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
-# the Free Software Foundation, either version 3 of the License, or
-# (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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_project.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_project.py
index 6aeabe7187..9fd7a73648 100644
--- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_project.py
+++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_project.py
@@ -2,19 +2,11 @@
# coding: utf-8 -*-
# (c) 2017, Wayne Witzel III
-#
-# 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
-# the Free Software Foundation, either version 3 of the License, or
-# (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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_role.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_role.py
index 04932d82a6..a2cfedb53f 100644
--- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_role.py
+++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_role.py
@@ -2,19 +2,11 @@
# coding: utf-8 -*-
# (c) 2017, Wayne Witzel III
-#
-# 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
-# the Free Software Foundation, either version 3 of the License, or
-# (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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_team.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_team.py
index 3eaefa036c..90b23b7a30 100644
--- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_team.py
+++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_team.py
@@ -2,19 +2,11 @@
# coding: utf-8 -*-
# (c) 2017, Wayne Witzel III
-#
-# 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
-# the Free Software Foundation, either version 3 of the License, or
-# (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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_user.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_user.py
index 3b86cd0172..61a8aa5010 100644
--- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_user.py
+++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_user.py
@@ -2,19 +2,11 @@
# coding: utf-8 -*-
# (c) 2017, Wayne Witzel III
-#
-# 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
-# the Free Software Foundation, either version 3 of the License, or
-# (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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/web_infrastructure/apache2_mod_proxy.py b/lib/ansible/modules/web_infrastructure/apache2_mod_proxy.py
index c021cc087a..b4fbc62e3b 100644
--- a/lib/ansible/modules/web_infrastructure/apache2_mod_proxy.py
+++ b/lib/ansible/modules/web_infrastructure/apache2_mod_proxy.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2016, Olivier Boukili
-#
-# 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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/web_infrastructure/apache2_module.py b/lib/ansible/modules/web_infrastructure/apache2_module.py
index d026d93a04..ba5a9326e2 100644
--- a/lib/ansible/modules/web_infrastructure/apache2_module.py
+++ b/lib/ansible/modules/web_infrastructure/apache2_module.py
@@ -2,19 +2,11 @@
# coding: utf-8 -*-
# (c) 2013-2014, Christian Berendt
-#
-# 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
-# the Free Software Foundation, either version 3 of the License, or
-# (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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/web_infrastructure/deploy_helper.py b/lib/ansible/modules/web_infrastructure/deploy_helper.py
index 5e32fccd5d..594640ade8 100644
--- a/lib/ansible/modules/web_infrastructure/deploy_helper.py
+++ b/lib/ansible/modules/web_infrastructure/deploy_helper.py
@@ -4,20 +4,11 @@
# (c) 2014, Jasper N. Brouwer
# (c) 2014, Ramon de la Fuente
#
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -282,10 +273,13 @@ EXAMPLES = '''
- debug:
var: deploy_helper
'''
+import os
+import shutil
+import time
+import traceback
-# import module snippets
-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._text import to_native
class DeployHelper(object):
@@ -344,9 +338,8 @@ class DeployHelper(object):
if not self.module.check_mode:
try:
shutil.rmtree(path, ignore_errors=False)
- except Exception:
- e = get_exception()
- self.module.fail_json(msg="rmtree failed: %s" % str(e))
+ except Exception as e:
+ self.module.fail_json(msg="rmtree failed: %s" % to_native(e), exception=traceback.format_exc())
return True
diff --git a/lib/ansible/modules/web_infrastructure/django_manage.py b/lib/ansible/modules/web_infrastructure/django_manage.py
index 1ad96a7c39..c3a1d962e5 100644
--- a/lib/ansible/modules/web_infrastructure/django_manage.py
+++ b/lib/ansible/modules/web_infrastructure/django_manage.py
@@ -2,22 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2013, Scott Anderson
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
@@ -138,8 +127,10 @@ EXAMPLES = """
app_path: "{{ django_dir }}"
"""
-
import os
+import sys
+
+from ansible.module_utils.basic import AnsibleModule
def _fail(module, cmd, out, err, **kwargs):
@@ -308,8 +299,6 @@ def main():
module.exit_json(changed=changed, out=out, cmd=cmd, app_path=app_path, virtualenv=virtualenv,
settings=module.params['settings'], pythonpath=module.params['pythonpath'])
-# import module snippets
-from ansible.module_utils.basic import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/web_infrastructure/ejabberd_user.py b/lib/ansible/modules/web_infrastructure/ejabberd_user.py
index c606a84088..e75bf5c11f 100644
--- a/lib/ansible/modules/web_infrastructure/ejabberd_user.py
+++ b/lib/ansible/modules/web_infrastructure/ejabberd_user.py
@@ -2,20 +2,12 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2013, Peter Sprygada
-#
-# 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
-# the Free Software Foundation, either version 3 of the License, or
-# (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, see .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
@@ -78,7 +70,7 @@ EXAMPLES = '''
'''
import syslog
-from ansible.module_utils.pycompat24 import get_exception
+
from ansible.module_utils.basic import AnsibleModule
@@ -113,7 +105,6 @@ class EjabberdUser(object):
options = [self.user, self.host, self.pwd]
(rc, out, err) = self.run_command('check_password', options)
except EjabberdUserException:
- e = get_exception()
(rc, out, err) = (1, None, "required attribute(s) missing")
return rc
@@ -127,7 +118,6 @@ class EjabberdUser(object):
options = [self.user, self.host]
(rc, out, err) = self.run_command('check_account', options)
except EjabberdUserException:
- e = get_exception()
(rc, out, err) = (1, None, "required attribute(s) missing")
return not bool(int(rc))
@@ -156,7 +146,6 @@ class EjabberdUser(object):
options = [self.user, self.host, self.pwd]
(rc, out, err) = self.run_command('change_password', options)
except EjabberdUserException:
- e = get_exception()
(rc, out, err) = (1, None, "required attribute(s) missing")
return (rc, out, err)
@@ -168,7 +157,6 @@ class EjabberdUser(object):
options = [self.user, self.host, self.pwd]
(rc, out, err) = self.run_command('register', options)
except EjabberdUserException:
- e = get_exception()
(rc, out, err) = (1, None, "required attribute(s) missing")
return (rc, out, err)
@@ -179,7 +167,6 @@ class EjabberdUser(object):
options = [self.user, self.host]
(rc, out, err) = self.run_command('unregister', options)
except EjabberdUserException:
- e = get_exception()
(rc, out, err) = (1, None, "required attribute(s) missing")
return (rc, out, err)
diff --git a/lib/ansible/modules/web_infrastructure/gunicorn.py b/lib/ansible/modules/web_infrastructure/gunicorn.py
index ee85428ed7..2b68f268d4 100644
--- a/lib/ansible/modules/web_infrastructure/gunicorn.py
+++ b/lib/ansible/modules/web_infrastructure/gunicorn.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2017, Alejandro Gomez
-#
-# 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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/web_infrastructure/htpasswd.py b/lib/ansible/modules/web_infrastructure/htpasswd.py
index bff8f0d5fc..48c332ebe1 100644
--- a/lib/ansible/modules/web_infrastructure/htpasswd.py
+++ b/lib/ansible/modules/web_infrastructure/htpasswd.py
@@ -2,22 +2,12 @@
# -*- coding: utf-8 -*-
# (c) 2013, Nimbis Services, Inc.
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
diff --git a/lib/ansible/modules/web_infrastructure/jboss.py b/lib/ansible/modules/web_infrastructure/jboss.py
index 53d671428a..97372315d6 100644
--- a/lib/ansible/modules/web_infrastructure/jboss.py
+++ b/lib/ansible/modules/web_infrastructure/jboss.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2013, Jeroen Hoekx
-#
-# 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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/web_infrastructure/jenkins_job.py b/lib/ansible/modules/web_infrastructure/jenkins_job.py
index 7b8f1760a4..9006aa1ae7 100644
--- a/lib/ansible/modules/web_infrastructure/jenkins_job.py
+++ b/lib/ansible/modules/web_infrastructure/jenkins_job.py
@@ -1,17 +1,11 @@
#!/usr/bin/python
#
-# This is a 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.
-#
-# This Ansible library 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 library. If not, see .
+# Copyright: (c) 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.0',
'status': ['preview'],
@@ -151,6 +145,8 @@ url:
sample: https://jenkins.mydomain.com
'''
+import traceback
+
try:
import jenkins
python_jenkins_installed = True
@@ -163,6 +159,9 @@ try:
except ImportError:
python_lxml_installed = False
+from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils._text import to_native
+
class JenkinsJob:
@@ -206,9 +205,8 @@ class JenkinsJob:
return jenkins.Jenkins(self.jenkins_url, self.user)
else:
return jenkins.Jenkins(self.jenkins_url)
- except Exception:
- e = get_exception()
- self.module.fail_json(msg='Unable to connect to Jenkins server, %s' % str(e))
+ except Exception as e:
+ self.module.fail_json(msg='Unable to connect to Jenkins server, %s' % to_native(e), exception=traceback.format_exc())
def job_class_excluded(self, response):
return response['_class'] in self.job_classes_exceptions
@@ -221,16 +219,15 @@ class JenkinsJob:
else:
return response['color'].encode('utf-8')
- except Exception:
- e = get_exception()
- self.module.fail_json(msg='Unable to fetch job information, %s' % str(e))
+ except Exception as e:
+ self.module.fail_json(msg='Unable to fetch job information, %s' % to_native(e), exception=traceback.format_exc())
def job_exists(self):
try:
return bool(self.server.job_exists(self.name))
- except Exception:
- e = get_exception()
- self.module.fail_json(msg='Unable to validate if job exists, %s for %s' % (str(e), self.jenkins_url))
+ except Exception as e:
+ self.module.fail_json(msg='Unable to validate if job exists, %s for %s' % (to_native(e), self.jenkins_url),
+ exception=traceback.format_exc())
def get_config(self):
return job_config_to_string(self.config)
@@ -293,9 +290,9 @@ class JenkinsJob:
if not self.module.check_mode:
self.switch_state()
- except Exception:
- e = get_exception()
- self.module.fail_json(msg='Unable to reconfigure job, %s for %s' % (str(e), self.jenkins_url))
+ except Exception as e:
+ self.module.fail_json(msg='Unable to reconfigure job, %s for %s' % (to_native(e), self.jenkins_url),
+ exception=traceback.format_exc())
def create_job(self):
if self.config is None:
@@ -307,9 +304,9 @@ class JenkinsJob:
self.result['diff']['after'] = config_file
if not self.module.check_mode:
self.server.create_job(self.name, config_file)
- except Exception:
- e = get_exception()
- self.module.fail_json(msg='Unable to create job, %s for %s' % (str(e), self.jenkins_url))
+ except Exception as e:
+ self.module.fail_json(msg='Unable to create job, %s for %s' % (to_native(e), self.jenkins_url),
+ exception=traceback.format_exc())
def absent_job(self):
if self.job_exists():
@@ -318,9 +315,9 @@ class JenkinsJob:
if not self.module.check_mode:
try:
self.server.delete_job(self.name)
- except Exception:
- e = get_exception()
- self.module.fail_json(msg='Unable to delete job, %s for %s' % (str(e), self.jenkins_url))
+ except Exception as e:
+ self.module.fail_json(msg='Unable to delete job, %s for %s' % (to_native(e), self.jenkins_url),
+ exception=traceback.format_exc())
def get_result(self):
result = self.result
@@ -376,6 +373,5 @@ def main():
module.exit_json(**result)
-from ansible.module_utils.basic import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/web_infrastructure/jenkins_plugin.py b/lib/ansible/modules/web_infrastructure/jenkins_plugin.py
index 18f2db2f8d..daf5e41b78 100644
--- a/lib/ansible/modules/web_infrastructure/jenkins_plugin.py
+++ b/lib/ansible/modules/web_infrastructure/jenkins_plugin.py
@@ -2,21 +2,11 @@
# encoding: utf-8
# (c) 2016, Jiri Tyr
-#
-# 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 .
+# 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.0',
diff --git a/lib/ansible/modules/web_infrastructure/jenkins_script.py b/lib/ansible/modules/web_infrastructure/jenkins_script.py
index ed9fe9ac6b..239954fef8 100644
--- a/lib/ansible/modules/web_infrastructure/jenkins_script.py
+++ b/lib/ansible/modules/web_infrastructure/jenkins_script.py
@@ -3,21 +3,10 @@
# encoding: utf-8
# (c) 2016, James Hogarth
-#
-# 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 .
+# 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.0',
diff --git a/lib/ansible/modules/web_infrastructure/jira.py b/lib/ansible/modules/web_infrastructure/jira.py
index 025d376dba..85e98cedcf 100644
--- a/lib/ansible/modules/web_infrastructure/jira.py
+++ b/lib/ansible/modules/web_infrastructure/jira.py
@@ -4,21 +4,11 @@
# (c) 2014, Steve Smith
# Atlassian open-source approval reference OSR-76.
#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
@@ -232,20 +222,12 @@ EXAMPLES = """
status: Done
"""
-try:
- 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 base64
+import json
+import sys
-from ansible.module_utils.basic import *
-from ansible.module_utils.urls import *
-from ansible.module_utils.pycompat24 import get_exception
+from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils.urls import fetch_url
def request(url, user, passwd, timeout, data=None, method=None):
@@ -442,8 +424,7 @@ def main():
ret = method(restbase, user, passwd, module.params)
- except Exception:
- e = get_exception()
+ except Exception as e:
return module.fail_json(msg=e.message)
module.exit_json(changed=True, meta=ret)
diff --git a/lib/ansible/modules/web_infrastructure/letsencrypt.py b/lib/ansible/modules/web_infrastructure/letsencrypt.py
index 6f57ccd40f..b7db6fd91f 100644
--- a/lib/ansible/modules/web_infrastructure/letsencrypt.py
+++ b/lib/ansible/modules/web_infrastructure/letsencrypt.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2016 Michael Gruener
-#
-# 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 .
+# 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.0',
'status': ['preview'],
@@ -164,12 +154,25 @@ authorizations:
type: dict
'''
+import base64
import binascii
import copy
+import hashlib
+import json
import locale
+import os
+import re
+import shutil
+import tempfile
import textwrap
+import time
+import traceback
from datetime import datetime
+from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils._text import to_native
+from ansible.module_utils.urls import fetch_url
+
def nopad_b64(data):
return base64.urlsafe_b64encode(data).decode('utf8').replace("=", "")
@@ -235,7 +238,7 @@ def write_file(module, dest, content):
f.write(content)
except Exception as err:
os.remove(tmpsrc)
- module.fail_json(msg="failed to create temporary content file: %s" % str(err))
+ module.fail_json(msg="failed to create temporary content file: %s" % to_native(err), exception=traceback.format_exc())
f.close()
checksum_src = None
checksum_dest = None
@@ -267,7 +270,7 @@ def write_file(module, dest, content):
changed = True
except Exception as err:
os.remove(tmpsrc)
- module.fail_json(msg="failed to copy %s to %s: %s" % (tmpsrc, dest, str(err)))
+ module.fail_json(msg="failed to copy %s to %s: %s" % (tmpsrc, dest, to_native(err)), exception=traceback.format_exc())
os.remove(tmpsrc)
return changed
@@ -630,8 +633,8 @@ class ACMEClient(object):
len_ka_digest = len(ka_digest)
resource = 'subjectAlternativeNames'
value = [
- "{0}.{1}.token.acme.invalid".format(token_digest[:len_token_digest / 2], token_digest[len_token_digest / 2:]),
- "{0}.{1}.ka.acme.invalid".format(ka_digest[:len_ka_digest / 2], ka_digest[len_ka_digest / 2:]),
+ "{0}.{1}.token.acme.invalid".format(token_digest[:len_token_digest // 2], token_digest[len_token_digest // 2:]),
+ "{0}.{1}.ka.acme.invalid".format(ka_digest[:len_ka_digest // 2], ka_digest[len_ka_digest // 2:]),
]
elif type == 'dns-01':
# https://tools.ietf.org/html/draft-ietf-acme-acme-02#section-7.4
@@ -805,9 +808,6 @@ def main():
else:
module.exit_json(changed=False, cert_days=cert_days)
-# import module snippets
-from ansible.module_utils.basic import *
-from ansible.module_utils.urls import *
if __name__ == '__main__':
main()
diff --git a/lib/ansible/modules/web_infrastructure/nginx_status_facts.py b/lib/ansible/modules/web_infrastructure/nginx_status_facts.py
index 5be94e8e67..307b786cbe 100644
--- a/lib/ansible/modules/web_infrastructure/nginx_status_facts.py
+++ b/lib/ansible/modules/web_infrastructure/nginx_status_facts.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
#
# (c) 2016, René Moser
-#
-# 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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/web_infrastructure/rundeck_acl_policy.py b/lib/ansible/modules/web_infrastructure/rundeck_acl_policy.py
index 14c0f14c22..c48dd217c1 100644
--- a/lib/ansible/modules/web_infrastructure/rundeck_acl_policy.py
+++ b/lib/ansible/modules/web_infrastructure/rundeck_acl_policy.py
@@ -1,26 +1,14 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-"""
-Ansible module to manage rundeck ACL policies
-(c) 2017, Loic Blot
-Sponsored by Infopro Digital. http://www.infopro-digital.com/
-Sponsored by E.T.A.I. http://www.etai.fr/
+# (c) 2017, Loic Blot
+# 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)
-This file is part of Ansible
+from __future__ import absolute_import, division, print_function
+__metaclass__ = type
-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 .
-"""
ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/web_infrastructure/rundeck_project.py b/lib/ansible/modules/web_infrastructure/rundeck_project.py
index be6fe25577..5985250507 100644
--- a/lib/ansible/modules/web_infrastructure/rundeck_project.py
+++ b/lib/ansible/modules/web_infrastructure/rundeck_project.py
@@ -6,19 +6,11 @@
# 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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/modules/web_infrastructure/supervisorctl.py b/lib/ansible/modules/web_infrastructure/supervisorctl.py
index 82ef08c545..5244e32c43 100644
--- a/lib/ansible/modules/web_infrastructure/supervisorctl.py
+++ b/lib/ansible/modules/web_infrastructure/supervisorctl.py
@@ -2,22 +2,12 @@
# -*- coding: utf-8 -*-
# (c) 2012, Matt Wright
-#
-# 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 .
-#
+# 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.0',
'status': ['preview'],
'supported_by': 'community'}
diff --git a/lib/ansible/modules/web_infrastructure/taiga_issue.py b/lib/ansible/modules/web_infrastructure/taiga_issue.py
index ffa8d4d710..22af09288f 100644
--- a/lib/ansible/modules/web_infrastructure/taiga_issue.py
+++ b/lib/ansible/modules/web_infrastructure/taiga_issue.py
@@ -2,21 +2,11 @@
# -*- coding: utf-8 -*-
# (c) 2015, Alejandro Guirao
-#
-# 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 .
+# 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.0',
'status': ['preview'],
diff --git a/lib/ansible/vars/unsafe_proxy.py b/lib/ansible/vars/unsafe_proxy.py
index 7951865d0c..b97ddb236f 100644
--- a/lib/ansible/vars/unsafe_proxy.py
+++ b/lib/ansible/vars/unsafe_proxy.py
@@ -20,7 +20,7 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
# This is backwards compat. unsafe_proxy was moved to avoid circular imports.
-from ansible.utils.unsafe_proxy import *
+from ansible.utils.unsafe_proxy import * # pylint: disable=wildcard-import
try:
from __main__ import display
diff --git a/test/sanity/pep8/legacy-files.txt b/test/sanity/pep8/legacy-files.txt
index cc6877b8ed..f16920da29 100644
--- a/test/sanity/pep8/legacy-files.txt
+++ b/test/sanity/pep8/legacy-files.txt
@@ -468,7 +468,6 @@ lib/ansible/modules/storage/netapp/sf_snapshot_schedule_manager.py
lib/ansible/modules/storage/netapp/sf_volume_access_group_manager.py
lib/ansible/modules/storage/netapp/sf_volume_manager.py
lib/ansible/modules/storage/zfs/zfs.py
-lib/ansible/modules/storage/zfs/zpool_facts.py
lib/ansible/modules/system/aix_inittab.py
lib/ansible/modules/system/alternatives.py
lib/ansible/modules/system/at.py