Compare commits
10 commits
56ae984a94
...
8789c9d594
Author | SHA1 | Date | |
---|---|---|---|
8789c9d594 | |||
e87a0cf268 | |||
2d4dc4ac48 | |||
0e6228b751 | |||
b79fb76f25 | |||
3dd6c77eae | |||
70fd56adcd | |||
66e6c4d30a | |||
e538a528d1 | |||
2def875433 |
7 changed files with 31 additions and 22 deletions
12
README.md
12
README.md
|
@ -1,10 +1,18 @@
|
||||||
# cfdns
|
# cfdns
|
||||||
|
|
||||||
Sample Ansible role to create CloudFlare DNS records
|
Sample Ansible role to create/remove CloudFlare DNS records
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
1) See `roles/defaults/vars.yml` for sample DNS zone entry definitions -- change/remove these as desired
|
1) See `roles/create-records/vars/sample.yml` for sample DNS zone entry definitions -- change 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:
|
||||||
```
|
```
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
[defaults]
|
[defaults]
|
||||||
nocows=True
|
nocows=True
|
||||||
|
localhost_warning=False
|
||||||
|
gathering=smart
|
2
domains
2
domains
|
@ -1 +1 @@
|
||||||
roles/create-records/vars
|
roles/manage-records/vars
|
8
play.yml
8
play.yml
|
@ -2,13 +2,15 @@
|
||||||
- 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: "enforce state for {{item}}"
|
- name: import cloudflare creds
|
||||||
|
include_vars:
|
||||||
|
file: "~/.cloudflare.yml"
|
||||||
|
- name: "manage-records: include role"
|
||||||
include_role:
|
include_role:
|
||||||
name: create-records
|
name: manage-records
|
||||||
vars_from: "{{item}}"
|
vars_from: "{{item}}"
|
||||||
with_items: "{{domains}}"
|
with_items: "{{domains}}"
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
domain: sampledomain.local
|
|
||||||
records:
|
|
||||||
- name: 'subdomain'
|
|
||||||
value: '127.0.0.1'
|
|
||||||
type: A
|
|
||||||
- name: 'subdomain'
|
|
||||||
value: '::1'
|
|
||||||
type: AAAA
|
|
|
@ -1,20 +1,15 @@
|
||||||
---
|
---
|
||||||
|
|
||||||
- name: import cloudflare creds
|
- name: "manage records for ({{ domain }})"
|
||||||
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
|
solo: "{{ 'yes' if record.state in ['present'] | default(false) else omit }}"
|
||||||
state: present
|
state: "{{ record.state }}" # don't assume / set a default, require explicit instruction
|
||||||
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')
|
|
10
roles/manage-records/vars/sampledomain.local.yml
Normal file
10
roles/manage-records/vars/sampledomain.local.yml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
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
|
Loading…
Reference in a new issue