ansible.builtin.cloudflare_dns (v2.5.11) — 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.5.11

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.
# 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.
# create a my.com CNAME record to example.com
- cloudflare_dns:
    zone: my.com
    type: CNAME
    value: example.com
    state: present
    account_email: test@example.com
    account_api_token: dummyapitoken
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# change it's ttl
- cloudflare_dns:
    zone: my.com
    type: CNAME
    value: example.com
    ttl: 600
    state: present
    account_email: test@example.com
    account_api_token: dummyapitoken
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# and delete the record
- cloudflare_dns:
    zone: my.com
    type: CNAME
    value: example.com
    state: absent
    account_email: test@example.com
    account_api_token: dummyapitoken
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
    state: present
    proxied: yes
    account_email: test@example.com
    account_api_token: dummyapitoken
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# create TXT record "test.my.com" with value "unique value"
# delete all other TXT records named "test.my.com"
- cloudflare_dns:
    domain: my.com
    record: test
    type: TXT
    value: unique value
    state: present
    solo: true
    account_email: test@example.com
    account_api_token: dummyapitoken
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# create a 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

Inputs

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

port:
    default: null
    description: Service port. Required for C(type=SRV)
    required: false

solo:
    default: null
    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.
    required: false

type:
    choices:
    - A
    - AAAA
    - CNAME
    - TXT
    - SRV
    - MX
    - NS
    - SPF
    default: null
    description:
    - The type of DNS record to create. Required if C(state=present)
    required: false

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

proto:
    choices:
    - tcp
    - udp
    default: null
    description: Service protocol. Required for C(type=SRV)
    required: false

state:
    choices:
    - present
    - absent
    default: present
    description:
    - Whether the record(s) should exist or not
    required: false

value:
    aliases:
    - content
    default: null
    description:
    - The record value. Required for C(state=present)
    required: false

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

weight:
    default: '1'
    description: Service weight. Required for C(type=SRV)
    required: false

proxied:
    default: false
    description: Proxy through cloudflare network or just use DNS
    required: false
    version_added: '2.3'
    version_added_collection: ansible.builtin

service:
    default: null
    description: Record service. Required for C(type=SRV)
    required: false

timeout:
    default: 30
    description:
    - Timeout for Cloudflare API calls
    required: false

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

account_email:
    description:
    - Account email.
    required: true

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://www.cloudflare.com/a/account)

      '
    required: true

Outputs

record:
  contains:
    content:
      description: the record content (details depend on record type)
      returned: success
      sample: 192.0.2.91
      type: string
    created_on:
      description: the record creation date
      returned: success
      sample: '2016-03-25T19:09:42.516553+00:00'
      type: string
    data:
      description: additional record data
      returned: success, if type is SRV
      sample:
        name: jabber
        port: 8080
        priority: 10
        proto: _tcp
        service: _xmpp
        target: jabberhost.sample.com
        weight: 5
      type: dictionary
    id:
      description: the record id
      returned: success
      sample: f9efb0549e96abcb750de63b38c9576e
      type: string
    locked:
      description: No documentation available
      returned: success
      sample: false
      type: boolean
    meta:
      description: No documentation available
      returned: success
      sample:
        auto_added: false
      type: dictionary
    modified_on:
      description: record modification date
      returned: success
      sample: '2016-03-25T19:09:42.516553+00:00'
      type: string
    name:
      description: the record name as FQDN (including _service and _proto for SRV)
      returned: success
      sample: www.sample.com
      type: string
    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: boolean
    proxied:
      description: whether the record is proxied through cloudflare
      returned: success
      sample: false
      type: boolean
    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: string
    zone_id:
      description: the id of the zone containing the record
      returned: success
      sample: abcede0bf9f0066f94029d2e6b73856a
      type: string
    zone_name:
      description: the name of the zone containing the record
      returned: success
      sample: sample.com
      type: string
  description: dictionary containing the record data
  returned: success, except on record deletion
  type: complex