From 5975296770681de396838beeaa3dc1bfde841fb0 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 2 Mar 2016 19:44:25 +0100 Subject: [PATCH 1/2] Fix AWS EC2 external inventory script config read EC2 inventory scripts reads configuration from an INI file. The `instance_filters` option controls which EC2 instances are retrieved for inventory. Filling this option and running the inventory script with Python 3 crashes with the following error: ```python Traceback (most recent call last): File "./contrib/inventory/ec2.py", line 1328, in Ec2Inventory() File "./contrib/inventory/ec2.py", line 163, in __init__ self.read_settings() File "./contrib/inventory/ec2.py", line 393, in read_settings for instance_filter in config.get('ec2', 'instance_filters', '').split(','): TypeError: get() takes 3 positional arguments but 4 were given ``` The problem is the last parameter of config.get() call, because `fallback` keyword argument is not specified. The fix handles epmpty `instance_filers` in case of Python 2&3 --- contrib/inventory/ec2.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/contrib/inventory/ec2.py b/contrib/inventory/ec2.py index 4c5cf23fcb8..f9a943efbe0 100755 --- a/contrib/inventory/ec2.py +++ b/contrib/inventory/ec2.py @@ -388,7 +388,10 @@ class Ec2Inventory(object): # Instance filters (see boto and EC2 API docs). Ignore invalid filters. self.ec2_instance_filters = defaultdict(list) if config.has_option('ec2', 'instance_filters'): - for instance_filter in config.get('ec2', 'instance_filters', '').split(','): + + filters = [tag for tag in config.get('ec2', 'instance_filters').split(',') if tag] + + for instance_filter in filters: instance_filter = instance_filter.strip() if not instance_filter or '=' not in instance_filter: continue From 21ba6e9ce83410d35adbc4c3b5b12a07a6e28271 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 2 Mar 2016 20:06:14 +0100 Subject: [PATCH 2/2] Do not use name `tag` for intance filter --- contrib/inventory/ec2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/inventory/ec2.py b/contrib/inventory/ec2.py index f9a943efbe0..86327360b90 100755 --- a/contrib/inventory/ec2.py +++ b/contrib/inventory/ec2.py @@ -389,7 +389,7 @@ class Ec2Inventory(object): self.ec2_instance_filters = defaultdict(list) if config.has_option('ec2', 'instance_filters'): - filters = [tag for tag in config.get('ec2', 'instance_filters').split(',') if tag] + filters = [f for f in config.get('ec2', 'instance_filters').split(',') if f] for instance_filter in filters: instance_filter = instance_filter.strip()