ansible.builtin.cloudflare_dns (v2.9.27) — module

Manage Cloudflare DNS records

| "added in version" 2.1 of ansible.builtin"

Authors: Michael Gruener (@mgruener)

preview | supported by community

Install Ansible via pip

Install with pip install ansible==2.9.27

Description

Manages dns records via the Cloudflare API, see the docs: U(https://api.cloudflare.com/)


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create a test.my.com A record to point to 127.0.0.1
  cloudflare_dns:
    zone: my.com
    record: test
    type: A
    value: 127.0.0.1
    account_email: test@example.com
    account_api_token: dummyapitoken
  register: record
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create a my.com CNAME record to example.com
  cloudflare_dns:
    zone: my.com
    type: CNAME
    value: example.com
    account_email: test@example.com
    account_api_token: dummyapitoken
    state: present
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Change its TTL
  cloudflare_dns:
    zone: my.com
    type: CNAME
    value: example.com
    ttl: 600
    account_email: test@example.com
    account_api_token: dummyapitoken
    state: present
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Delete the record
  cloudflare_dns:
    zone: my.com
    type: CNAME
    value: example.com
    account_email: test@example.com
    account_api_token: dummyapitoken
    state: absent
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: create a my.com CNAME record to example.com and proxy through Cloudflare's network
  cloudflare_dns:
    zone: my.com
    type: CNAME
    value: example.com
    proxied: yes
    account_email: test@example.com
    account_api_token: dummyapitoken
    state: present
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# This deletes all other TXT records named "test.my.com"
- name: Create TXT record "test.my.com" with value "unique value"
  cloudflare_dns:
    domain: my.com
    record: test
    type: TXT
    value: unique value
    solo: true
    account_email: test@example.com
    account_api_token: dummyapitoken
    state: present
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create an SRV record _foo._tcp.my.com
  cloudflare_dns:
    domain: my.com
    service: foo
    proto: tcp
    port: 3500
    priority: 10
    weight: 20
    type: SRV
    value: fooserver.my.com
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create a SSHFP record login.example.com
  cloudflare_dns:
    zone: example.com
    record: login
    type: SSHFP
    algorithm: 4
    hash_type: 2
    value: 9dc1d6742696d2f51ca1f1a78b3d16a840f7d111eb9454239e70db31363f33e1
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create a TLSA record _25._tcp.mail.example.com
  cloudflare_dns:
    zone: example.com
    record: mail
    port: 25
    proto: tcp
    type: TLSA
    cert_usage: 3
    selector: 1
    hash_type: 1
    value: 6b76d034492b493e15a7376fccd08e63befdad0edab8e442562f532338364bf3
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create a DS record for subdomain.example.com
  cloudflare_dns:
    zone: example.com
    record: subdomain
    type: DS
    key_tag: 5464
    algorithm: 8
    hash_type: 2
    value: B4EB5AC4467D2DFB3BAF9FB9961DC1B6FED54A58CDFAA3E465081EC86F89BFAB

Inputs

    
ttl:
    default: 1
    description:
    - The TTL to give the new record.
    - Must be between 120 and 2,147,483,647 seconds, or 1 for automatic.
    type: int

port:
    description:
    - Service port.
    - Required for C(type=SRV) and C(type=TLSA).
    type: int

solo:
    description:
    - Whether the record should be the only one for that record type and record name.
    - Only use with C(state=present).
    - This will delete all other records with the same record name and type.
    type: bool

type:
    choices:
    - A
    - AAAA
    - CNAME
    - DS
    - MX
    - NS
    - SPF
    - SRV
    - SSHFP
    - TLSA
    - TXT
    description:
    - The type of DNS record to create. Required if C(state=present).
    - C(type=DS), C(type=SSHFP) and C(type=TLSA) added in Ansible 2.7.
    type: str

zone:
    aliases:
    - domain
    description:
    - The name of the Zone to work with (e.g. "example.com").
    - The Zone must already exist.
    required: true
    type: str

proto:
    description:
    - Service protocol. Required for C(type=SRV) and C(type=TLSA).
    - Common values are TCP and UDP.
    - Before Ansible 2.6 only TCP and UDP were available.
    type: str

state:
    choices:
    - absent
    - present
    default: present
    description:
    - Whether the record(s) should exist or not.
    type: str

value:
    aliases:
    - content
    description:
    - The record value.
    - Required for C(state=present).
    type: str

record:
    aliases:
    - name
    default: '@'
    description:
    - Record to add.
    - Required if C(state=present).
    - Default is C(@) (e.g. the zone name).
    type: str

weight:
    default: 1
    description:
    - Service weight.
    - Required for C(type=SRV).
    type: int

key_tag:
    description:
    - DNSSEC key tag.
    - Needed for C(type=DS) when C(state=present).
    type: int
    version_added: '2.7'
    version_added_collection: ansible.builtin

proxied:
    default: false
    description:
    - Proxy through Cloudflare network or just use DNS.
    type: bool
    version_added: '2.3'
    version_added_collection: ansible.builtin

service:
    description:
    - Record service.
    - Required for C(type=SRV)

timeout:
    default: 30
    description:
    - Timeout for Cloudflare API calls.
    type: int

priority:
    default: 1
    description:
    - Record priority.
    - Required for C(type=MX) and C(type=SRV)

selector:
    choices:
    - 0
    - 1
    description:
    - Selector number.
    - Required for C(type=TLSA) when C(state=present).
    type: int
    version_added: '2.7'
    version_added_collection: ansible.builtin

algorithm:
    description:
    - Algorithm number.
    - Required for C(type=DS) and C(type=SSHFP) when C(state=present).
    type: int
    version_added: '2.7'
    version_added_collection: ansible.builtin

hash_type:
    choices:
    - 1
    - 2
    description:
    - Hash type number.
    - Required for C(type=DS), C(type=SSHFP) and C(type=TLSA) when C(state=present).
    type: int
    version_added: '2.7'
    version_added_collection: ansible.builtin

cert_usage:
    choices:
    - 0
    - 1
    - 2
    - 3
    description:
    - Certificate usage number.
    - Required for C(type=TLSA) when C(state=present).
    type: int
    version_added: '2.7'
    version_added_collection: ansible.builtin

account_email:
    description:
    - Account email.
    required: true
    type: str

account_api_token:
    description:
    - Account API token.
    - 'You can obtain your API key from the bottom of the Cloudflare ''My Account'' page,
      found here: U(https://dash.cloudflare.com/)'
    required: true
    type: str

Outputs

record:
  contains:
    content:
      description: The record content (details depend on record type).
      returned: success
      sample: 192.0.2.91
      type: str
    created_on:
      description: The record creation date.
      returned: success
      sample: '2016-03-25T19:09:42.516553Z'
      type: str
    data:
      description: Additional record data.
      returned: success, if type is SRV, DS, SSHFP or TLSA
      sample:
        name: jabber
        port: 8080
        priority: 10
        proto: _tcp
        service: _xmpp
        target: jabberhost.sample.com
        weight: 5
      type: dict
    id:
      description: The record ID.
      returned: success
      sample: f9efb0549e96abcb750de63b38c9576e
      type: str
    locked:
      description: No documentation available.
      returned: success
      sample: false
      type: bool
    meta:
      description: No documentation available.
      returned: success
      sample:
        auto_added: false
      type: dict
    modified_on:
      description: Record modification date.
      returned: success
      sample: '2016-03-25T19:09:42.516553Z'
      type: str
    name:
      description: The record name as FQDN (including _service and _proto for SRV).
      returned: success
      sample: www.sample.com
      type: str
    priority:
      description: Priority of the MX record.
      returned: success, if type is MX
      sample: 10
      type: int
    proxiable:
      description: Whether this record can be proxied through Cloudflare.
      returned: success
      sample: false
      type: bool
    proxied:
      description: Whether the record is proxied through Cloudflare.
      returned: success
      sample: false
      type: bool
    ttl:
      description: The time-to-live for the record.
      returned: success
      sample: 300
      type: int
    type:
      description: The record type.
      returned: success
      sample: A
      type: str
    zone_id:
      description: The ID of the zone containing the record.
      returned: success
      sample: abcede0bf9f0066f94029d2e6b73856a
      type: str
    zone_name:
      description: The name of the zone containing the record.
      returned: success
      sample: sample.com
      type: str
  description: A dictionary containing the record data.
  returned: success, except on record deletion
  type: complex