Created
February 16, 2024 11:52
-
-
Save markuman/47491b3b78735b787486979f6e7ddc50 to your computer and use it in GitHub Desktop.
ansible aws route53 dnssec draft
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
w#!/usr/bin/python | |
DOCUMENTATION = ''' | |
enable dnssec for public dns zone | |
''' | |
EXAMPLES = ''' | |
- name: enable dnssec | |
route53_dnssec: | |
zone: zone_id | |
kms: "{{ lookup('kms_arn', 'alias/dnssec', region='us-east-1') }}" | |
state: enable | |
''' | |
from ansible.module_utils.basic import * | |
import boto3 | |
def main(): | |
module = AnsibleModule( | |
argument_spec = dict( | |
zone = dict(type='str'), | |
kms = dict(type='str'), | |
state = dict(type='str', choices=['enable']) | |
) | |
) | |
zone = module.params.get('zone') | |
kms = module.params.get('kms') | |
state = module.params.get('state') | |
route53 = boto3.client('route53') | |
if state == 'enable': | |
response = route53.get_dnssec( | |
HostedZoneId=zone | |
) | |
if response['Status']['ServeSignature'] != 'NOT_SIGNING': | |
module.exit_json(changed=False, message='already enabled', details=response) | |
else: | |
response_ksk = route53.create_key_signing_key( | |
CallerReference='enables-by-ansible', | |
HostedZoneId=zone, | |
KeyManagementServiceArn=kms, | |
Name=zone + '_dnssec', | |
Status='ACTIVE' | |
) | |
response_zone = route53.enable_hosted_zone_dnssec( | |
HostedZoneId=zone | |
) | |
module.exit_json(changed=True, message='enabled', details=response_zone) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment