What is the name of the domain?
example.com
What is the error message?
API Bad request; Status: 400; Method: POST: /zones/XXXXX/dns_records
What is the issue you’re encountering
Unable to create DNS records on Cloudflare using Ansible
What steps have you taken to resolve the issue?
I am not sure if this is the right forum, as it seems like more of an issue with Ansible auth, than anything to do with Cloudflare. Posting it here, just incase someone can shed some ideas…
I wanted to manage our Cloudflare DNS records through Ansible and as such created a Cloudflare API Token which has DNS edit permissions for a specific DNS Zone. When I try to execute my playbook, it throws API bad request error. Whereas, when I use Postman to POST the same record with the same API token, it works.
This does not look like an issue with the token itself, as I tried to replace API token with Account Email and Account API Key, the response is same API bad request 400.
Can anyone please guide me what am I doing wrong?
- name: Create a customer facing A record in Cloudflare
community.general.cloudflare_dns:
zone: "example.com"
record: "login"
type: A
value: "200.200.200.200"
api_token: "MYPRIVATEAPITOKEN"
proxied: yes
state: present
Postman cURL command which provided correct output:
curl --location 'https://api.cloudflare.com/client/v4/zones/306ef97d12e62fc080ca38639d5ffa35/dns_records' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer MYPRIVATEAPITOKEN' \
--header 'Cookie: __cf_bm=GENERATEDCOOKIE' \
--data '{
"type": "A",
"name": "login.example.com",
"content": "200.200.200.200",
"ttl": 60,
"proxied": true
}
'