community.general.cloudflare_dns module – Manage Cloudflare DNS records
Note
This module is part of the community.general collection (version 10.7.5).
You might already have this collection installed if you are using the ansible package.
It is not included in ansible-core.
To check whether it is installed, run ansible-galaxy collection list.
To install it, use: ansible-galaxy collection install community.general.
To use it in a playbook, specify: community.general.cloudflare_dns.
Synopsis
- Manages DNS records using the Cloudflare API, see the docs: https://api.cloudflare.com/. 
Parameters
| Parameter | Comments | 
|---|---|
| Account API key. Required for API keys authentication. You can obtain your API key from the bottom of the Cloudflare ‘My Account’ page, found here: https://dash.cloudflare.com/. | |
| Account email. Required for API keys authentication. | |
| Algorithm number. Required for  | |
| API token. Required for API token authentication. You can obtain your API token from the bottom of the Cloudflare ‘My Account’ page, found here: https://dash.cloudflare.com/. Can be specified in  | |
| Comments or notes about the DNS record. | |
| DNSSEC key tag. Needed for  | |
| Proxy through Cloudflare network or just use DNS. Choices: 
 | |
| Record service. Required for  | |
| Whether the record should be the only one for that record type and record name. Only use with  This deletes all other records with the same record name and type. Choices: 
 | |
| Whether the record(s) should exist or not. Choices: 
 | |
| CAA issue restriction. Required for  Choices: 
 | |
| Custom tags for the DNS record. | |
| Timeout for Cloudflare API calls. Default:  | |
| The TTL to give the new record. Must be between  Default:  | |
| The type of DNS record to create. Required if  Support for  Support for  Choices: 
 | |
| The record value. Required for  | |
| The name of the Zone to work with (for example  The Zone must already exist. | 
Attributes
| Attribute | Support | Description | 
|---|---|---|
| Support: full | Can run in  | |
| Support: none | Will return details on what has changed (or possibly needs changing in  | 
Examples
- name: Create a test.example.net A record to point to 127.0.0.1
  community.general.cloudflare_dns:
    zone: example.net
    record: test
    type: A
    value: 127.0.0.1
    account_email: [email protected]
    account_api_key: dummyapitoken
  register: record
- name: Create a record using api token
  community.general.cloudflare_dns:
    zone: example.net
    record: test
    type: A
    value: 127.0.0.1
    api_token: dummyapitoken
- name: Create a record with comment and tags
  community.general.cloudflare_dns:
    zone: example.net
    record: test
    type: A
    value: 127.0.0.1
    comment: Local test website
    tags:
      - test
      - local
    api_token: dummyapitoken
- name: Create a example.net CNAME record to example.com
  community.general.cloudflare_dns:
    zone: example.net
    type: CNAME
    value: example.com
    account_email: [email protected]
    account_api_key: dummyapitoken
    state: present
- name: Change its TTL
  community.general.cloudflare_dns:
    zone: example.net
    type: CNAME
    value: example.com
    ttl: 600
    account_email: [email protected]
    account_api_key: dummyapitoken
    state: present
- name: Delete the record
  community.general.cloudflare_dns:
    zone: example.net
    type: CNAME
    value: example.com
    account_email: [email protected]
    account_api_key: dummyapitoken
    state: absent
- name: Create a example.net CNAME record to example.com and proxy through Cloudflare's network
  community.general.cloudflare_dns:
    zone: example.net
    type: CNAME
    value: example.com
    proxied: true
    account_email: [email protected]
    account_api_key: dummyapitoken
    state: present
# This deletes all other TXT records named "test.example.net"
- name: Create TXT record "test.example.net" with value "unique value"
  community.general.cloudflare_dns:
    domain: example.net
    record: test
    type: TXT
    value: unique value
    solo: true
    account_email: [email protected]
    account_api_key: dummyapitoken
    state: present
- name: Create an SRV record _foo._tcp.example.net
  community.general.cloudflare_dns:
    domain: example.net
    service: foo
    proto: tcp
    port: 3500
    priority: 10
    weight: 20
    type: SRV
    value: fooserver.example.net
- name: Create a SSHFP record login.example.com
  community.general.cloudflare_dns:
    zone: example.com
    record: login
    type: SSHFP
    algorithm: 4
    hash_type: 2
    value: 9dc1d6742696d2f51ca1f1a78b3d16a840f7d111eb9454239e70db31363f33e1
- name: Create a TLSA record _25._tcp.mail.example.com
  community.general.cloudflare_dns:
    zone: example.com
    record: mail
    port: 25
    proto: tcp
    type: TLSA
    cert_usage: 3
    selector: 1
    hash_type: 1
    value: 6b76d034492b493e15a7376fccd08e63befdad0edab8e442562f532338364bf3
- name: Create a CAA record subdomain.example.com
  community.general.cloudflare_dns:
    zone: example.com
    record: subdomain
    type: CAA
    flag: 0
    tag: issue
    value: ca.example.com
- name: Create a DS record for subdomain.example.com
  community.general.cloudflare_dns:
    zone: example.com
    record: subdomain
    type: DS
    key_tag: 5464
    algorithm: 8
    hash_type: 2
    value: B4EB5AC4467D2DFB3BAF9FB9961DC1B6FED54A58CDFAA3E465081EC86F89BFAB
Return Values
Common return values are documented here, the following are the fields unique to this module:
| Key | Description | 
|---|---|
| A dictionary containing the record data. Returned: success, except on record deletion | |
| Comments or notes about the DNS record. Returned: success Sample:  | |
| When the record comment was last modified. Omitted if there is no comment. Returned: success Sample:  | |
| The record content (details depend on record type). Returned: success Sample:  | |
| The record creation date. Returned: success Sample:  | |
| Additional record data. Returned: success, if type is SRV, DS, SSHFP TLSA or CAA Sample:  | |
| The record ID. Returned: success Sample:  | |
| No documentation available. Returned: success Sample:  | |
| Extra Cloudflare-specific information about the record. Returned: success Sample:  | |
| Record modification date. Returned: success Sample:  | |
| The record name as FQDN (including _service and _proto for SRV). Returned: success Sample:  | |
| Priority of the MX record. Returned: success, if type is MX Sample:  | |
| Whether this record can be proxied through Cloudflare. Returned: success Sample:  | |
| Whether the record is proxied through Cloudflare. Returned: success Sample:  | |
| Custom tags for the DNS record. Returned: success Sample:  | |
| When the record tags were last modified. Omitted if there are no tags. Returned: success Sample:  | |
| The time-to-live for the record. Returned: success Sample:  | |
| The record type. Returned: success Sample:  | |
| The ID of the zone containing the record. Returned: success Sample:  | |
| The name of the zone containing the record. Returned: success Sample:  | 
