commit 5a16d049753d33743ad1a76c310a161bf7cdf163 Author: Josh Lay Date: Sat Aug 22 01:45:15 2020 -0500 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a01ee28 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.*.swp diff --git a/README.md b/README.md new file mode 100644 index 0000000..1741af9 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# cfdns + +Sample Ansible role to create CloudFlare DNS records + +## Requirements + +1) See `roles/defaults/vars.yml` for sample DNS zone entry definitions -- change/remove these as desired + +2) Your CloudFlare email address and API key must be stored in `~/.cloudflare.yml` like so for authentication: +``` +--- +cf_email: you@domain.com +cf_token: abcdef123456 +``` +If this is a shared system, `chmod -v 0600 ~/.cloudflare.yml` once created to avoid potentially leaking credentials. diff --git a/play.yml b/play.yml new file mode 100644 index 0000000..ad5770b --- /dev/null +++ b/play.yml @@ -0,0 +1,7 @@ +--- +- name: create cloudflare dns records + hosts: localhost + connection: local + gather_facts: smart + roles: + - create-records diff --git a/roles/create-records/defaults/main.yml b/roles/create-records/defaults/main.yml new file mode 100644 index 0000000..4ac70fd --- /dev/null +++ b/roles/create-records/defaults/main.yml @@ -0,0 +1,14 @@ +--- +zones: + - name: jlay.dev + state: present + records: + - name: git.ry1 + value: "107.181.235.67" + type: A + - name: ry1 + value: "107.181.235.66" + type: A + - name: ry2 + value: "107.181.235.74" + type: A diff --git a/roles/create-records/tasks/main.yml b/roles/create-records/tasks/main.yml new file mode 100644 index 0000000..0e3ea24 --- /dev/null +++ b/roles/create-records/tasks/main.yml @@ -0,0 +1,8 @@ +--- + +- name: import cloudflare creds + include_vars: + file: "~/.cloudflare.yml" + +- include_tasks: zone.yml + loop: "{{ zones }}" diff --git a/roles/create-records/tasks/zone.yml b/roles/create-records/tasks/zone.yml new file mode 100644 index 0000000..a23c0eb --- /dev/null +++ b/roles/create-records/tasks/zone.yml @@ -0,0 +1,15 @@ +--- + +- name: create records + cloudflare_dns: + zone: "{{ item.name }}" + record: "{{ record.name }}" + value: "{{ record.value }}" + type: "{{ record.type }}" + solo: yes + account_email: "{{ cf_email }}" + account_api_token: "{{ cf_token }}" + loop: "{{ item.records }}" + loop_control: + loop_var: record + when: (not item.state == 'absent')