首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不可删除AWS Route53 TXT记录

不可删除AWS Route53 TXT记录
EN

Stack Overflow用户
提问于 2022-03-24 04:58:36
回答 2查看 107关注 0票数 1

我正在尝试使用Ansible删除AWS Route53 TXT记录

这是我的剧本的一部分

代码语言:javascript
复制
- name: "Retrieve the details for {{ item }}.{{ build_number }}.{{ internal_domain }} TXT Record"
  community.aws.route53:
    state: get
    private_zone: true
    record: "{{ item }}.{{ build_number }}.{{ internal_domain }}"
    type: TXT
    zone: "{{ internal_domain }}"
  register: rec_TXT

- name: display record
  debug: var=rec_TXT

- name: "Delete {{ item }}.{{ build_number }}.{{ internal_domain }} TXT Record"
  community.aws.route53:
    state: absent
    private_zone: true
    record: "{{ rec_TXT.set.record }}"
    ttl: "{{ rec_TXT.set.ttl }}"
    type: "{{ rec_TXT.set.type }}"
    value: "{{ rec_TXT.set.value | string }}"
    zone: "{{ rec_TXT.set.zone }}"
  when: rec_TXT.set | length > 0

这将导致错误。

代码语言:javascript
复制
    "msg": "[Tried to delete resource record set [name='dashboard.uat1tx.test.xyz.internal.', type='TXT'] but the rdata provided is invalid]"

在详细模式(-vvv)下运行剧本时,get请求将生成

代码语言:javascript
复制
ok: [localhost] => {
    "rec_TXT": {
        "changed": false,
        "failed": false,
        "nameservers": [
            "ns-1536.awsdns-00.co.uk.",
            "ns-0.awsdns-00.com.",
            "ns-1024.awsdns-00.org.",
            "ns-512.awsdns-00.net."
        ],
        "set": {
            "alias": false,
            "failover": null,
            "health_check": null,
            "hosted_zone_id": "HIAAGVXXXXPM9",
            "identifier": null,
            "record": "dashboard.uat1tx.test.xyz.internal.",
            "region": null,
            "ttl": "300",
            "type": "TXT",
            "value": "\"heritage=external-dns,external-dns/owner=SST4985-EKSCluster-uat1tx,external-dns/resource=service/default/k8s-dashboard-kubernetes-dashboard\"",
            "values": [
                "\"heritage=external-dns,external-dns/owner=SST4985-EKSCluster-uat1tx,external-dns/resource=service/default/k8s-dashboard-kubernetes-dashboard\""
            ],
            "weight": null,
            "zone": "test.xyz.internal."
        }
    }
}

缺席剧制作

代码语言:javascript
复制
The full traceback is:
  File "/tmp/ansible_community.aws.route53_payload_xb_ilskb/ansible_community.aws.route53_payload.zip/ansible_collections/community/aws/plugins/modules/route53.py", line 687, in main
  File "/tmp/ansible_community.aws.route53_payload_xb_ilskb/ansible_community.aws.route53_payload.zip/ansible_collections/community/aws/plugins/modules/route53.py", line 457, in invoke_with_throttling_retries
  File "/tmp/ansible_community.aws.route53_payload_xb_ilskb/ansible_community.aws.route53_payload.zip/ansible_collections/community/aws/plugins/modules/route53.py", line 453, in invoke_with_throttling_retries
  File "/tmp/ansible_community.aws.route53_payload_xb_ilskb/ansible_community.aws.route53_payload.zip/ansible_collections/community/aws/plugins/modules/route53.py", line 428, in commit
  File "/tmp/ansible_community.aws.route53_payload_xb_ilskb/ansible_community.aws.route53_payload.zip/ansible_collections/community/aws/plugins/modules/route53.py", line 422, in commit
  File "/usr/local/lib/python3.8/site-packages/boto/route53/record.py", line 168, in commit
    return self.connection.change_rrsets(self.hosted_zone_id, self.to_xml())
  File "/usr/local/lib/python3.8/site-packages/boto/route53/connection.py", line 473, in change_rrsets
    raise exception.DNSServerError(response.status,
fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "alias": null,
            "alias_evaluate_target_health": false,
            "alias_hosted_zone_id": null,
            "aws_access_key": null,
            "aws_ca_bundle": null,
            "aws_config": null,
            "aws_secret_key": null,
            "debug_botocore_endpoint_logs": false,
            "ec2_url": null,
            "failover": null,
            "health_check": null,
            "hosted_zone_id": null,
            "identifier": null,
            "overwrite": null,
            "private_zone": true,
            "profile": null,
            "record": "dashboard.uat1tx.test.xyz.internal.",
            "region": null,
            "retry_interval": 500,
            "security_token": null,
            "state": "absent",
            "ttl": 300,
            "type": "TXT",
            "validate_certs": true,
            "value": [
                "\"\"heritage=external-dns",
                "external-dns/owner=SST4985-EKSCluster-uat1tx",
                "external-dns/resource=service/default/k8s-dashboard-kubernetes-dashboard\"\""
            ],
            "vpc_id": null,
            "wait": false,
            "wait_timeout": 300,
            "weight": null,
            "zone": "test.xyz.internal."
        }
    },
    "msg": "[Tried to delete resource record set [name='dashboard.uat1tx.test.xyz.internal.', type='TXT'] but the rdata provided is invalid]"
}

