mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-29 23:08:06 +02:00
renamed role, to make the purpose better visible
This commit is contained in:
30
roles/nginx-domain-redirect/README.md
Normal file
30
roles/nginx-domain-redirect/README.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# Nginx Redirect Role
|
||||
|
||||
This Ansible role configures Nginx to perform 301 redirects from one domain to another. It handles SSL certificate retrieval for the source domains and sets up the Nginx configuration to redirect to the specified target domains.
|
||||
|
||||
## Requirements
|
||||
|
||||
- Ansible 2.9 or higher
|
||||
- Nginx installed on the target machine
|
||||
- Let's Encrypt for SSL certificate management
|
||||
|
||||
## Role Variables
|
||||
|
||||
- `domain_mappings`: A list of objects with `source` and `target` properties specifying the domains to redirect from and to.
|
||||
- `administrator_email`: The email used for SSL certificate registration with Let's Encrypt.
|
||||
|
||||
## Dependencies
|
||||
|
||||
- `nginx-https`: A role for setting up HTTPS for Nginx
|
||||
- `letsencrypt`: A role for managing SSL certificates with Let's Encrypt
|
||||
|
||||
## Example Playbook
|
||||
|
||||
```yaml
|
||||
- hosts: servers
|
||||
roles:
|
||||
- { role: nginx-domain-redirect, domain_mappings: [ {source: 'example.com', target: 'newdomain.com'} ] }
|
||||
``````
|
||||
|
||||
## Author Information
|
||||
This role was created in 2023 by Kevin Veen Birkenbach.
|
2
roles/nginx-domain-redirect/meta/main.yml
Normal file
2
roles/nginx-domain-redirect/meta/main.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
dependencies:
|
||||
- nginx-https
|
12
roles/nginx-domain-redirect/tasks/main.yml
Normal file
12
roles/nginx-domain-redirect/tasks/main.yml
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
- name: recieve redirect source certificates
|
||||
command: certbot certonly --agree-tos --email {{administrator_email}} --non-interactive --webroot -w /var/lib/letsencrypt/ -d {{item.source}}
|
||||
loop: "{{domain_mappings}}"
|
||||
|
||||
- name: configure nginx redirect configurations
|
||||
vars:
|
||||
domain: "{{item.source}}"
|
||||
target_domain: "{{item.target}}"
|
||||
template: src=redirect.domain.nginx.conf.j2 dest=/etc/nginx/conf.d/{{ domain }}.conf
|
||||
loop: "{{domain_mappings}}"
|
||||
notify: restart nginx
|
@@ -0,0 +1,5 @@
|
||||
server {
|
||||
server_name {{domain}};
|
||||
{% include 'roles/letsencrypt/templates/ssl_header.j2' %}
|
||||
return 301 https://{{target_domain}}$request_uri;
|
||||
}
|
Reference in New Issue
Block a user