diff --git a/cloud/amazon/ecs_task.py b/cloud/amazon/ecs_task.py
index 000ce68b56c..c2bd73751ad 100644
--- a/cloud/amazon/ecs_task.py
+++ b/cloud/amazon/ecs_task.py
@@ -98,7 +98,6 @@ task:
sample: "TODO: include sample"
'''
try:
- import json
import boto
import botocore
HAS_BOTO = True
@@ -123,7 +122,7 @@ class EcsExecManager:
module.fail_json(msg="Region must be specified as a parameter, in EC2_REGION or AWS_REGION environment variables or in boto configuration file")
self.ecs = boto3_conn(module, conn_type='client', resource='ecs', region=region, endpoint=ec2_url, **aws_connect_kwargs)
except boto.exception.NoAuthHandlerFound, e:
- self.module.fail_json(msg="Can't authorize connection - "+str(e))
+ module.fail_json(msg="Can't authorize connection - "+str(e))
def list_tasks(self, cluster_name, service_name, status):
response = self.ecs.list_tasks(
diff --git a/cloud/amazon/ecs_taskdefinition.py b/cloud/amazon/ecs_taskdefinition.py
index 50205d6691c..6ad23a88f86 100644
--- a/cloud/amazon/ecs_taskdefinition.py
+++ b/cloud/amazon/ecs_taskdefinition.py
@@ -95,7 +95,6 @@ taskdefinition:
type: dict inputs plus revision, status, taskDefinitionArn
'''
try:
- import json
import boto
import botocore
HAS_BOTO = True
@@ -120,7 +119,7 @@ class EcsTaskManager:
module.fail_json(msg="Region must be specified as a parameter, in EC2_REGION or AWS_REGION environment variables or in boto configuration file")
self.ecs = boto3_conn(module, conn_type='client', resource='ecs', region=region, endpoint=ec2_url, **aws_connect_kwargs)
except boto.exception.NoAuthHandlerFound, e:
- self.module.fail_json(msg="Can't authorize connection - "+str(e))
+ module.fail_json(msg="Can't authorize connection - "+str(e))
def describe_task(self, task_name):
try:
diff --git a/cloud/amazon/route53_facts.py b/cloud/amazon/route53_facts.py
index d6081dba4da..40bcea73e55 100644
--- a/cloud/amazon/route53_facts.py
+++ b/cloud/amazon/route53_facts.py
@@ -160,7 +160,6 @@ EXAMPLES = '''
'''
try:
- import json
import boto
import botocore
HAS_BOTO = True
diff --git a/cloud/vmware/vca_nat.py b/cloud/vmware/vca_nat.py
index 88fc24a20fc..2a464673e56 100644
--- a/cloud/vmware/vca_nat.py
+++ b/cloud/vmware/vca_nat.py
@@ -130,7 +130,6 @@ EXAMPLES = '''
'''
import time
-import json
import xmltodict
VALID_RULE_KEYS = ['rule_type', 'original_ip', 'original_port',
diff --git a/clustering/consul.py b/clustering/consul.py
index 609dce89227..627f7fb66af 100644
--- a/clustering/consul.py
+++ b/clustering/consul.py
@@ -190,11 +190,6 @@ EXAMPLES = '''
import sys
-try:
- import json
-except ImportError:
- import simplejson as json
-
try:
import consul
from requests.exceptions import ConnectionError
diff --git a/clustering/consul_kv.py b/clustering/consul_kv.py
index bb7dea3ad39..b61c0ee1841 100644
--- a/clustering/consul_kv.py
+++ b/clustering/consul_kv.py
@@ -122,11 +122,6 @@ EXAMPLES = '''
import sys
-try:
- import json
-except ImportError:
- import simplejson as json
-
try:
import consul
from requests.exceptions import ConnectionError
diff --git a/database/misc/riak.py b/database/misc/riak.py
index 453e6c15f3e..1f1cd11e922 100644
--- a/database/misc/riak.py
+++ b/database/misc/riak.py
@@ -100,10 +100,15 @@ EXAMPLES = '''
import time
import socket
import sys
+
try:
import json
except ImportError:
- import simplejson as json
+ try:
+ import simplejson as json
+ except ImportError:
+ # Let snippet from module_utils/basic.py return a proper error in this case
+ pass
def ring_check(module, riak_admin_bin):
diff --git a/monitoring/boundary_meter.py b/monitoring/boundary_meter.py
index 99cb74f870d..ef681704f04 100644
--- a/monitoring/boundary_meter.py
+++ b/monitoring/boundary_meter.py
@@ -22,7 +22,15 @@ You should have received a copy of the GNU General Public License
along with Ansible. If not, see .
"""
-import json
+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 datetime
import base64
import os
diff --git a/monitoring/sensu_check.py b/monitoring/sensu_check.py
index 9a004d372e0..09edae63813 100644
--- a/monitoring/sensu_check.py
+++ b/monitoring/sensu_check.py
@@ -174,16 +174,20 @@ EXAMPLES = '''
sensu_check: name=check_disk_capacity state=absent
'''
+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
+
def sensu_check(module, path, name, state='present', backup=False):
changed = False
reasons = []
- try:
- import json
- except ImportError:
- import simplejson as json
-
stream = None
try:
try:
diff --git a/monitoring/stackdriver.py b/monitoring/stackdriver.py
index 7b3688cbefc..25af77ec26e 100644
--- a/monitoring/stackdriver.py
+++ b/monitoring/stackdriver.py
@@ -92,10 +92,16 @@ EXAMPLES = '''
# ===========================================
# Stackdriver module specific support methods.
#
+
try:
- import json
+ import json
except ImportError:
- import simplejson as json
+ try:
+ import simplejson as json
+ except ImportError:
+ # Let snippet from module_utils/basic.py return a proper error in this case
+ pass
+
def send_deploy_event(module, key, revision_id, deployed_by='Ansible', deployed_to=None, repository=None):
"""Send a deploy event to Stackdriver"""
diff --git a/monitoring/uptimerobot.py b/monitoring/uptimerobot.py
index bdff8f1f134..65d963cda6d 100644
--- a/monitoring/uptimerobot.py
+++ b/monitoring/uptimerobot.py
@@ -64,7 +64,15 @@ EXAMPLES = '''
'''
-import json
+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 urllib
import time
diff --git a/network/ipify_facts.py b/network/ipify_facts.py
index 8f509dd278a..95bf549be92 100644
--- a/network/ipify_facts.py
+++ b/network/ipify_facts.py
@@ -59,7 +59,12 @@ ipify_public_ip:
try:
import json
except ImportError:
- import simplejson as json
+ try:
+ import simplejson as json
+ except ImportError:
+ # Let snippet from module_utils/basic.py return a proper error in this case
+ pass
+
class IpifyFacts(object):
diff --git a/packaging/language/composer.py b/packaging/language/composer.py
index 95b0eb3a940..5d1ec7b1014 100644
--- a/packaging/language/composer.py
+++ b/packaging/language/composer.py
@@ -128,7 +128,12 @@ import re
try:
import json
except ImportError:
- import simplejson as json
+ try:
+ import simplejson as json
+ except ImportError:
+ # Let snippet from module_utils/basic.py return a proper error in this case
+ pass
+
def parse_out(string):
return re.sub("\s+", " ", string).strip()
diff --git a/packaging/language/npm.py b/packaging/language/npm.py
index a52b7599d80..43fa1f325ff 100644
--- a/packaging/language/npm.py
+++ b/packaging/language/npm.py
@@ -107,7 +107,12 @@ import os
try:
import json
except ImportError:
- import simplejson as json
+ try:
+ import simplejson as json
+ except ImportError:
+ # Let snippet from module_utils/basic.py return a proper error in this case
+ pass
+
class Npm(object):
def __init__(self, module, **kwargs):
diff --git a/packaging/os/pacman.py b/packaging/os/pacman.py
index 1f955fa269e..7aa5bf45eaf 100644
--- a/packaging/os/pacman.py
+++ b/packaging/os/pacman.py
@@ -109,7 +109,6 @@ EXAMPLES = '''
- pacman: name=baz state=absent force=yes
'''
-import json
import shlex
import os
import re
diff --git a/packaging/os/pkgin.py b/packaging/os/pkgin.py
index 0f2714b6c74..cdba6a9218b 100644
--- a/packaging/os/pkgin.py
+++ b/packaging/os/pkgin.py
@@ -63,7 +63,6 @@ EXAMPLES = '''
'''
-import json
import shlex
import os
import sys
diff --git a/packaging/os/pkgng.py b/packaging/os/pkgng.py
index 0eafcb6d00b..ad097aae0df 100644
--- a/packaging/os/pkgng.py
+++ b/packaging/os/pkgng.py
@@ -85,7 +85,6 @@ EXAMPLES = '''
'''
-import json
import shlex
import os
import re
diff --git a/packaging/os/portinstall.py b/packaging/os/portinstall.py
index b4e3044167e..a5d0e510978 100644
--- a/packaging/os/portinstall.py
+++ b/packaging/os/portinstall.py
@@ -58,7 +58,6 @@ EXAMPLES = '''
'''
-import json
import shlex
import os
import sys
diff --git a/packaging/os/urpmi.py b/packaging/os/urpmi.py
index d344f2e7c5c..0b9ec929316 100644
--- a/packaging/os/urpmi.py
+++ b/packaging/os/urpmi.py
@@ -73,7 +73,6 @@ EXAMPLES = '''
'''
-import json
import shlex
import os
import sys
diff --git a/source_control/github_hooks.py b/source_control/github_hooks.py
index d75fcb1573d..9f664875587 100644
--- a/source_control/github_hooks.py
+++ b/source_control/github_hooks.py
@@ -18,7 +18,15 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see .
-import json
+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
DOCUMENTATION = '''
diff --git a/system/puppet.py b/system/puppet.py
index 2a70da3cea1..d4f69b1d515 100644
--- a/system/puppet.py
+++ b/system/puppet.py
@@ -22,7 +22,12 @@ import stat
try:
import json
except ImportError:
- import simplejson as json
+ try:
+ import simplejson as json
+ except ImportError:
+ # Let snippet from module_utils/basic.py return a proper error in this case
+ pass
+
DOCUMENTATION = '''
---
diff --git a/web_infrastructure/jira.py b/web_infrastructure/jira.py
index 79cfb72d4a7..dded069f743 100644
--- a/web_infrastructure/jira.py
+++ b/web_infrastructure/jira.py
@@ -160,7 +160,15 @@ EXAMPLES = """
issue={{issue.meta.key}} operation=transition status="Done"
"""
-import json
+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
def request(url, user, passwd, data=None, method=None):