Skip to content
This repository was archived by the owner on Sep 7, 2022. It is now read-only.

Commit ff0ee60

Browse files
committed
chore: refactor into record tasks files
1 parent e69897a commit ff0ee60

12 files changed

Lines changed: 181 additions & 29 deletions

File tree

.github/workflows/release.yml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,10 @@ name: Release
44
# This release workflow requires the following environment variables:
55
# - galaxy_api_key (API key for Ansible Galaxy)
66

7-
# disable GH action for template
8-
# remove and uncommment below "on" block when using in production
97
on:
108
push:
11-
branches-ignore:
12-
- '**'
13-
14-
#on:
15-
# push:
16-
# branches:
17-
# - master
9+
branches:
10+
- master
1811

1912
jobs:
2013
release:

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ jobs:
8181
wait_for_ssh: 1
8282
env:
8383
API_TOKEN: ${{ secrets.HETZNER_TOKEN }}
84-
- uses: getstackhead/stackhead/actions/integration-test@feature/dns-support
84+
- uses: getstackhead/stackhead/actions/integration-test@next
8585
with:
8686
ipaddress: ${{ steps.setup_server.outputs.hcloud_server_created_ipv4 }}
8787
domain: '${{ env.DOMAIN_NAME }}.${{ env.DOMAIN_SUFFIX }}'

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ StackHead module for Cloudflare DNS.
44

55
## Installation
66

7+
### Ansible
8+
79
Install it via `ansible-galaxy`:
810

911
```
@@ -27,12 +29,11 @@ all:
2729
# ...
2830
```
2931

30-
3132
## Configuration
3233

33-
Make sure to provide the API token for Cloudflare via StackHead CLI configuration file.
34+
### API Token
3435

