mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-29 15:06:26 +02:00
Restructured service und web role naming in inventor
This commit is contained in:
24
roles/web-svc-redir-www/README.md
Normal file
24
roles/web-svc-redir-www/README.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# Nginx WWW Redirect 🌐
|
||||
|
||||
## Description
|
||||
Automates the creation of Nginx server blocks that redirect all `www.` subdomains to their non-www equivalents. Simple, idempotent, and SEO-friendly! 🚀
|
||||
|
||||
## Overview
|
||||
This role will:
|
||||
- **Discover** existing `*.conf` vhosts in your Nginx servers directory
|
||||
- **Filter** domains with or without your `primary_domain`
|
||||
- **Generate** redirect rules via the `web-svc-redir-domains` role
|
||||
- **Optionally** include a wildcard redirect template (experimental) ⭐️
|
||||
- **Clean up** leftover configs when running in cleanup mode 🧹
|
||||
|
||||
All tasks are guarded by “run once” facts and `mode_cleanup` flags to avoid unintended re-runs or stale files.
|
||||
|
||||
## Purpose
|
||||
Ensure that any request to `www.example.com` automatically and permanently redirects to `https://example.com`, improving user experience, SEO, and certificate management. 🎯
|
||||
|
||||
## Features
|
||||
- **Auto-Discovery**: Scans your Nginx `servers` directory for `.conf` files. 🔍
|
||||
- **Dynamic Redirects**: Builds `source: "www.domain"` → `target: "domain"` mappings on the fly. 🔧
|
||||
- **Wildcard Redirect**: Includes a templated wildcard server block for `www.*` domains (toggleable). ✨
|
||||
- **Cleanup Mode**: Removes the wildcard config file when `certbot_flavor` is set to `dedicated` and `mode_cleanup` is enabled. 🗑️
|
||||
- **Debug Output**: Optional `enable_debug` gives detailed variable dumps for troubleshooting. 🐛
|
26
roles/web-svc-redir-www/meta/main.yml
Normal file
26
roles/web-svc-redir-www/meta/main.yml
Normal file
@@ -0,0 +1,26 @@
|
||||
---
|
||||
galaxy_info:
|
||||
author: "Kevin Veen-Birkenbach"
|
||||
description: "An Ansible role to redirect www subdomains to non-www domains in Nginx"
|
||||
license: "CyMaIS NonCommercial License (CNCL)"
|
||||
license_url: "https://s.veen.world/cncl"
|
||||
company: |
|
||||
Kevin Veen-Birkenbach
|
||||
Consulting & Coaching Solutions
|
||||
https://www.veen.world
|
||||
min_ansible_version: "2.9"
|
||||
platforms:
|
||||
- name: Archlinux
|
||||
versions:
|
||||
- rolling
|
||||
galaxy_tags:
|
||||
- nginx
|
||||
- redirect
|
||||
- www
|
||||
- wildcard
|
||||
- seo
|
||||
repository: "https://s.veen.world/cymais"
|
||||
issue_tracker_url: "https://s.veen.world/cymaisissues"
|
||||
documentation: "https://s.veen.world/cymais"
|
||||
dependencies:
|
||||
- srv-web-7-4-core
|
26
roles/web-svc-redir-www/tasks/main.yml
Normal file
26
roles/web-svc-redir-www/tasks/main.yml
Normal file
@@ -0,0 +1,26 @@
|
||||
---
|
||||
- name: Filter www-prefixed domains from current_play_domains_all
|
||||
set_fact:
|
||||
www_domains: "{{ current_play_domains_all | select('match', '^www\\.') | list }}"
|
||||
|
||||
- name: Include web-svc-redir-domains role for www-to-bare redirects
|
||||
include_role:
|
||||
name: web-svc-redir-domains
|
||||
vars:
|
||||
domain_mappings: "{{ www_domains
|
||||
| map('regex_replace',
|
||||
'^www\\.(.+)$',
|
||||
'{ source: \"www.\\1\", target: \"\\1\" }')
|
||||
| map('from_yaml')
|
||||
| list
|
||||
}}"
|
||||
|
||||
- name: Include DNS role to set redirects
|
||||
include_role:
|
||||
name: net-dns-records
|
||||
vars:
|
||||
cloudflare_api_token: "{{ certbot_dns_api_token }}"
|
||||
cloudflare_domains: "{{ www_domains }}"
|
||||
cloudflare_target_ip: "{{ networks.internet.ip4 }}"
|
||||
cloudflare_proxied: false
|
||||
when: dns_provider == 'cloudflare'
|
1
roles/web-svc-redir-www/vars/main.yml
Normal file
1
roles/web-svc-redir-www/vars/main.yml
Normal file
@@ -0,0 +1 @@
|
||||
application_id: "redir-www"
|
Reference in New Issue
Block a user