Compare commits
No commits in common. "8789c9d5941e7820735acbc3cb955f364eef1cdf" and "56ae984a9486c8a3a8cb5def8bb6a873deb04bec" have entirely different histories.
8789c9d594
...
56ae984a94
7 changed files with 22 additions and 31 deletions
12
README.md
12
README.md
|
@ -1,18 +1,10 @@
|
|||
# cfdns
|
||||
|
||||
Sample Ansible role to create/remove CloudFlare DNS records
|
||||
Sample Ansible role to create CloudFlare DNS records
|
||||
|
||||
## Requirements
|
||||
|
||||
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
|
||||
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:
|
||||
```
|
||||
|
|
|
@ -1,4 +1,2 @@
|
|||
[defaults]
|
||||
nocows=True
|
||||
localhost_warning=False
|
||||
gathering=smart
|
2
domains
2
domains
|
@ -1 +1 @@
|
|||
roles/manage-records/vars
|
||||
roles/create-records/vars
|
8
play.yml
8
play.yml
|
@ -2,15 +2,13 @@
|
|||
- name: create cloudflare dns records
|
||||
hosts: localhost
|
||||
connection: local
|
||||
gather_facts: smart
|
||||
vars:
|
||||
domains:
|
||||
- sampledomain.local
|
||||
tasks:
|
||||
- name: import cloudflare creds
|
||||
include_vars:
|
||||
file: "~/.cloudflare.yml"
|
||||
- name: "manage-records: include role"
|
||||
- name: "enforce state for {{item}}"
|
||||
include_role:
|
||||
name: manage-records
|
||||
name: create-records
|
||||
vars_from: "{{item}}"
|
||||
with_items: "{{domains}}"
|
||||
|
|
|
@ -1,15 +1,20 @@
|
|||
---
|
||||
|
||||
- name: "manage records for ({{ domain }})"
|
||||
- name: import cloudflare creds
|
||||
include_vars:
|
||||
file: "~/.cloudflare.yml"
|
||||
|
||||
- name: "create records ({{domain}})"
|
||||
cloudflare_dns:
|
||||
zone: "{{ domain }}"
|
||||
record: "{{ record.name }}"
|
||||
value: "{{ record.value }}"
|
||||
type: "{{ record.type }}"
|
||||
solo: "{{ 'yes' if record.state in ['present'] | default(false) else omit }}"
|
||||
state: "{{ record.state }}" # don't assume / set a default, require explicit instruction
|
||||
solo: yes
|
||||
state: present
|
||||
account_email: "{{ cf_email }}"
|
||||
account_api_token: "{{ cf_token }}"
|
||||
loop: "{{ records }}"
|
||||
loop_control:
|
||||
loop_var: record
|
||||
when: (item.state is undefined) or (not item.state == 'absent')
|
8
roles/create-records/vars/sample.yml
Normal file
8
roles/create-records/vars/sample.yml
Normal file
|
@ -0,0 +1,8 @@
|
|||
domain: sampledomain.local
|
||||
records:
|
||||
- name: 'subdomain'
|
||||
value: '127.0.0.1'
|
||||
type: A
|
||||
- name: 'subdomain'
|
||||
value: '::1'
|
||||
type: AAAA
|
|
@ -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
|
Loading…
Reference in a new issue