Implemented redirect function for domains

This commit is contained in:
Kevin Veen-Birkenbach 2021-10-20 10:22:03 +02:00
parent d45da7497f
commit 90fa9f830f
5 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,2 @@
dependencies:
- native-https-server

View File

@ -0,0 +1,5 @@
# native https-redirect
## see
- https://stackoverflow.com/questions/6045020/how-to-redirect-to-a-different-domain-using-nginx
- https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html

View 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

View File

@ -0,0 +1,5 @@
server {
server_name {{domain}};
{% include 'roles/native-letsencrypt/templates/ssl_header.j2' %}
return 301 https://{{target_domain}}$request_uri;
}

View File

@ -60,6 +60,13 @@
vars:
domains: "{{wordpress_domains}}"
http_port: 8003
- name: setup redirect hosts
hosts: redirect_hosts
become: true
roles:
- role: native-https-redirect
vars:
domain_mappings: "{{redirect_domain_mappings}}"
- name: setup mediawiki hosts
hosts: mediawiki_hosts
become: true