Commit 43a98000 by David Baumgold

SQS plugin: ignore import errors until we care about them

parent 0965bde5
...@@ -22,11 +22,12 @@ import time ...@@ -22,11 +22,12 @@ import time
import json import json
import socket import socket
try: try:
import boto
except ImportError:
boto = None
else:
import boto.sqs import boto.sqs
from boto.exception import NoAuthHandlerFound from boto.exception import NoAuthHandlerFound
except ImportError:
print "Boto is required for the sqs_notify callback plugin"
raise
class CallbackModule(object): class CallbackModule(object):
...@@ -47,36 +48,42 @@ class CallbackModule(object): ...@@ -47,36 +48,42 @@ class CallbackModule(object):
- START events - START events
""" """
def __init__(self): def __init__(self):
self.enable_sqs = 'ANSIBLE_ENABLE_SQS' in os.environ
if not self.enable_sqs:
return
# make sure we got our imports
if not boto:
raise ImportError(
"The sqs callback module requires the boto Python module, "
"which is not installed or was not found."
)
self.start_time = time.time() self.start_time = time.time()
if 'ANSIBLE_ENABLE_SQS' in os.environ: if not 'SQS_REGION' in os.environ:
self.enable_sqs = True print 'ANSIBLE_ENABLE_SQS enabled but SQS_REGION ' \
if not 'SQS_REGION' in os.environ: 'not defined in environment'
print 'ANSIBLE_ENABLE_SQS enabled but SQS_REGION ' \ sys.exit(1)
'not defined in environment' self.region = os.environ['SQS_REGION']
sys.exit(1) try:
self.region = os.environ['SQS_REGION'] self.sqs = boto.sqs.connect_to_region(self.region)
try: except NoAuthHandlerFound:
self.sqs = boto.sqs.connect_to_region(self.region) print 'ANSIBLE_ENABLE_SQS enabled but cannot connect ' \
except NoAuthHandlerFound: 'to AWS due invalid credentials'
print 'ANSIBLE_ENABLE_SQS enabled but cannot connect ' \ sys.exit(1)
'to AWS due invalid credentials' if not 'SQS_NAME' in os.environ:
sys.exit(1) print 'ANSIBLE_ENABLE_SQS enabled but SQS_NAME not ' \
if not 'SQS_NAME' in os.environ: 'defined in environment'
print 'ANSIBLE_ENABLE_SQS enabled but SQS_NAME not ' \ sys.exit(1)
'defined in environment' self.name = os.environ['SQS_NAME']
sys.exit(1) self.queue = self.sqs.create_queue(self.name)
self.name = os.environ['SQS_NAME'] if 'SQS_MSG_PREFIX' in os.environ:
self.queue = self.sqs.create_queue(self.name) self.prefix = os.environ['SQS_MSG_PREFIX']
if 'SQS_MSG_PREFIX' in os.environ:
self.prefix = os.environ['SQS_MSG_PREFIX']
else:
self.prefix = ''
self.last_seen_ts = {}
else: else:
self.enable_sqs = False self.prefix = ''
self.last_seen_ts = {}
def runner_on_failed(self, host, res, ignore_errors=False): def runner_on_failed(self, host, res, ignore_errors=False):
if self.enable_sqs: if self.enable_sqs:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment