From 753173b40de1647854d49dd47bb269061531bfd2 Mon Sep 17 00:00:00 2001 From: Andy Grimm Date: Wed, 4 Mar 2015 15:57:05 -0500 Subject: Add flexible destination format string to ec2.py This allows us to construct hostnames from a format string plus ec2 tag values. --- inventory/aws/ec2.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'inventory/aws/ec2.py') diff --git a/inventory/aws/ec2.py b/inventory/aws/ec2.py index 0f7c19857..f4e029553 100644 --- a/inventory/aws/ec2.py +++ b/inventory/aws/ec2.py @@ -215,6 +215,8 @@ class Ec2Inventory(object): # Destination addresses self.destination_variable = config.get('ec2', 'destination_variable') self.vpc_destination_variable = config.get('ec2', 'vpc_destination_variable') + self.destination_format = config.get('ec2', 'destination_format') + self.destination_format_tags = config.get('ec2', 'destination_format_tags', '').split(',') # Route53 self.route53_enabled = config.getboolean('ec2', 'route53') @@ -411,7 +413,9 @@ class Ec2Inventory(object): return # Select the best destination address - if instance.subnet_id: + if self.destination_format and self.destination_format_tags: + dest = self.destination_format.format(*[ getattr(instance, 'tags').get(tag, 'nil') for tag in self.destination_format_tags ]) + elif instance.subnet_id: dest = getattr(instance, self.vpc_destination_variable, None) if dest is None: dest = getattr(instance, 'tags').get(self.vpc_destination_variable, None) -- cgit v1.2.3