From 1dd3ff3879f00f2eee2742556fe08d9d5f604a92 Mon Sep 17 00:00:00 2001 From: Arthur Taylor Date: Tue, 20 Aug 2013 15:58:59 +0200 Subject: [PATCH] Added Overwrite option for Route53 record creation --- library/cloud/route53 | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/library/cloud/route53 b/library/cloud/route53 index d209ab815b3..cace25793f6 100644 --- a/library/cloud/route53 +++ b/library/cloud/route53 @@ -72,6 +72,12 @@ options: required: false default: null aliases: [] + overwrite: + description: + - Whether an existing record should be overwritten on create if values do not match + required: false + default: null + aliases: [] requirements: [ "boto" ] author: Bruce Pennypacker ''' @@ -133,7 +139,8 @@ def main(): type = dict(choices=['A', 'CNAME', 'MX', 'AAAA', 'TXT', 'PTR', 'SRV', 'SPF', 'NS'], required=True), value = dict(required=False), ec2_secret_key = dict(aliases=['EC2_SECRET_KEY'], no_log=True, required=False), - ec2_access_key = dict(aliases=['EC2_ACCESS_KEY'], required=False) + ec2_access_key = dict(aliases=['EC2_ACCESS_KEY'], required=False), + overwrite = dict(required=False, choices=BOOLEANS, type='bool') ) ) @@ -212,6 +219,14 @@ def main(): changes = ResourceRecordSets(conn, zones[zone_in]) + if command_in == 'create' and found_record: + if not module.params['overwrite']: + module.fail_json(msg = "Record already exists with different value. Set 'overwrite' to replace it") + else: + change = changes.add_change("DELETE", record_in, type_in, ttl_in) + for v in record['values']: + change.add_value(v) + if command_in == 'create' or command_in == 'delete': change = changes.add_change(command_in.upper(), record_in, type_in, ttl_in) for v in value_list: