Feature: adding route53_hostnames option to set the hostnames from route 53 (#20909)
* adding route53_hostnames option to set the hostnames from route 53 * checking whether the route53_hostnames option is present as suggested by @s-hertel * setting route53_hostnames to None when config option not present * skip the to_safe only when using route53_hostnames option, as suggested by @ryansb * skipping the to_safe strip only for the hostnames that came from route53 as suggested by @ryansb
This commit is contained in:
parent
32b92b53b0
commit
80bc7048bd
2 changed files with 20 additions and 1 deletions
|
@ -57,9 +57,14 @@ vpc_destination_variable = ip_address
|
|||
#destination_format_tags = Name,environment
|
||||
|
||||
# To tag instances on EC2 with the resource records that point to them from
|
||||
# Route53, uncomment and set 'route53' to True.
|
||||
# Route53, set 'route53' to True.
|
||||
route53 = False
|
||||
|
||||
# To use Route53 records as the inventory hostnames, uncomment and set
|
||||
# to equal the domain name you wish to use. You must also have 'route53' (above)
|
||||
# set to True.
|
||||
# route53_hostnames = .example.com
|
||||
|
||||
# To exclude RDS instances from the inventory, uncomment and set to False.
|
||||
#rds = False
|
||||
|
||||
|
|
|
@ -274,6 +274,10 @@ class Ec2Inventory(object):
|
|||
|
||||
# Route53
|
||||
self.route53_enabled = config.getboolean('ec2', 'route53')
|
||||
if config.has_option('ec2', 'route53_hostnames'):
|
||||
self.route53_hostnames = config.get('ec2', 'route53_hostnames')
|
||||
else:
|
||||
self.route53_hostnames = None
|
||||
self.route53_excluded_zones = []
|
||||
if config.has_option('ec2', 'route53_excluded_zones'):
|
||||
self.route53_excluded_zones.extend(
|
||||
|
@ -809,9 +813,19 @@ class Ec2Inventory(object):
|
|||
else:
|
||||
hostname = getattr(instance, self.hostname_variable)
|
||||
|
||||
# set the hostname from route53
|
||||
if self.route53_enabled and self.route53_hostnames:
|
||||
route53_names = self.get_instance_route53_names(instance)
|
||||
for name in route53_names:
|
||||
if name.endswith(self.route53_hostnames):
|
||||
hostname = name
|
||||
|
||||
# If we can't get a nice hostname, use the destination address
|
||||
if not hostname:
|
||||
hostname = dest
|
||||
# to_safe strips hostname characters like dots, so don't strip route53 hostnames
|
||||
elif self.route53_enabled and self.route53_hostnames and hostname.endswith(self.route53_hostnames):
|
||||
hostname = hostname.lower()
|
||||
else:
|
||||
hostname = self.to_safe(hostname).lower()
|
||||
|
||||
|
|
Loading…
Reference in a new issue