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

Update for modules which import json.

Some do not use the json module directly so don't need import json.
Some needed to fallback to simplejson with no traceback if neither was installed

Fixes #1298
This commit is contained in:
Toshio Kuratomi 2016-01-11 12:47:21 -08:00 committed by Matt Clay
parent db051ff9d2
commit ad0d2c1747
22 changed files with 85 additions and 37 deletions

View file

@ -95,7 +95,6 @@ task:
sample: "TODO: include sample"
'''
try:
import json
import boto
import botocore
HAS_BOTO = True
@ -120,7 +119,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=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(

View file

@ -93,7 +93,6 @@ taskdefinition:
type: dict inputs plus revision, status, taskDefinitionArn
'''
try:
import json
import boto
import botocore
HAS_BOTO = True
@ -118,7 +117,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=str(e))
module.fail_json(msg="Can't authorize connection - "+str(e))
def describe_task(self, task_name):
try:

View file

@ -160,7 +160,6 @@ EXAMPLES = '''
'''
try:
import json
import boto
import botocore
HAS_BOTO = True

View file

@ -130,7 +130,6 @@ EXAMPLES = '''
'''
import time
import json
import xmltodict
VALID_RULE_KEYS = ['rule_type', 'original_ip', 'original_port',

View file

@ -190,11 +190,6 @@ EXAMPLES = '''
import sys
try:
import json
except ImportError:
import simplejson as json
try:
import consul
from requests.exceptions import ConnectionError

View file

@ -122,11 +122,6 @@ EXAMPLES = '''
import sys
try:
import json
except ImportError:
import simplejson as json
try:
import consul
from requests.exceptions import ConnectionError

View file

@ -100,10 +100,15 @@ EXAMPLES = '''
import time
import socket
import sys
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 ring_check(module, riak_admin_bin):

View file

@ -22,7 +22,15 @@ You should have received a copy of the GNU General Public License
along with Ansible. If not, see <http://www.gnu.org/licenses/>.
"""
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

View file

@ -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:

View file

@ -92,10 +92,16 @@ EXAMPLES = '''
# ===========================================
# Stackdriver module specific support methods.
#
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 send_deploy_event(module, key, revision_id, deployed_by='Ansible', deployed_to=None, repository=None):
"""Send a deploy event to Stackdriver"""

View file

@ -64,7 +64,15 @@ EXAMPLES = '''
'''
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

View file

@ -59,7 +59,12 @@ ipify_public_ip:
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
class IpifyFacts(object):

View file

@ -128,7 +128,12 @@ import re
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 parse_out(string):
return re.sub("\s+", " ", string).strip()

View file

@ -107,7 +107,12 @@ import os
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
class Npm(object):
def __init__(self, module, **kwargs):

View file

@ -109,7 +109,6 @@ EXAMPLES = '''
- pacman: name=baz state=absent force=yes
'''
import json
import shlex
import os
import re

View file

@ -63,7 +63,6 @@ EXAMPLES = '''
'''
import json
import shlex
import os
import sys

View file

@ -85,7 +85,6 @@ EXAMPLES = '''
'''
import json
import shlex
import os
import re

View file

@ -58,7 +58,6 @@ EXAMPLES = '''
'''
import json
import shlex
import os
import sys

View file

@ -73,7 +73,6 @@ EXAMPLES = '''
'''
import json
import shlex
import os
import sys

View file

@ -18,7 +18,15 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
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 = '''

View file

@ -22,7 +22,12 @@ 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
DOCUMENTATION = '''
---

View file

@ -160,7 +160,15 @@ EXAMPLES = """
issue={{issue.meta.key}} operation=transition 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
def request(url, user, passwd, data=None, method=None):