diff --git a/domains b/domains index 9d33abd..7fe77e7 120000 --- a/domains +++ b/domains @@ -1 +1 @@ -roles/create-records/vars \ No newline at end of file +roles/manage-records/vars \ No newline at end of file diff --git a/roles/manage-records/tasks/main.yml b/roles/manage-records/tasks/main.yml index 417598f..f43aaf5 100644 --- a/roles/manage-records/tasks/main.yml +++ b/roles/manage-records/tasks/main.yml @@ -1,16 +1,15 @@ --- -- name: "create records ({{domain}})" +- name: "manage records for ({{ domain }})" cloudflare_dns: zone: "{{ domain }}" record: "{{ record.name }}" value: "{{ record.value }}" type: "{{ record.type }}" - solo: yes - state: present + solo: "{{ 'yes' if record.state in ['present'] | default(false) else omit }}" + state: "{{ record.state }}" # don't assume / set a default, require explicit instruction 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') diff --git a/roles/manage-records/vars/sample.yml b/roles/manage-records/vars/sample.yml deleted file mode 100644 index 9e406be..0000000 --- a/roles/manage-records/vars/sample.yml +++ /dev/null @@ -1,8 +0,0 @@ -domain: sampledomain.local -records: - - name: 'subdomain' - value: '127.0.0.1' - type: A - - name: 'subdomain' - value: '::1' - type: AAAA diff --git a/roles/manage-records/vars/sampledomain.local.yml b/roles/manage-records/vars/sampledomain.local.yml new file mode 100644 index 0000000..914816b --- /dev/null +++ b/roles/manage-records/vars/sampledomain.local.yml @@ -0,0 +1,10 @@ +domain: sampledomain.local +records: + - name: 'subdomain' # create a silly localhost subdomain.sampledomain.io A record (IPv4) + value: '127.0.0.1' + type: A + state: present + - name: 'subdomain' # remove equally silly subdomain.sampledomain.io AAAA record (IPv6 local) + value: '::1' + type: AAAA + state: absent