| | |
| | | --- |
| | | - name: Get all records from the environment private zone |
| | | route53_facts: |
| | | hosted_zone_id: "{{ _hostedzoneid }}" |
| | | query: record_sets |
| | | - name: Get all records |
| | | command: >- |
| | | aws route53 list-resource-record-sets --hosted-zone-id {{ _hostedzoneid }} |
| | | register: records |
| | | until: records is succeeded |
| | | retries: 10 |
| | | delay: "{{ 60|random(start=3, step=1) }}" |
| | | |
| | | - debug: |
| | | var: records |
| | | verbosity: 2 |
| | | - set_fact: |
| | | change_batch_dest: "{{ output_dir }}/{{ guid }}_{{ _hostedzoneid }}_delete_records.json" |
| | | |
| | | - name: Delete all non-alias records from the environment zone |
| | | route53: |
| | | private_zone: "{{ _zone.Config.PrivateZone }}" |
| | | zone: "{{aws_public_zone}}" |
| | | record: "{{item.Name}}" |
| | | type: "{{item.Type}}" |
| | | value: "{{item.ResourceRecords|json_query('[].Value')}}" |
| | | ttl: "{{item.TTL}}" |
| | | state: absent |
| | | when: >- |
| | | 'Name' in item |
| | | and 'ResourceRecords' in item |
| | | and item.Name != aws_public_zone |
| | | with_items: "{{records.ResourceRecordSets }}" |
| | | ignore_errors: yes |
| | | - name: Create route53 change batch (JSON) |
| | | copy: |
| | | dest: "{{ change_batch_dest }}" |
| | | content: | |
| | | { |
| | | "Comment": "Delete all records for {{ _hostedzoneid }}", |
| | | "Changes": [ |
| | | {% for record in |
| | | records.stdout |
| | | |from_json |
| | | |json_query('ResourceRecordSets') |
| | | |rejectattr('Name', 'equalto', aws_public_zone) %} |
| | | { "Action": "DELETE", |
| | | "ResourceRecordSet": {{ record | to_json }} |
| | | }{{ "," if not loop.last else "" }} |
| | | {% endfor %} |
| | | ] |
| | | } |
| | | |
| | | - name: Delete all ALIAS records from the environment public zone |
| | | route53: |
| | | private_zone: "{{ _zone.Config.PrivateZone }}" |
| | | zone: "{{aws_public_zone}}" |
| | | record: "{{item.Name | regex_replace('\\\\052', '*') }}" |
| | | type: "{{item.Type}}" |
| | | alias: yes |
| | | alias_hosted_zone_id: "{{ item.AliasTarget.HostedZoneId }}" |
| | | value: "{{ item.AliasTarget.DNSName }}" |
| | | alias_evaluate_target_health: "{{ item.AliasTarget.EvaluateTargetHealth }}" |
| | | state: absent |
| | | when: >- |
| | | 'Name' in item |
| | | and 'AliasTarget' in item |
| | | and item.Name != aws_public_zone |
| | | |
| | | with_items: "{{records.ResourceRecordSets }}" |
| | | ignore_errors: yes |
| | | - name: Delete all record from the zone |
| | | command: >- |
| | | aws route53 change-resource-record-sets |
| | | --hosted-zone-id={{_hostedzoneid}} |
| | | --change-batch=file://{{ change_batch_dest }} |
| | | |
| | | - name: Remove route53 zone |
| | | command: >- |