damex.cloudflare.cloudflare_dns_record module – Ensure Cloudflare DNS record

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_record.

Synopsis

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.

content

string

DNS record content.

Required when 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 A record
  damex.cloudflare.cloudflare_dns_record:
    zone_name: example.com
    api_token: "{{ cloudflare_api_token }}"
    record: www
    type: A
    content: 192.0.2.1

- name: Ensure AAAA record
  damex.cloudflare.cloudflare_dns_record:
    zone_name: example.com
    api_token: "{{ cloudflare_api_token }}"
    record: www
    type: AAAA
    content: 2001:db8::1

- name: Ensure MX record
  damex.cloudflare.cloudflare_dns_record:
    zone_name: example.com
    api_token: "{{ cloudflare_api_token }}"
    record: example.com
    type: MX
    content: mail.example.com
    priority: 10

- name: Ensure CNAME record with proxy
  damex.cloudflare.cloudflare_dns_record:
    zone_name: example.com
    api_token: "{{ cloudflare_api_token }}"
    record: blog
    type: CNAME
    content: example.com
    proxied: true

- name: Ensure TXT record
  damex.cloudflare.cloudflare_dns_record:
    zone_name: example.com
    api_token: "{{ cloudflare_api_token }}"
    record: example.com
    type: TXT
    content: v=spf1 include:_spf.example.com ~all

- name: Ensure DNS record is absent
  damex.cloudflare.cloudflare_dns_record:
    zone_name: example.com
    api_token: "{{ cloudflare_api_token }}"
    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

dns_record

dictionary

DNS record object from the Cloudflare API.

Returned: when state is present

content

string

Record content.

Returned: success

id

string

Record identifier.

Returned: success

name

string

Record name.

Returned: success

priority

integer

Record priority.

Returned: success

proxied

boolean

Proxy status.

Returned: success

ttl

integer

Record TTL.

Returned: success

type

string

Record type.

Returned: success

Authors

  • Roman Kuzmitskii (@damex)