On this page
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
The below requirements are needed on the host that executes this module.
- python >= 2.6
 
Parameters
| Parameter | Choices/Defaults | Comments | 
|---|---|---|
| account_api_token  
        required
         | 
      
        
        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  
        required
         | 
      
        
        Account email.
         | 
     |
| port | 
        
        Service port. Required for  type=SRV
        | 
     |
| priority | Default: 
        "1"
         | 
      
        
        Record priority. Required for  type=MX and type=SRV
        | 
     
| proto | 
        
        Service protocol. Required for  
       type=SRV.
       
        Common values are tcp and udp.
        
       
        Before Ansible 2.6 only tcp and udp were available.
         | 
     |
| proxied  
        bool
         
        (added in 2.3)
         | 
      
       
  | 
      
        
        Proxy through cloudflare network or just use DNS
         | 
     
| record | Default: 
        "@"
         | 
      
        
        Record to add. Required if  
       state=present. Default is @ (e.g. the zone name)
       aliases: name  | 
     
| service | 
        
        Record service. Required for  type=SRV
        | 
     |
| solo | 
        
        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 | 
       
  | 
      
        
        Whether the record(s) should exist or not
         | 
     
| timeout | Default: 
        30
         | 
      
        
        Timeout for Cloudflare API calls
         | 
     
| ttl | Default: 
        "1 (automatic)"
         | 
      
        
        The TTL to give the new record. Must be between 120 and 2,147,483,647 seconds, or 1 for automatic.
         | 
     
| type | 
       
  | 
      
        
        The type of DNS record to create. Required if  state=present
        | 
     
| value | 
        
        The record value. Required for  
       state=present
       aliases: content  | 
     |
| weight | Default: 
        "1"
         | 
      
        
        Service weight. Required for  type=SRV
        | 
     
| zone  
        required
         | 
      
        
        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: test@example.com
    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: test@example.com
    account_api_token: dummyapitoken
# 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
# 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
# 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
# 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
# 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, the following are the fields unique to this module:
| Key | Returned | Description | |
|---|---|---|---|
| record  
        complex
         | 
      success, except on record deletion | 
        
        dictionary containing the record data
          | 
     |
| content  
        string
         | 
      success | 
        
        the record content (details depend on record type)
         Sample:
        
       
        192.0.2.91
         | 
     |
| created_on  
        string
         | 
      success | 
        
        the record creation date
         Sample:
        
       
        2016-03-25 19:09:42.516553
         | 
     |
| data  
        dictionary
         | 
      success, if type is SRV | 
        
        additional record data
         Sample:
        
       
        {'name': 'jabber', 'port': 8080, 'priority': 10, 'proto': '_tcp', 'service': '_xmpp', 'target': 'jabberhost.sample.com', 'weight': 5}
         | 
     |
| id  
        string
         | 
      success | 
        
        the record id
         Sample:
        
       
        f9efb0549e96abcb750de63b38c9576e
         | 
     |
| locked  
        boolean
         | 
      success | 
        
        No documentation available
          | 
     |
| meta  
        dictionary
         | 
      success | 
        
        No documentation available
         Sample:
        
       
        {'auto_added': False}
         | 
     |
| modified_on  
        string
         | 
      success | 
        
        record modification date
         Sample:
        
       
        2016-03-25 19:09:42.516553
         | 
     |
| name  
        string
         | 
      success | 
        
        the record name as FQDN (including _service and _proto for SRV)
         Sample:
        
       
        www.sample.com
         | 
     |
| priority  
        int
         | 
      success, if type is MX | 
        
        priority of the MX record
         Sample:
        
       
        10
         | 
     |
| proxiable  
        boolean
         | 
      success | 
        
        whether this record can be proxied through cloudflare
          | 
     |
| proxied  
        boolean
         | 
      success | 
        
        whether the record is proxied through cloudflare
          | 
     |
| ttl  
        int
         | 
      success | 
        
        the time-to-live for the record
         Sample:
        
       
        300
         | 
     |
| type  
        string
         | 
      success | 
        
        the record type
         Sample:
        
       
        A
         | 
     |
| zone_id  
        string
         | 
      success | 
        
        the id of the zone containing the record
         Sample:
        
       
        abcede0bf9f0066f94029d2e6b73856a
         | 
     |
| zone_name  
        string
         | 
      success | 
        
        the name of the zone containing the record
         Sample:
        
       
        sample.com
         | 
     |
Status
This module is flagged as preview which means that it is not guaranteed to have a backwards compatible interface.
Maintenance
This module is flagged as community which means that it is maintained by the Ansible Community. See Module Maintenance & Support for more info.
For a list of other modules that are also maintained by the Ansible Community, see here.
Author
- Michael Gruener (@mgruener)
 
Hint
If you notice any issues in this documentation you can edit this document to improve it.
© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
 https://docs.ansible.com/ansible/2.6/modules/cloudflare_dns_module.html