From 418f91d0e25c7caea96f801b533af19f05ad3508 Mon Sep 17 00:00:00 2001 From: Tom Paine Date: Sun, 19 Jun 2016 15:55:42 +0100 Subject: [PATCH] Fail softly when boto3 is not installed Updated as per @ryansb comments. The EC2 inventory script will now fail with a useful message when boto3 is not installed and the user is trying to read RDS cluster information. --- contrib/inventory/ec2.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/contrib/inventory/ec2.py b/contrib/inventory/ec2.py index c0cddca088f..f2622ef6f14 100755 --- a/contrib/inventory/ec2.py +++ b/contrib/inventory/ec2.py @@ -130,7 +130,13 @@ from boto import rds from boto import elasticache from boto import route53 import six -import boto3 + +HAS_BOTO3 = False +try: + import boto3 + HAS_BOTO3 = True +except ImportError: + pass from six.moves import configparser from collections import defaultdict @@ -584,7 +590,10 @@ class Ec2Inventory(object): self.fail_with_error(error, 'getting RDS instances') def include_rds_clusters_by_region(self, region): - client = boto3.client('rds', region_name=region) + if not HAS_BOTO3: + module.fail_json(message="This module requires boto3 be installed - please install boto3 and try again") + + client = self.connect_to_aws(rds, region) clusters = client.describe_db_clusters()["DBClusters"] account_id = boto.connect_iam().get_user().arn.split(':')[4] c_dict = {}