Refactor web-opt-rdr-www:

- Split Cloudflare edge redirect into _01 and _02 task files
- Wrap Cloudflare routines in a conditional block on DNS_PROVIDER
- Preserve origin vs edge flavor handling
Conversation: https://chatgpt.com/share/68c3609b-5624-800f-b5fa-69def6032dca
This commit is contained in:
2025-09-12 01:52:13 +02:00
parent 206b3eadbc
commit a0c2245bbd
3 changed files with 32 additions and 31 deletions

View File

@@ -0,0 +1,7 @@
- name: Include Cloudflare redirect rule to enforce www → apex
include_tasks: _02_cloudflare_redirect_rule.yml
vars:
domain: "{{ item | regex_replace('^www\\.', '') }}"
www_fqdn: "{{ item }}"
apex_url: "{{ WEB_PROTOCOL }}://{{ item | regex_replace('^www\\.', '') }}"
loop: "{{ REDIRECT_WWW_DOMAINS }}"

View File

@@ -13,7 +13,10 @@
redirect_domain_mappings: "{{ REDIRECT_WWW_DOMAINS | map('regex_replace', '^www\\.(.+)$', '{ source: \"www.\\1\", target: \"\\1\" }') | map('from_yaml') | list }}" redirect_domain_mappings: "{{ REDIRECT_WWW_DOMAINS | map('regex_replace', '^www\\.(.+)$', '{ source: \"www.\\1\", target: \"\\1\" }') | map('from_yaml') | list }}"
when: REDIRECT_WWW_FLAVOR == 'origin' when: REDIRECT_WWW_FLAVOR == 'origin'
- name: Include DNS role to set redirects - name: Cloudflare WWW Routines
when: DNS_PROVIDER == 'cloudflare'
block:
- name: Include DNS role to set redirects
include_role: include_role:
name: sys-dns-cloudflare-records name: sys-dns-cloudflare-records
vars: vars:
@@ -31,17 +34,8 @@
}{{ "," if not loop.last else "" }} }{{ "," if not loop.last else "" }}
{%- endfor -%} {%- endfor -%}
] ]
when: when: REDIRECT_WWW_FLAVOR == 'origin'
- DNS_PROVIDER == 'cloudflare'
- REDIRECT_WWW_FLAVOR == 'origin'
- name: Include Cloudflare redirect rule to enforce www → apex - name: Include Cloudflare edge redirect
include_tasks: cloudflare_redirect_rule.yml include_tasks: _01_cloudflare_edge_redirect.yml
vars:
domain: "{{ item | regex_replace('^www\\.', '') }}"
www_fqdn: "{{ item }}"
apex_url: "{{ WEB_PROTOCOL }}://{{ item | regex_replace('^www\\.', '') }}"
loop: "{{ REDIRECT_WWW_DOMAINS }}"
when: REDIRECT_WWW_FLAVOR == 'edge' when: REDIRECT_WWW_FLAVOR == 'edge'