W3cubDocs

/Ansible

cloudflare_dns - manage Cloudflare DNS records

New in version 2.1.

Synopsis

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

Requirements (on host that executes module)

  • python >= 2.6

Options

parameter required default choices comments
account_api_token
yes
Account API token. You can obtain your API key from the bottom of the Cloudflare 'My Account' page, found here: https://www.cloudflare.com/a/account
account_email
yes
Account email.
port
no
Service port. Required for type=SRV
priority
no 1
Record priority. Required for type=MX and type=SRV
proto
no
  • tcp
  • udp
Service protocol. Required for type=SRV
proxied
(added in 2.3)
no
Proxy through cloudflare network or just use DNS
record
no @
Record to add. Required if state=present. Default is @ (e.g. the zone name)
aliases: name
service
no
Record service. Required for type=SRV
solo
no
Whether the record should be the only one for that record type and record name. Only use with state=present
This will delete all other records with the same record name and type.
state
no present
  • present
  • absent
Whether the record(s) should exist or not
timeout
no 30
Timeout for Cloudflare API calls
ttl
no 1 (automatic)
The TTL to give the new record. Must be between 120 and 2,147,483,647 seconds, or 1 for automatic.
type
no
  • A
  • AAAA
  • CNAME
  • TXT
  • SRV
  • MX
  • NS
  • SPF
The type of DNS record to create. Required if state=present
value
no
The record value. Required for state=present
aliases: content
weight
no 1
Service weight. Required for type=SRV
zone
yes
The name of the Zone to work with (e.g. "example.com"). The Zone must already exist.
aliases: domain

Examples

# 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: [email protected]
    account_api_token: dummyapitoken
  register: record

# create a my.com CNAME record to example.com
- cloudflare_dns:
    zone: my.com
    type: CNAME
    value: example.com
    state: present
    account_email: [email protected]
    account_api_token: dummyapitoken

# change it's ttl
- cloudflare_dns:
    zone: my.com
    type: CNAME
    value: example.com
    ttl: 600
    state: present
    account_email: [email protected]
    account_api_token: dummyapitoken

# and delete the record
- cloudflare_dns:
    zone: my.com
    type: CNAME
    value: example.com
    state: absent
    account_email: [email protected]
    account_api_token: dummyapitoken

# 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: [email protected]
    account_api_token: dummyapitoken

# 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: [email protected]
    account_api_token: dummyapitoken

# 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

Return Values

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

name description returned type sample
record dictionary containing the record data success, except on record deletion dictionary
contains:
name description returned type sample
proxiable whether this record can be proxied through cloudflare success boolean False
locked No documentation available success boolean False
name the record name as FQDN (including _service and _proto for SRV) success string www.sample.com
data additional record data success, if type is SRV dictionary {'priority': 10, 'target': 'jabberhost.sample.com', 'service': '_xmpp', 'proto': '_tcp', 'port': 8080, 'weight': 5, 'name': 'jabber'}
proxied whether the record is proxied through cloudflare success boolean False
priority priority of the MX record success, if type is MX int 10
created_on the record creation date success string 2016-03-25 19:09:42.516553
meta No documentation available success dictionary {'auto_added': False}
ttl the time-to-live for the record success int 300
modified_on record modification date success string 2016-03-25 19:09:42.516553
zone_name the name of the zone containing the record success string sample.com
content the record content (details depend on record type) success string 192.0.2.91
type the record type success string A
id the record id success string f9efb0549e96abcb750de63b38c9576e
zone_id the id of the zone containing the record success string abcede0bf9f0066f94029d2e6b73856a

This is an Extras Module

For more information on what this means please read Extras Modules

For help in developing on modules, should you be so inclined, please read Community Information & Contributing, developing_test_pr and Developing Modules.

© 2012–2016 Michael DeHaan
© 2016 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/cloudflare_dns_module.html