diff options
author | Andy Grimm <agrimm@redhat.com> | 2015-03-04 15:57:05 -0500 |
---|---|---|
committer | Andy Grimm <agrimm@redhat.com> | 2015-03-04 15:57:05 -0500 |
commit | 753173b40de1647854d49dd47bb269061531bfd2 (patch) | |
tree | d7e691cf5139e58eae4a6002c7ba450f00d177e4 /inventory/aws | |
parent | 9c774bb95baba3da0a8cac56a5e9bf1fb9cf657b (diff) | |
download | openshift-753173b40de1647854d49dd47bb269061531bfd2.tar.gz openshift-753173b40de1647854d49dd47bb269061531bfd2.tar.bz2 openshift-753173b40de1647854d49dd47bb269061531bfd2.tar.xz openshift-753173b40de1647854d49dd47bb269061531bfd2.zip |
Add flexible destination format string to ec2.py
This allows us to construct hostnames from a format string
plus ec2 tag values.
Diffstat (limited to 'inventory/aws')
-rw-r--r-- | inventory/aws/ec2.ini | 7 | ||||
-rw-r--r-- | inventory/aws/ec2.py | 6 |
2 files changed, 12 insertions, 1 deletions
diff --git a/inventory/aws/ec2.ini b/inventory/aws/ec2.ini index 8a0c3ad45..eaab0a410 100644 --- a/inventory/aws/ec2.ini +++ b/inventory/aws/ec2.ini @@ -53,3 +53,10 @@ cache_path = ~/.ansible/tmp # seconds, a new API call will be made, and the cache file will be updated. # To disable the cache, set this value to 0 cache_max_age = 300 + +# These two settings allow flexible ansible host naming based on a format +# string and a comma-separated list of ec2 tags. The tags used must be +# present for all instances, or the code will fail. This overrides both +# destination_variable and vpc_destination_variable. +# destination_format = {0}.{1}.rhcloud.com +# destination_format_tags = Name,environment 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) |