From 16bd2c735734fb2d7c291bfcceb209624158c4e3 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Fri, 19 Jun 2015 08:59:19 -0700 Subject: [PATCH] be explicit about urllib import and remove conditional urllib(2) import urllib and urllib2 have been in the python stdlib since at least python-2.3. There's no reason to conditionalize it. Fixes https://github.com/ansible/ansible/issues/11322 --- .../modules/extras/monitoring/airbrake_deployment.py | 5 +++-- .../modules/extras/monitoring/newrelic_deployment.py | 5 +++-- lib/ansible/modules/extras/monitoring/rollbar_deployment.py | 1 + lib/ansible/modules/extras/network/citrix/netscaler.py | 4 ++-- lib/ansible/modules/extras/network/dnsmadeeasy.py | 6 ++++-- lib/ansible/modules/extras/notification/flowdock.py | 5 +++-- lib/ansible/modules/extras/notification/grove.py | 2 ++ lib/ansible/modules/extras/notification/hipchat.py | 4 ++-- lib/ansible/modules/extras/notification/nexmo.py | 1 + lib/ansible/modules/extras/notification/sendgrid.py | 5 +---- lib/ansible/modules/extras/notification/twilio.py | 5 +---- 11 files changed, 23 insertions(+), 20 deletions(-) diff --git a/lib/ansible/modules/extras/monitoring/airbrake_deployment.py b/lib/ansible/modules/extras/monitoring/airbrake_deployment.py index 3b54e55e75..a58df02418 100644 --- a/lib/ansible/modules/extras/monitoring/airbrake_deployment.py +++ b/lib/ansible/modules/extras/monitoring/airbrake_deployment.py @@ -61,8 +61,7 @@ options: default: 'yes' choices: ['yes', 'no'] -# informational: requirements for nodes -requirements: [ urllib, urllib2 ] +requirements: [] ''' EXAMPLES = ''' @@ -72,6 +71,8 @@ EXAMPLES = ''' revision=4.2 ''' +import urllib + # =========================================== # Module execution. # diff --git a/lib/ansible/modules/extras/monitoring/newrelic_deployment.py b/lib/ansible/modules/extras/monitoring/newrelic_deployment.py index 832e467dea..3d9bc6c0ec 100644 --- a/lib/ansible/modules/extras/monitoring/newrelic_deployment.py +++ b/lib/ansible/modules/extras/monitoring/newrelic_deployment.py @@ -72,8 +72,7 @@ options: choices: ['yes', 'no'] version_added: 1.5.1 -# informational: requirements for nodes -requirements: [ urllib, urllib2 ] +requirements: [] ''' EXAMPLES = ''' @@ -83,6 +82,8 @@ EXAMPLES = ''' revision=1.0 ''' +import urllib + # =========================================== # Module execution. # diff --git a/lib/ansible/modules/extras/monitoring/rollbar_deployment.py b/lib/ansible/modules/extras/monitoring/rollbar_deployment.py index 43e2aa0072..060193b78a 100644 --- a/lib/ansible/modules/extras/monitoring/rollbar_deployment.py +++ b/lib/ansible/modules/extras/monitoring/rollbar_deployment.py @@ -76,6 +76,7 @@ EXAMPLES = ''' comment='Test Deploy' ''' +import urllib def main(): diff --git a/lib/ansible/modules/extras/network/citrix/netscaler.py b/lib/ansible/modules/extras/network/citrix/netscaler.py index 61bc35356e..384a625bdc 100644 --- a/lib/ansible/modules/extras/network/citrix/netscaler.py +++ b/lib/ansible/modules/extras/network/citrix/netscaler.py @@ -81,7 +81,7 @@ options: default: 'yes' choices: ['yes', 'no'] -requirements: [ "urllib", "urllib2" ] +requirements: [] author: "Nandor Sivok (@dominis)" ''' @@ -99,7 +99,7 @@ ansible host -m netscaler -a "nsc_host=nsc.example.com user=apiuser password=api import base64 import socket - +import urllib class netscaler(object): diff --git a/lib/ansible/modules/extras/network/dnsmadeeasy.py b/lib/ansible/modules/extras/network/dnsmadeeasy.py index b6320d65e6..cce7bd1008 100644 --- a/lib/ansible/modules/extras/network/dnsmadeeasy.py +++ b/lib/ansible/modules/extras/network/dnsmadeeasy.py @@ -86,8 +86,8 @@ notes: - The DNS Made Easy service requires that machines interacting with the API have the proper time and timezone set. Be sure you are within a few seconds of actual time by using NTP. - This module returns record(s) in the "result" element when 'state' is set to 'present'. This value can be be registered and used in your playbooks. -requirements: [ urllib, urllib2, hashlib, hmac ] -author: Brice Burgess +requirements: [ hashlib, hmac ] +author: "Brice Burgess (@briceburg)" ''' EXAMPLES = ''' @@ -113,6 +113,8 @@ EXAMPLES = ''' # DNSMadeEasy module specific support methods. # +import urllib + IMPORT_ERROR = None try: import json diff --git a/lib/ansible/modules/extras/notification/flowdock.py b/lib/ansible/modules/extras/notification/flowdock.py index 7c42e58644..34dad8db37 100644 --- a/lib/ansible/modules/extras/notification/flowdock.py +++ b/lib/ansible/modules/extras/notification/flowdock.py @@ -85,8 +85,7 @@ options: choices: ['yes', 'no'] version_added: 1.5.1 -# informational: requirements for nodes -requirements: [ urllib, urllib2 ] +requirements: [ ] ''' EXAMPLES = ''' @@ -104,6 +103,8 @@ EXAMPLES = ''' tags=tag1,tag2,tag3 ''' +import urllib + # =========================================== # Module execution. # diff --git a/lib/ansible/modules/extras/notification/grove.py b/lib/ansible/modules/extras/notification/grove.py index 85601d1cc7..4e4a0b5b68 100644 --- a/lib/ansible/modules/extras/notification/grove.py +++ b/lib/ansible/modules/extras/notification/grove.py @@ -49,6 +49,8 @@ EXAMPLES = ''' message=deployed {{ target }} ''' +import urllib + BASE_URL = 'https://grove.io/api/notice/%s/' # ============================================================== diff --git a/lib/ansible/modules/extras/notification/hipchat.py b/lib/ansible/modules/extras/notification/hipchat.py index fbb44d3ac6..3fc04767d9 100644 --- a/lib/ansible/modules/extras/notification/hipchat.py +++ b/lib/ansible/modules/extras/notification/hipchat.py @@ -62,8 +62,7 @@ options: version_added: 1.6.0 -# informational: requirements for nodes -requirements: [ urllib, urllib2 ] +requirements: [ ] author: "WAKAYAMA Shirou (@shirou), BOURDEL Paul (@pb8226)" ''' @@ -76,6 +75,7 @@ EXAMPLES = ''' # MSG_URI = "https://api.hipchat.com/v1/rooms/message" +import urllib def send_msg(module, token, room, msg_from, msg, msg_format='text', color='yellow', notify=False, api=MSG_URI): diff --git a/lib/ansible/modules/extras/notification/nexmo.py b/lib/ansible/modules/extras/notification/nexmo.py index d0c3d05e65..89a246c0d9 100644 --- a/lib/ansible/modules/extras/notification/nexmo.py +++ b/lib/ansible/modules/extras/notification/nexmo.py @@ -71,6 +71,7 @@ EXAMPLES = """ msg: "{{ inventory_hostname }} completed" """ +import urllib NEXMO_API = 'https://rest.nexmo.com/sms/json' diff --git a/lib/ansible/modules/extras/notification/sendgrid.py b/lib/ansible/modules/extras/notification/sendgrid.py index 78806687e0..7a2ee3ad65 100644 --- a/lib/ansible/modules/extras/notification/sendgrid.py +++ b/lib/ansible/modules/extras/notification/sendgrid.py @@ -84,10 +84,7 @@ EXAMPLES = ''' # ======================================= # sendgrid module support methods # -try: - import urllib, urllib2 -except ImportError: - module.fail_json(msg="urllib and urllib2 are required") +import urllib, urllib2 import base64 diff --git a/lib/ansible/modules/extras/notification/twilio.py b/lib/ansible/modules/extras/notification/twilio.py index e9ec5bcf51..a2dd77fb2c 100644 --- a/lib/ansible/modules/extras/notification/twilio.py +++ b/lib/ansible/modules/extras/notification/twilio.py @@ -104,10 +104,7 @@ EXAMPLES = ''' # ======================================= # twilio module support methods # -try: - import urllib, urllib2 -except ImportError: - module.fail_json(msg="urllib and urllib2 are required") +import urllib, urllib2 import base64