From f23d71aa6a10f86e60f1be5b1be413db1a81e9fb Mon Sep 17 00:00:00 2001 From: Markus Hauschild Date: Wed, 8 Jan 2020 12:03:28 +0100 Subject: [PATCH] new host: strontium (Rocket.Chat) --- group_vars/all/vars.yml | 2 + host_vars/strontium.binary-kitchen.net | 4 ++ hosts | 1 + roles/rocketchat/handlers/main.yml | 7 +++ roles/rocketchat/meta/main.yml | 5 +++ roles/rocketchat/tasks/main.yml | 60 ++++++++++++++++++++++++++ roles/rocketchat/templates/certs.j2 | 15 +++++++ roles/rocketchat/templates/vhost.j2 | 43 ++++++++++++++++++ site.yml | 7 ++- 9 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 host_vars/strontium.binary-kitchen.net create mode 100644 roles/rocketchat/handlers/main.yml create mode 100644 roles/rocketchat/meta/main.yml create mode 100644 roles/rocketchat/tasks/main.yml create mode 100644 roles/rocketchat/templates/certs.j2 create mode 100644 roles/rocketchat/templates/vhost.j2 diff --git a/group_vars/all/vars.yml b/group_vars/all/vars.yml index a6647ab..79f94a6 100644 --- a/group_vars/all/vars.yml +++ b/group_vars/all/vars.yml @@ -85,6 +85,8 @@ prosody_domain: jabber.binary-kitchen.de radius_secret: "{{ vault_radius_secret }}" +rocketchat_domain: chat.binary-kitchen.de + root_keys: - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJBmZnJLG1WRppbLtOAJw3E4LgLRK0NirfCgpovhhU6h moepman" - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINPlktM2x11cNBMKurf57MLE1XcOm2sGQXguc0tl1vYd kishi" diff --git a/host_vars/strontium.binary-kitchen.net b/host_vars/strontium.binary-kitchen.net new file mode 100644 index 0000000..76db882 --- /dev/null +++ b/host_vars/strontium.binary-kitchen.net @@ -0,0 +1,4 @@ +--- + +root_keys_host: +- "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINkN1eqP1Mv29z0npVznVJ4Cumyf4EoqS44xHKl0ms0e timo@charon" diff --git a/hosts b/hosts index 96359dd..e2c4f85 100644 --- a/hosts +++ b/hosts @@ -20,3 +20,4 @@ oxygen.binary-kitchen.net fluorine.binary-kitchen.net neon.binary-kitchen.net krypton.binary-kitchen.net +strontium.binary-kitchen.net diff --git a/roles/rocketchat/handlers/main.yml b/roles/rocketchat/handlers/main.yml new file mode 100644 index 0000000..45972c5 --- /dev/null +++ b/roles/rocketchat/handlers/main.yml @@ -0,0 +1,7 @@ +--- + +- name: Run acertmgr + command: /opt/acertmgr/acertmgr.py + +- name: Restart nginx + service: name=nginx state=restarted diff --git a/roles/rocketchat/meta/main.yml b/roles/rocketchat/meta/main.yml new file mode 100644 index 0000000..8fcf724 --- /dev/null +++ b/roles/rocketchat/meta/main.yml @@ -0,0 +1,5 @@ +--- + +dependencies: +- { role: acertmgr } +- { role: nginx, nginx_ssl: True } diff --git a/roles/rocketchat/tasks/main.yml b/roles/rocketchat/tasks/main.yml new file mode 100644 index 0000000..281ea94 --- /dev/null +++ b/roles/rocketchat/tasks/main.yml @@ -0,0 +1,60 @@ +--- + +- name: Create user + user: name=rocketchat + +- name: Enable https for apt + apt: name=apt-transport-https + +- name: Enable mongodb apt-key + apt_key: url="https://www.mongodb.org/static/pgp/server-4.0.asc" + +- name: Enable mongodb repository + apt_repository: repo="deb http://repo.mongodb.org/apt/debian stretch/mongodb-org/4.0 main" + +# mongodb needs libcurl3 which is no longer available in buster +- name: Enable stretch repository + apt_repository: repo="deb http://deb.debian.org/debian/ stretch main" + +- name: Enable nodesource apt-key + apt_key: url="https://deb.nodesource.com/gpgkey/nodesource.gpg.key" + +- name: Enable nodesource repository + apt_repository: repo="deb https://deb.nodesource.com/node_8.x/ {{ ansible_distribution_release }} main" + +- name: Pin nodejs repository + blockinfile: + path: /etc/apt/preferences.d/nodejs + create: yes + block: | + Package: * + Pin: origin deb.nodesource.com + Pin-Priority: 600 + +- name: Install packages + apt: name={{ item }} + with_items: + - build-essential + - dirmngr + - graphicsmagick + - libcurl3 + - mongodb-org + - nodejs + +# rocket.chat itself is not setup here - it is done manually + +- name: Ensure certificates are available + command: openssl req -x509 -nodes -newkey rsa:2048 -keyout /etc/nginx/ssl/{{ rocketchat_domain }}.key -out /etc/nginx/ssl/{{ rocketchat_domain }}.crt -days 730 -subj "/CN={{ rocketchat_domain }}" creates=/etc/nginx/ssl/{{ rocketchat_domain }}.crt + notify: Restart nginx + +- name: Configure certificate manager for rocketchat + template: src=certs.j2 dest=/etc/acertmgr/{{ rocketchat_domain }}.conf + notify: Run acertmgr + +- name: Configure vhost + template: src=vhost.j2 dest=/etc/nginx/sites-available/rocketchat + notify: Restart nginx + +- name: Enable vhost + file: src=/etc/nginx/sites-available/rocketchat dest=/etc/nginx/sites-enabled/rocketchat state=link + notify: Restart nginx diff --git a/roles/rocketchat/templates/certs.j2 b/roles/rocketchat/templates/certs.j2 new file mode 100644 index 0000000..afe1f74 --- /dev/null +++ b/roles/rocketchat/templates/certs.j2 @@ -0,0 +1,15 @@ +--- + +{{ rocketchat_domain }}: +- path: /etc/nginx/ssl/{{ rocketchat_domain }}.key + user: root + group: root + perm: '400' + format: key + action: '/usr/sbin/service nginx restart' +- path: /etc/nginx/ssl/{{ rocketchat_domain }}.crt + user: root + group: root + perm: '400' + format: crt,ca + action: '/usr/sbin/service nginx restart' diff --git a/roles/rocketchat/templates/vhost.j2 b/roles/rocketchat/templates/vhost.j2 new file mode 100644 index 0000000..7fb7b89 --- /dev/null +++ b/roles/rocketchat/templates/vhost.j2 @@ -0,0 +1,43 @@ +server { + listen 80; + listen [::]:80; + + server_name {{ rocketchat_domain }}; + + location /.well-known/acme-challenge { + default_type "text/plain"; + alias /var/www/acme-challenge; + } + + location / { + return 301 https://{{ rocketchat_domain }}$request_uri; + } +} + +server { + listen 443 ssl http2; + listen [::]:443 ssl http2; + + server_name {{ rocketchat_domain }}; + + ssl_certificate_key /etc/nginx/ssl/{{ rocketchat_domain }}.key; + ssl_certificate /etc/nginx/ssl/{{ rocketchat_domain }}.crt; + + location / { + client_max_body_size 128M; + + proxy_pass http://localhost:3000; + proxy_http_version 1.1; + + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $http_host; + + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forward-Proto http; + proxy_set_header X-Nginx-Proxy true; + + proxy_redirect off; + } +} diff --git a/site.yml b/site.yml index 4006b83..fbe491d 100644 --- a/site.yml +++ b/site.yml @@ -8,7 +8,7 @@ - root-keys - name: Setup unattended updates - hosts: [sulis.binary.kitchen, nabia.binary.kitchen, beryllium.binary-kitchen.net, boron.binary-kitchen.net, carbon.binary-kitchen.net, nitrogen.binary-kitchen.net, oxygen.binary-kitchen.net, fluorine.binary-kitchen.net, krypton.binary-kitchen.net] + hosts: [sulis.binary.kitchen, nabia.binary.kitchen, beryllium.binary-kitchen.net, boron.binary-kitchen.net, carbon.binary-kitchen.net, nitrogen.binary-kitchen.net, oxygen.binary-kitchen.net, fluorine.binary-kitchen.net, krypton.binary-kitchen.net, strontium.binary-kitchen.net] roles: - uau @@ -82,3 +82,8 @@ hosts: krypton.binary-kitchen.net roles: - partdb + +- name: Setup rocketchat server + hosts: strontium.binary-kitchen.net + roles: + - rocketchat