Ansible throws HTTP 400 for a valid Cloudflare API Token.
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?
My Playbook:
- 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
}
'
Exact Error Message: