From d88a42570e459d962c33ceb92466f64075fdc808 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Schr=C3=B6der?= Date: Mon, 29 Jun 2015 21:56:36 +0200 Subject: [PATCH] Adds a check for 'not None' values when iterating ElastiCache SecurityGroups keys --- plugins/inventory/ec2.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/plugins/inventory/ec2.py b/plugins/inventory/ec2.py index e07efac4c0..081990cd8f 100755 --- a/plugins/inventory/ec2.py +++ b/plugins/inventory/ec2.py @@ -791,7 +791,11 @@ class Ec2Inventory(object): # Inventory: Group by security group if self.group_by_security_group and not is_redis: - if 'SecurityGroups' in cluster: + + # Check for the existance of the 'SecurityGroups' key and also if + # this key has some value. When the cluster is not placed in a SG + # the query can return None here and cause an error. + if 'SecurityGroups' in cluster and cluster['SecurityGroups'] is not None: for security_group in cluster['SecurityGroups']: key = self.to_safe("security_group_" + security_group['SecurityGroupId']) self.push(self.inventory, key, dest) @@ -879,7 +883,11 @@ class Ec2Inventory(object): # Inventory: Group by security group if self.group_by_security_group: - if 'SecurityGroups' in cluster: + + # Check for the existance of the 'SecurityGroups' key and also if + # this key has some value. When the cluster is not placed in a SG + # the query can return None here and cause an error. + if 'SecurityGroups' in cluster and cluster['SecurityGroups'] is not None: for security_group in cluster['SecurityGroups']: key = self.to_safe("security_group_" + security_group['SecurityGroupId']) self.push(self.inventory, key, dest)