Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cloudflare_dns: deleting DNS records not working anymore due to API change #9652

Closed
1 task done
ibot3 opened this issue Jan 30, 2025 · 4 comments
Closed
1 task done
Labels
bug This issue/PR relates to a bug has_pr module module plugins plugin (any type) traceback

Comments

@ibot3
Copy link

ibot3 commented Jan 30, 2025

Summary

As announced on 2025-01-27 here, the entries returned by https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records no longer include the zone_id parameter.

Records returned by the API will no longer contain the zone_id and zone_name fields. This change may take up to four weeks to fully roll out. The affected fields were deprecated with an End of Life (EOL) date of November 30, 2024.

However, the parameter is used in the delete_dns_records action of cloudflare_dns:

for rr in records:
if params['solo']:
if not ((rr['type'] == params['type']) and (rr['name'] == search_record) and (rr['content'] == content)):
self.changed = True
if not self.module.check_mode:
result, info = self._cf_api_call('/zones/{0}/dns_records/{1}'.format(rr['zone_id'], rr['id']), 'DELETE')
else:
self.changed = True
if not self.module.check_mode:
result, info = self._cf_api_call('/zones/{0}/dns_records/{1}'.format(rr['zone_id'], rr['id']), 'DELETE')

This results in line 659, in delete_dns_records; KeyError: 'zone_id' (line differs because of older version)

Issue Type

Bug Report

Component Name

cloudflare_dns

Ansible Version

$ ansible --version
ansible [core 2.16.14]
  python version = 3.11.2 (main, Sep 14 2024, 03:00:30) [GCC 12.2.0] 
  jinja version = 3.1.4
  libyaml = True

Community.general Version

$ ansible-galaxy collection list community.general
Collection        Version
----------------- -------
community.general 8.5.0  

Configuration

$ ansible-config dump --only-changed

OS / Environment

Debian

Steps to Reproduce

- name: Delete records on cloudflare
  community.general.cloudflare_dns:
    zone: "{{ item }}"
    record: "{{ ... }}"
    type: CNAME
    value: "..."
    account_email: "{{ ... }}"
    api_token: "{{ ...  }}"
    proxied: false
    state: absent

Expected Results

Action should not fail

Actual Results

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'zone_id'
failed: [localhost] (item=xxx) => {"ansible_loop_var": "item", "changed": false, "item": "xxx", "module_stderr": "Traceback (most recent call last):\n  File \"/opt/app/.ansible/tmp/ansible-tmp-1738249809.769321-1864504-247335003966029/AnsiballZ_cloudflare_dns.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/opt/app/.ansible/tmp/ansible-tmp-1738249809.769321-1864504-247335003966029/AnsiballZ_cloudflare_dns.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/opt/app/.ansible/tmp/ansible-tmp-1738249809.769321-1864504-247335003966029/AnsiballZ_cloudflare_dns.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.general.plugins.modules.cloudflare_dns', init_globals=dict(_module_fqn='ansible_collections.community.general.plugins.modules.cloudflare_dns', _modlib_path=modlib_path),\n  File \"<frozen runpy>\", line 226, in run_module\n  File \"<frozen runpy>\", line 98, in _ru
 n_module_code\n  File \"<frozen runpy>\", line 88, in _run_code\n  File \"/tmp/ansible_community.general.cloudflare_dns_payload_1i4wdn7s/ansible_community.general.cloudflare_dns_payload.zip/ansible_collections/community/general/plugins/modules/cloudflare_dns.py\", line 949, in <module>\n  File \"/tmp/ansible_community.general.cloudflare_dns_payload_1i4wdn7s/ansible_community.general.cloudflare_dns_payload.zip/ansible_collections/community/general/plugins/modules/cloudflare_dns.py\", line 944, in main\n  File \"/tmp/ansible_community.general.cloudflare_dns_payload_1i4wdn7s/ansible_community.general.cloudflare_dns_payload.zip/ansible_collections/community/general/plugins/modules/cloudflare_dns.py\", line 659, in delete_dns_records\nKeyError: 'zone_id'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibullbot
Copy link
Collaborator

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module module plugins plugin (any type) traceback labels Jan 30, 2025
@valievkarim
Copy link
Contributor

Hello
Fix proposed here #9649

@ibot3
Copy link
Author

ibot3 commented Jan 31, 2025

Can be closed as #9649 got merged.

@ibot3 ibot3 closed this as completed Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug has_pr module module plugins plugin (any type) traceback
Projects
None yet
Development

No branches or pull requests

3 participants