Bookmarks

You haven't yet saved any bookmarks. To bookmark a post, just click .

  • Change DNS records at cloudflare with ansible

  • For my current company i had the task to setup a lot of domains within cloudflare and change/setup DNS records in a reproducible way. So i came up with the idea to use puppet for this, but i couldn’t find a good module for puppet to manage this. But i wanted to play a little bit with ansible and ansible has since version 2.2 support for cloudflare_dns

    ---
    - hosts: localhost
      vars:
        cloudflare_email: account@domain.com
        cloudflare_api_token: 123456798
        domain: domain.com
      tasks:
      - name: add several a records
        cloudflare_dns:
          zone:  "{{ domain }}"
          record: "{{ item.domain }}"
          type: A
          value: "{{ item.ip }}"
          ttl: 1
          account_email: "{{ cloudflare_email }}"
          account_api_token: "{{ cloudflare_api_token }}"
        with_items:
          - { domain: 'mailin', ip: '10.10.129.142' }
          - { domain: 'static', ip: '10.10.129.139' }
          - { domain: 'static1', ip: '10.10.129.139' }
          - { domain: 'static2', ip: '10.10.129.139' }
          - { domain: 'static3', ip: '10.10.129.139' }
          - { domain: 'static4', ip: '10.10.129.139' }
          - { domain: 'static5', ip: '10.10.129.139' }
          - { domain: 'static6', ip: '10.10.129.139' }
          - { domain: 'static7', ip: '10.10.129.139' }
          - { domain: 'static8', ip: '10.10.129.139' }
          - { domain: 'static9', ip: '10.10.129.139' }
      - name: add several cname records
        cloudflare_dns:
          zone:  "{{ domain }}"
          record: "{{ item.domain }}"
          type: CNAME
          value: "{{ item.target }}"
          ttl: 1
          account_email: "{{ cloudflare_email }}"
          account_api_token: "{{ cloudflare_api_token }}"
        with_items:
          - { domain: 'mout', target: 'mailout.domain.com' }
          - { domain: 'mail', target: 'mail2.domain.com' }