Compare commits

..

No commits in common. "8789c9d5941e7820735acbc3cb955f364eef1cdf" and "56ae984a9486c8a3a8cb5def8bb6a873deb04bec" have entirely different histories.

7 changed files with 22 additions and 31 deletions

View file

@ -1,18 +1,10 @@
# cfdns # cfdns
Sample Ansible role to create/remove CloudFlare DNS records Sample Ansible role to create CloudFlare DNS records
## Requirements ## Requirements
1) See `roles/create-records/vars/sample.yml` for sample DNS zone entry definitions -- change these as desired 1) See `roles/defaults/vars.yml` for sample DNS zone entry definitions -- change/remove these as desired
To add a domain, define it in the `domains` list in `play.yml`.
This will load the correlating file at `roles/create-records/vars/{{domain}}.yml`.
The symbolic link `./domains` was provided to make these files more accessible, not used for function -- can be removed.
_TODO_: Load files created here dynamically
2) Your CloudFlare email address and API key must be stored in `~/.cloudflare.yml` like so for authentication: 2) Your CloudFlare email address and API key must be stored in `~/.cloudflare.yml` like so for authentication:
``` ```

View file

@ -1,4 +1,2 @@
[defaults] [defaults]
nocows=True nocows=True
localhost_warning=False
gathering=smart

View file

@ -1 +1 @@
roles/manage-records/vars roles/create-records/vars

View file

@ -2,15 +2,13 @@
- name: create cloudflare dns records - name: create cloudflare dns records
hosts: localhost hosts: localhost
connection: local connection: local
gather_facts: smart
vars: vars:
domains: domains:
- sampledomain.local - sampledomain.local
tasks: tasks:
- name: import cloudflare creds - name: "enforce state for {{item}}"
include_vars:
file: "~/.cloudflare.yml"
- name: "manage-records: include role"
include_role: include_role:
name: manage-records name: create-records
vars_from: "{{item}}" vars_from: "{{item}}"
with_items: "{{domains}}" with_items: "{{domains}}"

View file

@ -1,15 +1,20 @@
--- ---
- name: "manage records for ({{ domain }})" - name: import cloudflare creds
include_vars:
file: "~/.cloudflare.yml"
- name: "create records ({{domain}})"
cloudflare_dns: cloudflare_dns:
zone: "{{ domain }}" zone: "{{ domain }}"
record: "{{ record.name }}" record: "{{ record.name }}"
value: "{{ record.value }}" value: "{{ record.value }}"
type: "{{ record.type }}" type: "{{ record.type }}"
solo: "{{ 'yes' if record.state in ['present'] | default(false) else omit }}" solo: yes
state: "{{ record.state }}" # don't assume / set a default, require explicit instruction state: present
account_email: "{{ cf_email }}" account_email: "{{ cf_email }}"
account_api_token: "{{ cf_token }}" account_api_token: "{{ cf_token }}"
loop: "{{ records }}" loop: "{{ records }}"
loop_control: loop_control:
loop_var: record loop_var: record
when: (item.state is undefined) or (not item.state == 'absent')

View file

@ -0,0 +1,8 @@
domain: sampledomain.local
records:
- name: 'subdomain'
value: '127.0.0.1'
type: A
- name: 'subdomain'
value: '::1'
type: AAAA

View file

@ -1,10 +0,0 @@
domain: sampledomain.local
records:
- name: 'subdomain' # create a silly localhost subdomain.sampledomain.local A record (IPv4)
value: '127.0.0.1'
type: A
state: present
- name: 'subdomain' # remove equally silly subdomain.sampledomain.local AAAA record (IPv6 local)
value: '::1'
type: AAAA
state: absent