A simple 'dynamic dns'-client with Ansible and Cloudflare

My ISP does not give me a static IP. It doesn’t change often, but in the rare case that it has changed I never discover it before I actually need it.

So. I wanted a very simple way of auto-updating the home.example.com record. I didn’t want to bother with a thirdparty client from something like dyndns (and I didn’t want to pay for anything).

As I use Cloudflare as dns service for all domains I own I could just use their API and solve it with a oneliner, but doing it with Ansible is more readable

- hosts: localhost
  connection: local

  - cf_zone: 'example.com'
    cf_record: 'home'
    cf_email: 'email-for-cloudflare-login'
    cf_api_token: 'your-api-token-from-cloudflare'
  - name: Get current public IP address
      url: 'https://ipinfo.io/ip'
      return_content: yes
    register: public_ip

  - name: Update DNS record
      zone: '{{ cf_zone }}'
      record: '{{ cf_record }}'
      type: A
      value: '{{ public_ip.content | trim }}'
      state: present
      account_email: '{{ cf_email }}'
      account_api_token: '{{ cf_api_token }}'

  - name: Create Cron job
      name: Update DNS record
      minute: '*/15'
      job: 'ansible-playbook -i "localhost," /path/to/ansible/playbook.yml'