问题在于值中的逗号。

有人提出了一个问题,但没有提供任何建议。https://github.com/ansible/ansible/issues/58084

如何传递“文字”刺激值选项?

有谁能提供任何提示/解决方案吗?

EN

回答 2

Stack Overflow用户

发布于 2022-03-24 07:49:07

因为我有一个类似的用例,但是有了其他REST,我想在这里分享我的解决方案方法。

在我的用例中,还需要一个CSV_STRING。有点像

代码语言:javascript
复制
    CSV_STRING:
      '
         "heritage=external-dns",
         "external-dns/owner=SST4985-EKSCluster-uat1tx",
         "external-dns/resource=service/default/k8s-dashboard-kubernetes-dashboard"
      '

我将值设置为

代码语言:javascript
复制
{{ CSV_STRING | trim | replace(' ', '') }}

如果我已经把它列出来了

代码语言:javascript
复制
---

CSV_STRING
  - '"heritage=external-dns"'
  - '"external-dns/owner=SST4985-EKSCluster-uat1tx"'
  - '"external-dns/resource=service/default/k8s-dashboard-kubernetes-dashboard"'

我可以用

代码语言:javascript
复制
{{ CSV_STRING | join(',') }}

但是,查看ansible-collections/community.aws/blob/main/plugins/modules/route53.py的当前源代码,看起来value不需要字符串。

代码语言:javascript
复制
def main():
    argument_spec = dict(
...
        value=dict(type='list', elements='str'),
...

-添加或删除Amazons 53号路由DNS服务中的条目的文档还指出,对于参数value,需要字符串元素的列表。

这意味着,您需要进行相反的操作,在前面将逗号上的字符串拆分成一个列表。

进一步Q&A

票数 0
EN

Stack Overflow用户

发布于 2022-03-26 05:48:04

我欺骗并默认到命令模块。

我仍然希望使用route53模块并解决这个问题。

我有一个模板

代码语言:javascript
复制
{ 
  "Comment": "Record Set Delete Changes",
  "Changes": [
    {
      "Action": "DELETE",
      "ResourceRecordSet": {
        "Name": "{{ rec_TXT.set.record }}",
        "Type": "TXT",
        "TTL" : {{ rec_TXT.set.ttl }},
        "ResourceRecords": [
          {
            "Value": "\"{{ rec_TXT.set.value[1:-1] }}\""
          }
        ]
      }
    }
  ]
}

剧本看上去就像

代码语言:javascript
复制
- name: "Retrieve the details for {{ item }}.{{ build_number }}.{{ internal_domain }} TXT Record"
  community.aws.route53:
    state: get
    private_zone: true
    record: "{{ item }}.{{ build_number }}.{{ internal_domain }}"
    type: TXT
    zone: "{{ internal_domain }}"
  register: rec_TXT

- block:
  - name: Create the JSON file to delete the TXT record
    ansible.builtin.template:
      src: delete_txt_record.json.j2
      dest: "{{ output_dir }}/{{ item }}_delete_txt_record.json"
      owner: test
      group: test
      mode: '0644'
  - name: "Delete {{ item }}.{{ build_number }}.{{ internal_domain }} TXT Record"
    ansible.builtin.command:
      cmd: "/usr/local/bin/aws route53 change-resource-record-sets --hosted-zone-id {{ rec_TXT.set.hosted_zone_id }} --change-batch file://{{ output_dir }}/{{ item }}_delete_txt_record.json"
    when: rec_TXT.set | length > 0

  when: rec_TXT.set | length > 0
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71597253

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档