From 7e17cf6b4165b9374c5ce2e99b937ca3f2158a38 Mon Sep 17 00:00:00 2001 From: Josh Lay Date: Sat, 18 Dec 2021 21:30:46 -0600 Subject: [PATCH] modernize, break out domains into vars files --- play.yml | 13 +++++++++++-- roles/create-records/defaults/main.yml | 14 -------------- roles/create-records/tasks/main.yml | 16 ++++++++++++++-- roles/create-records/tasks/zone.yml | 15 --------------- 4 files changed, 25 insertions(+), 33 deletions(-) delete mode 100644 roles/create-records/defaults/main.yml delete mode 100644 roles/create-records/tasks/zone.yml diff --git a/play.yml b/play.yml index ad5770b..96d5a31 100644 --- a/play.yml +++ b/play.yml @@ -3,5 +3,14 @@ hosts: localhost connection: local gather_facts: smart - roles: - - create-records + vars: + domains: + - jlay.io + - jlay.dev + - init3.io + tasks: + - name: "enforce state for {{item}}" + include_role: + name: create-records + vars_from: "{{item}}" + with_items: "{{domains}}" diff --git a/roles/create-records/defaults/main.yml b/roles/create-records/defaults/main.yml deleted file mode 100644 index 4ac70fd..0000000 --- a/roles/create-records/defaults/main.yml +++ /dev/null @@ -1,14 +0,0 @@ ---- -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 index 0e3ea24..dbb97db 100644 --- a/roles/create-records/tasks/main.yml +++ b/roles/create-records/tasks/main.yml @@ -4,5 +4,17 @@ include_vars: file: "~/.cloudflare.yml" -- include_tasks: zone.yml - loop: "{{ zones }}" +- name: "create records ({{domain}})" + cloudflare_dns: + zone: "{{ domain }}" + record: "{{ record.name }}" + value: "{{ record.value }}" + type: "{{ record.type }}" + 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') diff --git a/roles/create-records/tasks/zone.yml b/roles/create-records/tasks/zone.yml deleted file mode 100644 index a23c0eb..0000000 --- a/roles/create-records/tasks/zone.yml +++ /dev/null @@ -1,15 +0,0 @@ ---- - -- 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')