ops-guru / godaddy_ansible_role

GoDaddy DNS records management role
BSD 2-Clause "Simplified" License
13 stars 13 forks source link

Removing records enhancement #6

Open dtio opened 1 year ago

dtio commented 1 year ago

The current role doesn't seem to remove multiple dns records, I have updated the remove.record.yml using the DELETE method and the removal for multiple dns records seems to work well now. Below are the code.

# vim: ts=2 sw=2 et ft=ansible.yaml
---
# tasks file for nrg.godaddy
- name: setup api_server_url
  set_fact:
    api_server_url: '{{api_server}}/v{{api_version}}/domains/{{domain_name}}/records/{{type}}/{{record_name}}'
    authorization:  'sso-key {{api_key}}:{{api_secret}}'

- name: search for record in goddady
  uri:
    url:          '{{api_server_url}}'
    method:       GET
    headers:
      Authorization: '{{authorization}}'
  register: record

- name: call godaddy api to delete a record
  uri:
    url:          '{{api_server_url}}'
    method:       DELETE
    status_code: [200,204]
    headers:
      Authorization: '{{authorization}}'
      Accept: 'application/json'
  when:
  - record.json | length > 0