From 39e5ad9e20cd281ee97495152686d7dcb7204325 Mon Sep 17 00:00:00 2001 From: Markus Hauschild Date: Thu, 24 Dec 2020 12:38:42 +0100 Subject: [PATCH] web_mc: webserver for minecraft map --- group_vars/all/vars.yml | 2 ++ roles/web_mc/handlers/main.yml | 7 +++++++ roles/web_mc/meta/main.yml | 5 +++++ roles/web_mc/tasks/main.yml | 20 ++++++++++++++++++++ roles/web_mc/templates/certs.j2 | 15 +++++++++++++++ roles/web_mc/templates/vhost.j2 | 27 +++++++++++++++++++++++++++ site.yml | 5 +++++ 7 files changed, 81 insertions(+) create mode 100644 roles/web_mc/handlers/main.yml create mode 100644 roles/web_mc/meta/main.yml create mode 100644 roles/web_mc/tasks/main.yml create mode 100644 roles/web_mc/templates/certs.j2 create mode 100644 roles/web_mc/templates/vhost.j2 diff --git a/group_vars/all/vars.yml b/group_vars/all/vars.yml index abe53f5..eb41d5a 100644 --- a/group_vars/all/vars.yml +++ b/group_vars/all/vars.yml @@ -100,6 +100,8 @@ matrix_dbname: matrix matrix_dbuser: matrix matrix_dbpass: "{{ vault_matrix_dbpass }}" +mc_domain: minecraft.binary-kitchen.de + nextcloud_domain: oc.binary-kitchen.de nextcloud_dbname: owncloud nextcloud_dbuser: owncloud diff --git a/roles/web_mc/handlers/main.yml b/roles/web_mc/handlers/main.yml new file mode 100644 index 0000000..ff936dd --- /dev/null +++ b/roles/web_mc/handlers/main.yml @@ -0,0 +1,7 @@ +--- + +- name: Restart nginx + service: name=nginx state=restarted + +- name: Run acertmgr + command: /usr/bin/acertmgr diff --git a/roles/web_mc/meta/main.yml b/roles/web_mc/meta/main.yml new file mode 100644 index 0000000..8fcf724 --- /dev/null +++ b/roles/web_mc/meta/main.yml @@ -0,0 +1,5 @@ +--- + +dependencies: +- { role: acertmgr } +- { role: nginx, nginx_ssl: True } diff --git a/roles/web_mc/tasks/main.yml b/roles/web_mc/tasks/main.yml new file mode 100644 index 0000000..3dc43d5 --- /dev/null +++ b/roles/web_mc/tasks/main.yml @@ -0,0 +1,20 @@ +--- + +- name: Create vhost directory + file: path=/var/www/mc state=directory owner=www-data group=www-data + +- name: Ensure certificates are available + command: openssl req -x509 -nodes -newkey rsa:2048 -keyout /etc/nginx/ssl/{{ mc_domain }}.key -out /etc/nginx/ssl/{{ mc_domain }}.crt -days 730 -subj "/CN={{ mc_domain }}" creates=/etc/nginx/ssl/{{ mc_domain }}.crt + notify: Restart nginx + +- name: Configure certificate manager + template: src=certs.j2 dest=/etc/acertmgr/{{ mc_domain }}.conf + notify: Run acertmgr + +- name: Configure vhosts + template: src=vhost.j2 dest=/etc/nginx/sites-available/mc + notify: Restart nginx + +- name: Enable vhosts + file: src=/etc/nginx/sites-available/mc dest=/etc/nginx/sites-enabled/mc state=link + notify: Restart nginx diff --git a/roles/web_mc/templates/certs.j2 b/roles/web_mc/templates/certs.j2 new file mode 100644 index 0000000..5f47fbf --- /dev/null +++ b/roles/web_mc/templates/certs.j2 @@ -0,0 +1,15 @@ +--- + +{{ mc_domain }}: +- path: /etc/nginx/ssl/{{ mc_domain }}.key + user: root + group: root + perm: '400' + format: key + action: '/usr/sbin/service nginx restart' +- path: /etc/nginx/ssl/{{ mc_domain }}.crt + user: root + group: root + perm: '400' + format: crt,ca + action: '/usr/sbin/service nginx restart' diff --git a/roles/web_mc/templates/vhost.j2 b/roles/web_mc/templates/vhost.j2 new file mode 100644 index 0000000..7c89cf0 --- /dev/null +++ b/roles/web_mc/templates/vhost.j2 @@ -0,0 +1,27 @@ +server { + listen 80; + listen [::]:80; + + server_name {{ mc_domain }}; + + location /.well-known/acme-challenge { + default_type "text/plain"; + alias /var/www/acme-challenge; + } + + location / { + return 301 https://{{ mc_domain }}$request_uri; + } +} + +server { + listen 443 ssl http2; + listen [::]:443 ssl http2; + + server_name {{ plk_domain }}; + + ssl_certificate_key /etc/nginx/ssl/{{ mc_domain }}.key; + ssl_certificate /etc/nginx/ssl/{{ mc_domain }}.crt; + + root /var/www/mc; +} diff --git a/site.yml b/site.yml index 1b93b55..9041ae3 100644 --- a/site.yml +++ b/site.yml @@ -104,3 +104,8 @@ hosts: technetium.binary-kitchen.net roles: - web_plk + +- name: Setup minecraft server + hosts: ruthenium.binary-kitchen.net + roles: + - web_mc