damex.cloudflare.cloudflare_dns_records module – Ensure Cloudflare DNS records for a zone

Note

This module is part of the damex.cloudflare collection (version 1.2.3).

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 damex.cloudflare.

To use it in a playbook, specify: damex.cloudflare.cloudflare_dns_records.

Synopsis

  • Ensures DNS records for a Cloudflare zone using the batch API, see the docs: https://developers.cloudflare.com/dns/.

  • All records for the zone are reconciled in a single API call.

  • Records are matched by type, name, and content.

Parameters

Parameter

Comments

account_api_key

string

Cloudflare account API key.

Required together with account_email if api_token is not provided.

account_email

string

Cloudflare account email.

Required together with account_api_key if api_token is not provided.

api_token

string

Cloudflare API token.

Required if account_email and account_api_key are not provided.

Can be specified in CLOUDFLARE_TOKEN environment variable.

records

list / elements=dictionary / required

DNS records to ensure.

content

string

DNS record content.

Required when records[].state is present.

priority

integer

DNS record priority.

Required for MX and URI records.

proxied

boolean

Cloudflare proxy status.

Only applicable to A, AAAA, and CNAME records.

Choices:

  • false ← (default)

  • true

record

string / required

DNS record name (subdomain or @ for zone apex).

state

string

DNS record state.

Choices:

  • "absent"

  • "present" ← (default)

ttl

integer

DNS record TTL in seconds.

Value of 1 means automatic.

Default: 1

type

string / required

DNS record type.

Choices:

  • "A"

  • "AAAA"

  • "CAA"

  • "CNAME"

  • "DS"

  • "HTTPS"

  • "MX"

  • "NAPTR"

  • "NS"

  • "PTR"

  • "SMIMEA"

  • "SRV"

  • "SSHFP"

  • "SVCB"

  • "TLSA"

  • "TXT"

  • "URI"

zone_id

string

Zone identifier.

Required if zone_name is not provided.

zone_name

string

Zone domain name.

Required if zone_id is not provided.

Resolved to zone identifier via the Cloudflare API.

Attributes

Attribute

Support

Description

check_mode

Support: full

Supports check mode.

diff_mode

Support: full

Supports diff mode.

Examples

- name: Ensure DNS records for zone
  damex.cloudflare.cloudflare_dns_records:
    zone_name: example.com
    api_token: "{{ cloudflare_api_token }}"
    records:
      - record: "@"
        type: A
        content: 192.0.2.1
      - record: www
        type: CNAME
        content: example.com
        proxied: true
      - record: "@"
        type: MX
        content: mail.example.com
        priority: 10
      - record: "@"
        type: TXT
        content: v=spf1 include:_spf.example.com ~all
      - record: old
        type: A
        content: 192.0.2.99
        state: absent

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

deletes

list / elements=dictionary

Records deleted.

Returned: success

posts

list / elements=dictionary

Records created.

Returned: success

puts

list / elements=dictionary

Records updated.

Returned: success

Authors

  • Roman Kuzmitskii (@damex)