簡體   English   中英

Ansible 刪除 AWS Route53 TXT 記錄

[英]Ansible Deleting AWS Route53 TXT records

我正在嘗試使用 Ansible 刪除 AWS Route53 TXT 記錄

這是我劇本的一部分

- 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

這導致錯誤

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

在詳細模式 (-vvv) 下運行劇本時, get請求會生成

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."
        }
    }
}

缺席的戲產生了

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

如何將“文字”字符串傳遞給值選項?

任何人都可以提供任何提示/解決方案嗎?!!!

因為我有一個有點相似的用例,但是有另一個 REST API,我想在這里分享我的解決方法。

在我的用例中,還需要一個CSV_STRING 就像是

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

我設置值

{{ CSV_STRING | trim | replace(' ', '') }}

如果我已經把它列為清單

---

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

我可以設置值

{{ CSV_STRING | join(',') }}

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

def main():
    argument_spec = dict(
...
        value=dict(type='list', elements='str'),
...

以及route53的文檔 – 在 Amazons Route 53 DNS 服務中添加或刪除條目說,對於參數value ,需要一個字符串元素列表。

這意味着,您需要做相反的事情,將逗號上的字符串拆分成一個列表。

進一步問答

我作弊並默認了命令模塊

我仍然想使用 route53 模塊並解決問題。

我有一個模板

{ 
  "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] }}\""
          }
        ]
      }
    }
  ]
}

劇情好像

- 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM