Merge branch 'Coderah-route53-alias' into devel
This commit is contained in:
commit
3a40a02156
2 changed files with 71 additions and 21 deletions
|
@ -328,7 +328,9 @@ class ElbManager(object):
|
||||||
'security_group_ids': check_elb.security_groups,
|
'security_group_ids': check_elb.security_groups,
|
||||||
'status': self.status,
|
'status': self.status,
|
||||||
'subnets': self.subnets,
|
'subnets': self.subnets,
|
||||||
'scheme': check_elb.scheme
|
'scheme': check_elb.scheme,
|
||||||
|
'hosted_zone_name': check_elb.canonical_hosted_zone_name,
|
||||||
|
'hosted_zone_id': check_elb.canonical_hosted_zone_name_id
|
||||||
}
|
}
|
||||||
|
|
||||||
if check_elb.health_check:
|
if check_elb.health_check:
|
||||||
|
|
|
@ -54,9 +54,23 @@ options:
|
||||||
default: null
|
default: null
|
||||||
aliases: []
|
aliases: []
|
||||||
choices: [ 'A', 'CNAME', 'MX', 'AAAA', 'TXT', 'PTR', 'SRV', 'SPF', 'NS' ]
|
choices: [ 'A', 'CNAME', 'MX', 'AAAA', 'TXT', 'PTR', 'SRV', 'SPF', 'NS' ]
|
||||||
|
alias:
|
||||||
|
description:
|
||||||
|
- Indicates if this is an alias record.
|
||||||
|
required: false
|
||||||
|
version_added: 1.9
|
||||||
|
default: False
|
||||||
|
aliases: []
|
||||||
|
alias_hosted_zone_id:
|
||||||
|
description:
|
||||||
|
- The hosted zone identifier.
|
||||||
|
required: false
|
||||||
|
version_added: 1.9
|
||||||
|
default: null
|
||||||
|
aliases: []
|
||||||
value:
|
value:
|
||||||
description:
|
description:
|
||||||
- The new value when creating a DNS record. Multiple comma-spaced values are allowed. When deleting a record all values for the record must be specified or Route53 will not delete it.
|
- The new value when creating a DNS record. Multiple comma-spaced values are allowed for non-alias records. When deleting a record all values for the record must be specified or Route53 will not delete it.
|
||||||
required: false
|
required: false
|
||||||
default: null
|
default: null
|
||||||
aliases: []
|
aliases: []
|
||||||
|
@ -143,6 +157,16 @@ EXAMPLES = '''
|
||||||
ttl: "7200"
|
ttl: "7200"
|
||||||
value: '"bar"'
|
value: '"bar"'
|
||||||
|
|
||||||
|
# Add an alias record that points to an Amazon ELB:
|
||||||
|
- route53:
|
||||||
|
command=create
|
||||||
|
zone=foo.com
|
||||||
|
record=elb.foo.com
|
||||||
|
type=A
|
||||||
|
value="{{ elb_dns_name }}"
|
||||||
|
alias=yes
|
||||||
|
alias_hosted_zone_id="{{ elb_zone_id }}"
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@ -174,27 +198,31 @@ def commit(changes, retry_interval):
|
||||||
def main():
|
def main():
|
||||||
argument_spec = ec2_argument_spec()
|
argument_spec = ec2_argument_spec()
|
||||||
argument_spec.update(dict(
|
argument_spec.update(dict(
|
||||||
command = dict(choices=['get', 'create', 'delete'], required=True),
|
command = dict(choices=['get', 'create', 'delete'], required=True),
|
||||||
zone = dict(required=True),
|
zone = dict(required=True),
|
||||||
record = dict(required=True),
|
record = dict(required=True),
|
||||||
ttl = dict(required=False, default=3600),
|
ttl = dict(required=False, default=3600),
|
||||||
type = dict(choices=['A', 'CNAME', 'MX', 'AAAA', 'TXT', 'PTR', 'SRV', 'SPF', 'NS'], required=True),
|
type = dict(choices=['A', 'CNAME', 'MX', 'AAAA', 'TXT', 'PTR', 'SRV', 'SPF', 'NS'], required=True),
|
||||||
value = dict(required=False),
|
alias = dict(required=False, type='bool'),
|
||||||
overwrite = dict(required=False, type='bool'),
|
alias_hosted_zone_id = dict(required=False),
|
||||||
retry_interval = dict(required=False, default=500),
|
value = dict(required=False),
|
||||||
private_zone = dict(required=False, type='bool', default=False),
|
overwrite = dict(required=False, type='bool'),
|
||||||
|
retry_interval = dict(required=False, default=500),
|
||||||
|
private_zone = dict(required=False, type='bool', default=False),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
module = AnsibleModule(argument_spec=argument_spec)
|
module = AnsibleModule(argument_spec=argument_spec)
|
||||||
|
|
||||||
command_in = module.params.get('command')
|
command_in = module.params.get('command')
|
||||||
zone_in = module.params.get('zone').lower()
|
zone_in = module.params.get('zone').lower()
|
||||||
ttl_in = module.params.get('ttl')
|
ttl_in = module.params.get('ttl')
|
||||||
record_in = module.params.get('record').lower()
|
record_in = module.params.get('record').lower()
|
||||||
type_in = module.params.get('type')
|
type_in = module.params.get('type')
|
||||||
value_in = module.params.get('value')
|
value_in = module.params.get('value')
|
||||||
retry_interval_in = module.params.get('retry_interval')
|
alias_in = module.params.get('alias')
|
||||||
private_zone_in = module.params.get('private_zone')
|
alias_hosted_zone_id_in = module.params.get('alias_hosted_zone_id')
|
||||||
|
retry_interval_in = module.params.get('retry_interval')
|
||||||
|
private_zone_in = module.params.get('private_zone')
|
||||||
|
|
||||||
ec2_url, aws_access_key, aws_secret_key, region = get_ec2_creds(module)
|
ec2_url, aws_access_key, aws_secret_key, region = get_ec2_creds(module)
|
||||||
|
|
||||||
|
@ -215,6 +243,11 @@ def main():
|
||||||
if command_in == 'create' or command_in == 'delete':
|
if command_in == 'create' or command_in == 'delete':
|
||||||
if not value_in:
|
if not value_in:
|
||||||
module.fail_json(msg = "parameter 'value' required for create/delete")
|
module.fail_json(msg = "parameter 'value' required for create/delete")
|
||||||
|
elif alias_in:
|
||||||
|
if len(value_list) != 1:
|
||||||
|
module.fail_json(msg = "parameter 'value' must contain a single dns name for alias create/delete")
|
||||||
|
elif not alias_hosted_zone_id_in:
|
||||||
|
module.fail_json(msg = "parameter 'alias_hosted_zone_id' required for alias create/delete")
|
||||||
|
|
||||||
# connect to the route53 endpoint
|
# connect to the route53 endpoint
|
||||||
try:
|
try:
|
||||||
|
@ -255,6 +288,15 @@ def main():
|
||||||
record['ttl'] = rset.ttl
|
record['ttl'] = rset.ttl
|
||||||
record['value'] = ','.join(sorted(rset.resource_records))
|
record['value'] = ','.join(sorted(rset.resource_records))
|
||||||
record['values'] = sorted(rset.resource_records)
|
record['values'] = sorted(rset.resource_records)
|
||||||
|
if rset.alias_dns_name:
|
||||||
|
record['alias'] = True
|
||||||
|
record['value'] = rset.alias_dns_name
|
||||||
|
record['values'] = [rset.alias_dns_name]
|
||||||
|
record['alias_hosted_zone_id'] = rset.alias_hosted_zone_id
|
||||||
|
else:
|
||||||
|
record['alias'] = False
|
||||||
|
record['value'] = ','.join(sorted(rset.resource_records))
|
||||||
|
record['values'] = sorted(rset.resource_records)
|
||||||
if value_list == sorted(rset.resource_records) and int(record['ttl']) == ttl_in and command_in == 'create':
|
if value_list == sorted(rset.resource_records) and int(record['ttl']) == ttl_in and command_in == 'create':
|
||||||
module.exit_json(changed=False)
|
module.exit_json(changed=False)
|
||||||
|
|
||||||
|
@ -272,12 +314,18 @@ def main():
|
||||||
else:
|
else:
|
||||||
change = changes.add_change("DELETE", record_in, type_in, record['ttl'])
|
change = changes.add_change("DELETE", record_in, type_in, record['ttl'])
|
||||||
for v in record['values']:
|
for v in record['values']:
|
||||||
change.add_value(v)
|
if record['alias']:
|
||||||
|
change.set_alias(record['alias_hosted_zone_id'], v)
|
||||||
|
else:
|
||||||
|
change.add_value(v)
|
||||||
|
|
||||||
if command_in == 'create' or command_in == 'delete':
|
if command_in == 'create' or command_in == 'delete':
|
||||||
change = changes.add_change(command_in.upper(), record_in, type_in, ttl_in)
|
change = changes.add_change(command_in.upper(), record_in, type_in, ttl_in)
|
||||||
for v in value_list:
|
for v in value_list:
|
||||||
change.add_value(v)
|
if module.params['alias']:
|
||||||
|
change.set_alias(alias_hosted_zone_id_in, v)
|
||||||
|
else:
|
||||||
|
change.add_value(v)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = commit(changes, retry_interval_in)
|
result = commit(changes, retry_interval_in)
|
||||||
|
|
Loading…
Reference in a new issue