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

Commit

Permalink
chore: refactor into record tasks files
Browse files Browse the repository at this point in the history
  • Loading branch information
saitho committed Mar 11, 2021
1 parent e69897a commit ff0ee60
Show file tree
Hide file tree
Showing 12 changed files with 181 additions and 29 deletions.
11 changes: 2 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,10 @@ name: Release
# This release workflow requires the following environment variables:
# - galaxy_api_key (API key for Ansible Galaxy)

# disable GH action for template
# remove and uncommment below "on" block when using in production
on:
push:
branches-ignore:
- '**'

#on:
# push:
# branches:
# - master
branches:
- master

jobs:
release:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
wait_for_ssh: 1
env:
API_TOKEN: ${{ secrets.HETZNER_TOKEN }}
- uses: getstackhead/stackhead/actions/integration-test@feature/dns-support
- uses: getstackhead/stackhead/actions/integration-test@next
with:
ipaddress: ${{ steps.setup_server.outputs.hcloud_server_created_ipv4 }}
domain: '${{ env.DOMAIN_NAME }}.${{ env.DOMAIN_SUFFIX }}'
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ StackHead module for Cloudflare DNS.

## Installation

### Ansible

Install it via `ansible-galaxy`:

```
Expand All @@ -27,12 +29,11 @@ all:
# ...
```


## Configuration

Make sure to provide the API token for Cloudflare via StackHead CLI configuration file.
### API Token

You can generate an API token [in your Cloudflare profile](https://dash.cloudflare.com/profile/api-tokens).
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).
Make sure to grant `write` permissions to DNS on Zone level.

