-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract GCP DNS (clouddns) from gce-specific 'clean' playbook so that…
… it can be used separately. (#41) Fix clouddns cleaning so that it only cleans cluster hosts, not all GCP
- Loading branch information
1 parent
6008476
commit e6252ad
Showing
6 changed files
with
145 additions
and
148 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
--- | ||
|
||
- name: Delete DNS entries from route53 | ||
block: | ||
- name: Delete DNS A records using nsupdate (if applicable) | ||
nsupdate: | ||
key_name: "{{bind9[buildenv].key_name}}" | ||
key_secret: "{{bind9[buildenv].key_secret}}" | ||
server: "{{bind9[buildenv].server}}" | ||
zone: "{{dns_tld_external}}" | ||
state: "absent" | ||
record: "{{item.hostname}}.{{cluster_vars.dns_zone_external | regex_replace('^(.*?)\\.' + dns_tld_external, '\\1')}}" | ||
with_items: "{{ cluster_hosts_flat }}" | ||
|
||
- name: "Delete CNAME records" | ||
nsupdate: | ||
key_name: "{{bind9[buildenv].key_name}}" | ||
key_secret: "{{bind9[buildenv].key_secret}}" | ||
server: "{{bind9[buildenv].server}}" | ||
zone: "{{dns_tld_external}}" | ||
record: "{{item.hostname | regex_replace('-(?!.*-).*')}}.{{cluster_vars.dns_zone_external | regex_replace('^(.*?)\\.' + dns_tld_external, '\\1')}}" | ||
value: "{{item.hostname}}.{{cluster_vars.dns_zone_external | regex_replace('^(.*?)\\.' + dns_tld_external, '\\1')}}" | ||
type: CNAME | ||
state: absent | ||
with_items: "{{ cluster_hosts_flat }}" | ||
when: instance_to_create is undefined or rescuing_instance is undefined | ||
when: cluster_vars.dns_server == "nsupdate" | ||
|
||
- name: Delete DNS entries from route53 | ||
block: | ||
- name: Get A records from route53 | ||
route53: | ||
aws_access_key: "{{cluster_vars[buildenv].aws_access_key}}" | ||
aws_secret_key: "{{cluster_vars[buildenv].aws_secret_key}}" | ||
state: "get" | ||
zone: "{{cluster_vars.dns_zone_external}}" | ||
record: "{{item.hostname}}.{{cluster_vars.dns_zone_external}}" | ||
type: "A" | ||
private_zone: "{{cluster_vars.route53_private_zone | default(true)}}" | ||
register: dns_rec | ||
with_items: "{{ cluster_hosts_flat }}" | ||
|
||
- name: Remove A records from route53 | ||
route53: | ||
aws_access_key: "{{cluster_vars[buildenv].aws_access_key}}" | ||
aws_secret_key: "{{cluster_vars[buildenv].aws_secret_key}}" | ||
state: "absent" | ||
zone: "{{ item.set.zone }}" | ||
record: "{{ item.set.record }}" | ||
type: "{{ item.set.type }}" | ||
ttl: "{{ item.set.ttl }}" | ||
value: ["{{ item.set.value }}"] | ||
private_zone: "{{cluster_vars.route53_private_zone | default(true)}}" | ||
with_items: "{{ dns_rec.results }}" | ||
when: item.set.value is defined | ||
|
||
- name: Get CNAME records from route53 | ||
route53: | ||
aws_access_key: "{{cluster_vars[buildenv].aws_access_key}}" | ||
aws_secret_key: "{{cluster_vars[buildenv].aws_secret_key}}" | ||
state: "get" | ||
zone: "{{cluster_vars.dns_zone_external}}" | ||
record: "{{item.hostname | regex_replace('-(?!.*-)[0-9]{10}$')}}.{{cluster_vars.dns_zone_external}}" | ||
type: "CNAME" | ||
private_zone: "{{cluster_vars.route53_private_zone | default(true)}}" | ||
register: dns_rec | ||
with_items: "{{ cluster_hosts_flat }}" | ||
|
||
- name: Remove CNAME records from route53 | ||
route53: | ||
aws_access_key: "{{cluster_vars[buildenv].aws_access_key}}" | ||
aws_secret_key: "{{cluster_vars[buildenv].aws_secret_key}}" | ||
state: "absent" | ||
zone: "{{ item.set.zone }}" | ||
record: "{{ item.set.record }}" | ||
type: "{{ item.set.type }}" | ||
ttl: "{{ item.set.ttl }}" | ||
value: ["{{ item.set.value }}"] | ||
private_zone: "{{cluster_vars.route53_private_zone | default(true)}}" | ||
with_items: "{{ dns_rec.results }}" | ||
when: item.set.value is defined | ||
when: cluster_vars.dns_server == "route53" | ||
|
||
|
||
- name: Delete DNS entries from clouddns | ||
block: | ||
- name: Gather info for a pre-existing GCP Managed Zone and store as dict | ||
gcp_dns_managed_zone_info: | ||
auth_kind: serviceaccount | ||
dns_name: "{{dns_tld_external}}" | ||
project: "{{cluster_vars.project_id}}" | ||
service_account_file: "{{gcp_credentials_file}}" | ||
register: gcp_dns_managed_zone_info | ||
|
||
- name: Get DNS entries from clouddns | ||
gcp_dns_resource_record_set_info: | ||
auth_kind: serviceaccount | ||
managed_zone: | ||
name: "{{gcp_dns_managed_zone_info.resources.0.name}}" | ||
dnsName: "{{gcp_dns_managed_zone_info.resources.0.dnsName}}" | ||
project: "{{cluster_vars.project_id}}" | ||
service_account_file: "{{gcp_credentials_file}}" | ||
register: gcp_dns_resource_record_set_info | ||
|
||
- name: Remove A records from clouddns | ||
gcp_dns_resource_record_set: | ||
auth_kind: serviceaccount | ||
managed_zone: | ||
name: "{{gcp_dns_managed_zone_info.resources.0.name}}" | ||
dnsName: "{{gcp_dns_managed_zone_info.resources.0.dnsName}}" | ||
name: "{{ item.name }}" | ||
project: "{{cluster_vars.project_id}}" | ||
service_account_file: "{{gcp_credentials_file}}" | ||
state: absent | ||
target: "{{ item.rrdatas }}" | ||
type: A | ||
with_items: "{{ gcp_dns_resource_record_set_info.resources | json_query(\"[?type=='A']\") }}" | ||
vars: | ||
hosts_to_clean: "{{cluster_hosts_flat | map(attribute='hostname') | list }}" | ||
when: (item.name | regex_replace('^(.*?)\\..*$', '\\1')) in hosts_to_clean | ||
|
||
- name: Remove CNAME records from clouddns | ||
gcp_dns_resource_record_set: | ||
auth_kind: serviceaccount | ||
managed_zone: | ||
name: "{{gcp_dns_managed_zone_info.resources.0.name}}" | ||
dnsName: "{{gcp_dns_managed_zone_info.resources.0.dnsName}}" | ||
name: "{{ item.name }}" | ||
project: "{{cluster_vars.project_id}}" | ||
service_account_file: "{{gcp_credentials_file}}" | ||
state: absent | ||
target: "{{ item.rrdatas[0] }}" | ||
type: CNAME | ||
with_items: "{{ gcp_dns_resource_record_set_info.resources | json_query(\"[?type=='CNAME']\") }}" | ||
vars: | ||
cnames_to_clean: "{{cluster_hosts_flat | map(attribute='hostname') | map('regex_replace', '-(?!.*-).*') | list }}" | ||
when: (item.name | regex_replace('^(.*?)\\..*$', '\\1')) in cnames_to_clean | ||
when: cluster_vars.dns_server=="clouddns" |
This file contains 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
This file contains 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