summaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorIan White <ian@stardog.io>2017-02-14 16:50:41 +0100
committerRyan Brown <sb@ryansb.com>2017-02-14 16:50:41 +0100
commit80bc7048bd707266ccef8dfd57b300ce5ba4818c (patch)
tree453c1bead9486cdb9765f977a94c56a0d5a69370 /contrib
parentservice state typo (diff)
downloadansible-80bc7048bd707266ccef8dfd57b300ce5ba4818c.tar.xz
ansible-80bc7048bd707266ccef8dfd57b300ce5ba4818c.zip
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
Diffstat (limited to 'contrib')
-rw-r--r--contrib/inventory/ec2.ini7
-rwxr-xr-xcontrib/inventory/ec2.py14
2 files changed, 20 insertions, 1 deletions
diff --git a/contrib/inventory/ec2.ini b/contrib/inventory/ec2.ini
index 8acce912f1..f3171eac10 100644
--- a/contrib/inventory/ec2.ini
+++ b/contrib/inventory/ec2.ini
@@ -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
diff --git a/contrib/inventory/ec2.py b/contrib/inventory/ec2.py
index 0bb2eb410a..9ee967b437 100755
--- a/contrib/inventory/ec2.py
+++ b/contrib/inventory/ec2.py
@@ -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()