```yaml
Expand All @@ -50,6 +51,8 @@ stackhead__config_deployment:
cloudflare_api_token: MY-API-TOKEN
```
### Domain setting
You'll also have to define the DNS provider to be used for each domain you want to set up in project definition:
```yaml
Expand Down
2 changes: 2 additions & 0 deletions stackhead-module.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
---
constraints:
- stackhead>=1.3.0
type: dns
13 changes: 4 additions & 9 deletions tasks/steps/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@
that:
- module.config.cloudflare_api_token|d("") != ""
- name: "Create A record for domain {{ item.domain }}"
cloudflare_dns:
zone: "{{ item.domain|getstackhead.stackhead.domain }}"
record: "{{ item.domain|getstackhead.stackhead.subdomain|d('@', true) }}"
type: A
value: "{{ ansible_ssh_host }}"
api_token: "{{ module.config.cloudflare_api_token }}"
proxied: no
solo: yes
include_tasks: "{{ module_role_path | default(role_path) }}/tasks/steps/records/a.yml"
vars:
domain: "{{ item.domain }}"
state: present
when: item.dns.provider|d('') == 'cloudflare'
when: item.dns.provider|d('') == 'getstackhead.stackhead_dns_cloudflare'
with_items: "{{ app_config.domains }}" # item.domain
11 changes: 4 additions & 7 deletions tasks/steps/destroy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
that:
- module.config.cloudflare_api_token|d("") != ""
- name: "Remove A record for domain {{ item.domain }}"
cloudflare_dns:
zone: "{{ item.domain|getstackhead.stackhead.domain }}"
record: "{{ item.domain|getstackhead.stackhead.subdomain|d('@', true) }}"
type: A
value: "{{ ansible_ssh_host }}"
api_token: "{{ module.config.cloudflare_api_token }}"
include_tasks: "{{ module_role_path | default(role_path) }}/tasks/steps/records/a.yml"
vars:
domain: "{{ item.domain }}"
state: absent
when: item.dns.provider|d('') == 'cloudflare'
when: item.dns.provider|d('') == 'getstackhead.stackhead_dns_cloudflare'
with_items: "{{ app_config.domains }}" # item.domain
26 changes: 26 additions & 0 deletions tasks/steps/records/a.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# required vars:
# - domain
# - state
# optional vars:
# - proxied
# - solo
---
- cloudflare_dns:
zone: "{{ domain|getstackhead.stackhead.domain }}"
record: "{{ domain|getstackhead.stackhead.subdomain|d('@', true) }}"
type: A
value: "{{ ansible_ssh_host }}"
api_token: "{{ module.config.cloudflare_api_token }}"
proxied: "{{ proxied|d(false) }}"
solo: "{{ solo|d(true) }}"
state: present
when: state == 'present'
- cloudflare_dns:
zone: "{{ domain|getstackhead.stackhead.domain }}"
record: "{{ domain|getstackhead.stackhead.subdomain|d('@', true) }}"
type: A
value: "{{ ansible_ssh_host }}"
api_token: "{{ module.config.cloudflare_api_token }}"
proxied: "{{ proxied|d(false) }}"
state: "{{ state }}"
when: state != 'present'
26 changes: 26 additions & 0 deletions tasks/steps/records/aaaa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# required vars:
# - domain
# - state
# optional vars:
# - proxied
# - solo
---
- cloudflare_dns:
zone: "{{ domain|getstackhead.stackhead.domain }}"
record: "{{ domain|getstackhead.stackhead.subdomain|d('@', true) }}"
type: AAAA
value: "{{ ansible_ssh_host }}"
api_token: "{{ module.config.cloudflare_api_token }}"
proxied: "{{ proxied|d(false) }}"
solo: "{{ solo|d(true) }}"
state: present
when: state == 'present'
- cloudflare_dns:
zone: "{{ domain|getstackhead.stackhead.domain }}"
record: "{{ domain|getstackhead.stackhead.subdomain|d('@', true) }}"
type: AAAA
value: "{{ ansible_ssh_host }}"
api_token: "{{ module.config.cloudflare_api_token }}"
proxied: "{{ proxied|d(false) }}"
state: "{{ state }}"
when: state != 'present'
27 changes: 27 additions & 0 deletions tasks/steps/records/cname.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# required vars:
# - domain
# - value
# - state
# optional vars:
# - proxied
# - solo
---
- cloudflare_dns:
zone: "{{ domain|getstackhead.stackhead.domain }}"
record: "{{ domain|getstackhead.stackhead.subdomain|d('@', true) }}"
type: CNAME
value: "{{ value }}"
api_token: "{{ module.config.cloudflare_api_token }}"
proxied: "{{ proxied|d(false) }}"
solo: "{{ solo|d(true) }}"
state: present
when: state == 'present'
- cloudflare_dns:
zone: "{{ domain|getstackhead.stackhead.domain }}"
record: "{{ domain|getstackhead.stackhead.subdomain|d('@', true) }}"
type: CNAME
value: "{{ value }}"
api_token: "{{ module.config.cloudflare_api_token }}"
proxied: "{{ proxied|d(false) }}"
state: "{{ state }}"
when: state != 'present'
29 changes: 29 additions & 0 deletions tasks/steps/records/mx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# required vars:
# - domain
# - value
# - state
# optional vars:
# - proxied
# - solo
---
- cloudflare_dns:
zone: "{{ domain|getstackhead.stackhead.domain }}"
record: "{{ domain|getstackhead.stackhead.subdomain|d('@', true) }}"
type: MX
priority: 1
value: "{{ value }}"
api_token: "{{ module.config.cloudflare_api_token }}"
proxied: "{{ proxied|d(false) }}"
solo: "{{ solo|d(true) }}"
state: present
when: state == 'present'
- cloudflare_dns:
zone: "{{ domain|getstackhead.stackhead.domain }}"
record: "{{ domain|getstackhead.stackhead.subdomain|d('@', true) }}"
type: MX
priority: 1
value: "{{ value }}"
api_token: "{{ module.config.cloudflare_api_token }}"
proxied: "{{ proxied|d(false) }}"
state: "{{ state }}"
when: state != 'present'
27 changes: 27 additions & 0 deletions tasks/steps/records/spf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# required vars:
# - domain
# - value
# - state
# optional vars:
# - proxied
# - solo
---
- cloudflare_dns:
zone: "{{ domain|getstackhead.stackhead.domain }}"
record: "{{ domain|getstackhead.stackhead.subdomain|d('@', true) }}"
type: SPF
value: "{{ value }}"
api_token: "{{ module.config.cloudflare_api_token }}"
proxied: "{{ proxied|d(false) }}"
solo: "{{ solo|d(true) }}"
state: present
when: state == 'present'
- cloudflare_dns:
zone: "{{ domain|getstackhead.stackhead.domain }}"
record: "{{ domain|getstackhead.stackhead.subdomain|d('@', true) }}"
type: SPF
value: "{{ value }}"
api_token: "{{ module.config.cloudflare_api_token }}"
proxied: "{{ proxied|d(false) }}"
state: "{{ state }}"
when: state != 'present'
27 changes: 27 additions & 0 deletions tasks/steps/records/txt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# required vars:
# - domain
# - value
# - state
# optional vars:
# - proxied
# - solo
---
- cloudflare_dns:
zone: "{{ domain|getstackhead.stackhead.domain }}"
record: "{{ domain|getstackhead.stackhead.subdomain|d('@', true) }}"
type: TXT
value: "{{ value }}"
api_token: "{{ module.config.cloudflare_api_token }}"
proxied: "{{ proxied|d(false) }}"
solo: "{{ solo|d(true) }}"
state: present
when: state == 'present'
- cloudflare_dns:
zone: "{{ domain|getstackhead.stackhead.domain }}"
record: "{{ domain|getstackhead.stackhead.subdomain|d('@', true) }}"
type: TXT
value: "{{ value }}"
api_token: "{{ module.config.cloudflare_api_token }}"
proxied: "{{ proxied|d(false) }}"
state: "{{ state }}"
when: state != 'present'

0 comments on commit ff0ee60

Please sign in to comment.