35-
You can generate an API token [in your Cloudflare profile](https://dash.cloudflare.com/profile/api-tokens).
36+
Make sure to provide the API token for Cloudflare. You can generate an API token [in your Cloudflare profile](https://dash.cloudflare.com/profile/api-tokens).
3637
Make sure to grant `write` permissions to DNS on Zone level.
3738

3839
```yaml
@@ -50,6 +51,8 @@ stackhead__config_deployment:
5051
cloudflare_api_token: MY-API-TOKEN
5152
```
5253
54+
### Domain setting
55+
5356
You'll also have to define the DNS provider to be used for each domain you want to set up in project definition:
5457
5558
```yaml

stackhead-module.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
---
2+
constraints:
3+
- stackhead>=1.3.0
24
type: dns

tasks/steps/deploy.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@
55
that:
66
- module.config.cloudflare_api_token|d("") != ""
77
- name: "Create A record for domain {{ item.domain }}"
8-
cloudflare_dns:
9-
zone: "{{ item.domain|getstackhead.stackhead.domain }}"
10-
record: "{{ item.domain|getstackhead.stackhead.subdomain|d('@', true) }}"
11-
type: A
12-
value: "{{ ansible_ssh_host }}"
13-
api_token: "{{ module.config.cloudflare_api_token }}"
14-
proxied: no
15-
solo: yes
8+
include_tasks: "{{ module_role_path | default(role_path) }}/tasks/steps/records/a.yml"
9+
vars:
10+
domain: "{{ item.domain }}"
1611
state: present
17-
when: item.dns.provider|d('') == 'cloudflare'
12+
when: item.dns.provider|d('') == 'getstackhead.stackhead_dns_cloudflare'
1813
with_items: "{{ app_config.domains }}" # item.domain

tasks/steps/destroy.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@
55
that:
66
- module.config.cloudflare_api_token|d("") != ""
77
- name: "Remove A record for domain {{ item.domain }}"
8-
cloudflare_dns:
9-
zone: "{{ item.domain|getstackhead.stackhead.domain }}"
10-
record: "{{ item.domain|getstackhead.stackhead.subdomain|d('@', true) }}"
11-
type: A
12-
value: "{{ ansible_ssh_host }}"
13-
api_token: "{{ module.config.cloudflare_api_token }}"
8+
include_tasks: "{{ module_role_path | default(role_path) }}/tasks/steps/records/a.yml"
9+
vars:
10+
domain: "{{ item.domain }}"
1411
state: absent
15-
when: item.dns.provider|d('') == 'cloudflare'
12+
when: item.dns.provider|d('') == 'getstackhead.stackhead_dns_cloudflare'
1613
with_items: "{{ app_config.domains }}" # item.domain

tasks/steps/records/a.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# required vars:
2+
# - domain
3+
# - state
4+
# optional vars:
5+
# - proxied
6+
# - solo
7+
---
8+
- cloudflare_dns:
9+
zone: "{{ domain|getstackhead.stackhead.domain }}"
10+
record: "{{ domain|getstackhead.stackhead.subdomain|d('@', true) }}"
11+
type: A
12+
value: "{{ ansible_ssh_host }}"
13+
api_token: "{{ module.config.cloudflare_api_token }}"
14+
proxied: "{{ proxied|d(false) }}"
15+
solo: "{{ solo|d(true) }}"
16+
state: present
17+
when: state == 'present'
18+
- cloudflare_dns:
19+
zone: "{{ domain|getstackhead.stackhead.domain }}"
20+
record: "{{ domain|getstackhead.stackhead.subdomain|d('@', true) }}"
21+
type: A
22+
value: "{{ ansible_ssh_host }}"
23+
api_token: "{{ module.config.cloudflare_api_token }}"
24+
proxied: "{{ proxied|d(false) }}"
25+
state: "{{ state }}"
26+
when: state != 'present'

tasks/steps/records/aaaa.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# required vars:
2+
# - domain
3+
# - state
4+
# optional vars:
5+
# - proxied
6+
# - solo
7+
---
8+
- cloudflare_dns:
9+
zone: "{{ domain|getstackhead.stackhead.domain }}"
10+
record: "{{ domain|getstackhead.stackhead.subdomain|d('@', true) }}"
11+
type: AAAA
12+
value: "{{ ansible_ssh_host }}"
13+
api_token: "{{ module.config.cloudflare_api_token }}"
14+
proxied: "{{ proxied|d(false) }}"
15+
solo: "{{ solo|d(true) }}"
16+
state: present
17+
when: state == 'present'
18+
- cloudflare_dns:
19+
zone: "{{ domain|getstackhead.stackhead.domain }}"
20+
record: "{{ domain|getstackhead.stackhead.subdomain|d('@', true) }}"
21+
type: AAAA
22+
value: "{{ ansible_ssh_host }}"
23+
api_token: "{{ module.config.cloudflare_api_token }}"
24+
proxied: "{{ proxied|d(false) }}"
25+
state: "{{ state }}"
26+
when: state != 'present'

tasks/steps/records/cname.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# required vars:
2+
# - domain
3+
# - value
4+
# - state
5+
# optional vars:
6+
# - proxied
7+
# - solo
8+
---
9+
- cloudflare_dns:
10+
zone: "{{ domain|getstackhead.stackhead.domain }}"
11+
record: "{{ domain|getstackhead.stackhead.subdomain|d('@', true) }}"
12+
type: CNAME
13+
value: "{{ value }}"
14+
api_token: "{{ module.config.cloudflare_api_token }}"
15+
proxied: "{{ proxied|d(false) }}"
16+
solo: "{{ solo|d(true) }}"
17+
state: present
18+
when: state == 'present'
19+
- cloudflare_dns:
20+
zone: "{{ domain|getstackhead.stackhead.domain }}"
21+
record: "{{ domain|getstackhead.stackhead.subdomain|d('@', true) }}"
22+
type: CNAME
23+
value: "{{ value }}"
24+
api_token: "{{ module.config.cloudflare_api_token }}"
25+
proxied: "{{ proxied|d(false) }}"
26+
state: "{{ state }}"
27+
when: state != 'present'

tasks/steps/records/mx.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# required vars:
2+
# - domain
3+
# - value
4+
# - state
5+
# optional vars:
6+
# - proxied
7+
# - solo
8+
---
9+
- cloudflare_dns:
10+
zone: "{{ domain|getstackhead.stackhead.domain }}"
11+
record: "{{ domain|getstackhead.stackhead.subdomain|d('@', true) }}"
12+
type: MX
13+
priority: 1
14+
value: "{{ value }}"
15+
api_token: "{{ module.config.cloudflare_api_token }}"
16+
proxied: "{{ proxied|d(false) }}"
17+
solo: "{{ solo|d(true) }}"
18+
state: present
19+
when: state == 'present'
20+
- cloudflare_dns:
21+
zone: "{{ domain|getstackhead.stackhead.domain }}"
22+
record: "{{ domain|getstackhead.stackhead.subdomain|d('@', true) }}"
23+
type: MX
24+
priority: 1
25+
value: "{{ value }}"
26+
api_token: "{{ module.config.cloudflare_api_token }}"
27+
proxied: "{{ proxied|d(false) }}"
28+
state: "{{ state }}"
29+
when: state != 'present'

0 commit comments

Comments
 (0)