From 663deff2c25af18ec72276fac02bb221f7288492 Mon Sep 17 00:00:00 2001 From: Lorrin Nelson Date: Thu, 5 Dec 2013 21:33:25 -0800 Subject: [PATCH] Fix loading from cache in ec2.py inventory plugin. --- plugins/inventory/ec2.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/inventory/ec2.py b/plugins/inventory/ec2.py index d6fe9504865..a38545052d7 100755 --- a/plugins/inventory/ec2.py +++ b/plugins/inventory/ec2.py @@ -131,12 +131,15 @@ except ImportError: class Ec2Inventory(object): + def _empty_inventory(self): + return {"_meta" : {"hostvars" : {}}} + def __init__(self): ''' Main execution path ''' # Inventory grouped by instance IDs, tags, security groups, regions, # and availability zones - self.inventory = {"_meta" : {"hostvars" : {}}} + self.inventory = self._empty_inventory() # Index of hostname (address) to instance ID self.index = {} @@ -157,7 +160,7 @@ class Ec2Inventory(object): elif self.args.list: # Display list of instances for inventory - if len(self.inventory) == 0: + if self.inventory == self._empty_inventory(): data_to_print = self.get_inventory_from_cache() else: data_to_print = self.json_format_dict(self.inventory, True)