From 62c102625472a9c1d59adc026d46e6f723fbb132 Mon Sep 17 00:00:00 2001 From: phil Date: Fri, 22 Dec 2023 08:46:29 +0100 Subject: [PATCH] Cleanup role --- files/nolog4j0day.options | 1 - files/plain-text.patch | 10 ------ files/senselab.css | 8 ----- handlers/main.yml | 5 --- tasks/cron.yml | 16 --------- tasks/customizations.yml | 8 ----- tasks/gateway.yml | 29 ---------------- tasks/main.yml | 6 ---- tasks/user.yml | 2 +- tasks/webserver.yml | 3 -- tasks/zammad.yml | 18 ---------- templates/database.yml.j2 | 32 ----------------- templates/nginx-rp-site.j2 | 27 --------------- templates/zammad-delete-customers.rb.j2 | 27 --------------- templates/zammad-updater.j2 | 46 ------------------------- 15 files changed, 1 insertion(+), 237 deletions(-) delete mode 100644 files/nolog4j0day.options delete mode 100644 files/plain-text.patch delete mode 100644 files/senselab.css delete mode 100644 tasks/cron.yml delete mode 100644 tasks/customizations.yml delete mode 100644 tasks/gateway.yml delete mode 100644 templates/nginx-rp-site.j2 delete mode 100644 templates/zammad-delete-customers.rb.j2 delete mode 100644 templates/zammad-updater.j2 diff --git a/files/nolog4j0day.options b/files/nolog4j0day.options deleted file mode 100644 index 5af9281..0000000 --- a/files/nolog4j0day.options +++ /dev/null @@ -1 +0,0 @@ --Dlog4j2.formatMsgNoLookups=true diff --git a/files/plain-text.patch b/files/plain-text.patch deleted file mode 100644 index c821a8e..0000000 --- a/files/plain-text.patch +++ /dev/null @@ -1,10 +0,0 @@ ---- app/models/channel/email_build.rb.orig 2021-07-27 18:03:57.295467567 +0200 -+++ app/models/channel/email_build.rb 2021-07-27 18:04:20.705471697 +0200 -@@ -62,6 +62,7 @@ - - # generate plain part - attr[:body] = attr[:body].html2text -+ html_alternative = false - end - - # add plain text part diff --git a/files/senselab.css b/files/senselab.css deleted file mode 100644 index 28b8724..0000000 --- a/files/senselab.css +++ /dev/null @@ -1,8 +0,0 @@ -form.article-add.is-internal .article-content > .internal-border::after { - content: 'Du schreibst eine interne Notiz. Es wird keine ausgehende Mail an Gesprächsteilnehmer:innen versendet!'; - padding-top: 6px; - display: block; - font-weight: bold; - font-size: 1.2em; - text-align: center; -} diff --git a/handlers/main.yml b/handlers/main.yml index 1cf9682..6c3195e 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,9 +1,4 @@ --- -- name: reload monit - ansible.builtin.service: - name: monit - state: reloaded - - name: reload nginx ansible.builtin.service: name: nginx diff --git a/tasks/cron.yml b/tasks/cron.yml deleted file mode 100644 index 8b662e8..0000000 --- a/tasks/cron.yml +++ /dev/null @@ -1,16 +0,0 @@ ---- -- name: "cron | Setze Umgebungsvariablen" - ansible.builtin.cron: - user: "{{ zammad_user }}" - name: RAILS_ENV - job: production - env: true - -- name: "cron | Richte cron ein" - ansible.builtin.cron: - user: "{{ zammad_user }}" - name: "Loesche unbenutzte Zammad-Kunden" - minute: "1" - hour: "1" - day: "1" - job: " cd {{ zammad_home }} && chronic rbenv exec rails r {{ local_scripts_dir }}/zammad-delete-customers.rb" diff --git a/tasks/customizations.yml b/tasks/customizations.yml deleted file mode 100644 index a030d77..0000000 --- a/tasks/customizations.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -- name: "customizations | Kopiere custom css" - ansible.builtin.copy: - src: senselab.css - dest: "{{ zammad_home }}/app/assets/stylesheets/custom/senselab.css" - owner: "{{ zammad_user }}" - group: "{{ zammad_user }}" - mode: "0644" diff --git a/tasks/gateway.yml b/tasks/gateway.yml deleted file mode 100644 index e2c18ff..0000000 --- a/tasks/gateway.yml +++ /dev/null @@ -1,29 +0,0 @@ ---- -- name: "gateway: Domain zur Zertifikatsliste hinzufügen" - lineinfile: - path: /etc/dehydrated/domains.txt - insertafter: "^### systemausfall" - line: "{{ zammad_domain }}" - when: "'dehydrated' in ansible_facts.packages" - register: add_certificate - delegate_to: "{{ gateway_host }}" - -- name: "gateway: Zertifikat erstellen" - command: dehydrated --cron -g - when: add_certificate.changed - delegate_to: "{{ gateway_host }}" - -- name: "gateway: Proxy einrichten" - template: - src: nginx-rp-site.j2 - dest: "/etc/nginx/sites-available/{{ zammad_domain }}" - force: no - delegate_to: "{{ gateway_host }}" - -- name: "gateway: Seite aktivieren" - file: - src: "/etc/nginx/sites-available/{{ zammad_domain }}" - dest: "/etc/nginx/sites-enabled/{{ zammad_domain }}" - state: link - notify: reload reverse_proxy - delegate_to: "{{ gateway_host }}" diff --git a/tasks/main.yml b/tasks/main.yml index f1803da..90562b4 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -10,12 +10,6 @@ - import_tasks: zammad.yml tags: zammad -- import_tasks: customizations.yml - tags: customizations - -- import_tasks: cron.yml - tags: cron - - import_tasks: ruby.yml tags: ruby diff --git a/tasks/user.yml b/tasks/user.yml index 3691855..06f2f14 100644 --- a/tasks/user.yml +++ b/tasks/user.yml @@ -10,4 +10,4 @@ home: "{{ zammad_user_home }}" shell: /bin/bash password_lock: true - system: yes + system: true diff --git a/tasks/webserver.yml b/tasks/webserver.yml index 5e35c87..2e4c5c6 100644 --- a/tasks/webserver.yml +++ b/tasks/webserver.yml @@ -10,6 +10,3 @@ dest: "/etc/nginx/sites-enabled/{{ zammad_domain }}" state: link notify: reload nginx - - - diff --git a/tasks/zammad.yml b/tasks/zammad.yml index 0e555ff..be2e46f 100644 --- a/tasks/zammad.yml +++ b/tasks/zammad.yml @@ -19,30 +19,12 @@ owner: "{{ zammad_user }}" group: "{{ zammad_user }}" -# https://github.com/zammad/zammad/issues/325 -- name: "zammad | Wende plain-Text-Patch an" - ansible.posix.patch: - src: plain-text.patch - dest: "{{ zammad_home }}/app/models/channel/email_build.rb" - - name: "zammad | Ermittle Ruby-Version" ansible.builtin.command: cat "{{ zammad_home }}/.ruby-version" register: ruby_version changed_when: false check_mode: false -- name: "zammad | Kopiere Skripte" - ansible.builtin.template: - src: zammad-delete-customers.rb.j2 - dest: "{{ local_scripts_dir }}/zammad-delete-customers.rb" - mode: "0644" - -- name: "zammad | Kopiere Updater" - ansible.builtin.template: - src: zammad-updater.j2 - dest: "{{ local_scripts_dir }}/zammad-updater" - mode: "0755" - - name: "zammad | Erstelle Alias" ansible.builtin.lineinfile: path: /root/.bashrc diff --git a/templates/database.yml.j2 b/templates/database.yml.j2 index 7363e47..af90efe 100644 --- a/templates/database.yml.j2 +++ b/templates/database.yml.j2 @@ -1,44 +1,12 @@ -# this is a database config sample for zammad ready to use with a postgresql db -# copy or symlink this file to config/database.yml to use it - default: &default - # For details on connection pooling, see Rails configuration guide - # http://guides.rubyonrails.org/configuring.html#database-pooling pool: 50 timeout: 5000 encoding: utf8 - - ##### postgresql config ##### - adapter: postgresql username: {{ zammad_database_user }} password: {{ zammad_database_password }} - - # If the database server is not on localhost, you can set hostname and port: host: {{ database_host }} - # port: - - #### mysql config ##### - - # adapter: mysql2 - # username: zammad - # password: - - # If the database server is not on localhost, you can set hostname and port: - # host: - # port: production: <<: *default database: {{ zammad_database_name }} - -development: - <<: *default - database: zammad_development - -# Warning: The database defined as "test" will be erased and -# re-generated from your development database when you run "rake". -# Do not set this db to the same as development or production. -test: - <<: *default - database: zammad_test diff --git a/templates/nginx-rp-site.j2 b/templates/nginx-rp-site.j2 deleted file mode 100644 index aa4e0be..0000000 --- a/templates/nginx-rp-site.j2 +++ /dev/null @@ -1,27 +0,0 @@ -server { - listen 80; - server_name {{ zammad_domain }}; - include snippets/letsencrypt.conf; - location / { return 301 https://$http_host$request_uri; } -} - -server { - listen 443 ssl http2; - server_name {{ zammad_domain }}; - ssl_certificate /var/lib/dehydrated/certs/{{ zammad_domain }}/fullchain.pem; - ssl_certificate_key /var/lib/dehydrated/certs/{{ zammad_domain }}/privkey.pem; - include /etc/nginx/snippets/add_headers.conf; - location /cable { - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "Upgrade"; - proxy_pass http://{{ inventory_hostname }}:80; - } - location /ws { - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "Upgrade"; - proxy_pass http://{{ inventory_hostname }}:80; - } - location / { - proxy_pass http://{{ inventory_hostname }}:80; - } -} diff --git a/templates/zammad-delete-customers.rb.j2 b/templates/zammad-delete-customers.rb.j2 deleted file mode 100644 index bb2515e..0000000 --- a/templates/zammad-delete-customers.rb.j2 +++ /dev/null @@ -1,27 +0,0 @@ -# https://github.com/JBails/PurgeZammad -# This script will delete all users that do not have an assigned ticket (open or closed), with no regards as to how long they haven't had a ticket -# i.e. doesn't care if the last ticket was deleted 30 seconds or 30 days ago - -ticketless_customers = User.with_permissions('ticket.customer'){% if zammad_preserve_customer_domains is defined %}{% for domain in zammad_preserve_customer_domains %}.where('email NOT LIKE ?', '%{{ domain }}%'){% endfor %}{% endif %}.where('id NOT IN (SELECT customer_id FROM tickets)') -count = ticketless_customers.count - -puts "#{count} customers without tickets found." -puts - -ticketless_customers.find_each.with_index do |user, i| - next if user.permissions?(%w[admin ticket.agent]) - next if user.id == 1 - - display_name = user.fullname + (user.fullname == user.email ? '' : " (#{user.email})") - - User.transaction do - begin - user.destroy! - puts " #{display_name} deleted." - rescue => e - puts " #{display_name} could not be deleted: #{e.message}" - raise ActiveRecord::Rollback - next - end - end -end diff --git a/templates/zammad-updater.j2 b/templates/zammad-updater.j2 deleted file mode 100644 index bec8b49..0000000 --- a/templates/zammad-updater.j2 +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash -# {{ ansible_managed }} - -set -eu - -RUBY_VERSION=$(cat {{ zammad_home }}/.ruby-version) -RUBY_INSTALLED_VERSIONS=$(rbenv version | grep $RUBY_VERSION | cut -d ' ' -f2) - -echo "Wechsle Verzeichnis..." -cd {{ zammad_home }} - -echo "Leere Rails Cache..." -sudo -u {{ zammad_user }} RAILS_ENV=production rbenv exec rails r "Cache.clear" - -echo "Aktualisiere Git-Repository..." -git pull - -if [ -n "$RUBY_INSTALLED_VERSIONS" ]; then - echo "Aktualisiere Ruby-Version..." - sudo -u {{ zammad_user }} rbenv install "$RUBY_VERSION" -fi - -echo "Aktualisiere bundler..." -sudo -u {{ zammad_user }} RAILS_ENV=production rbenv exec gem install bundler - -echo "Aktualisiere Ruby-Pakete..." -sudo -u {{ zammad_user }} RAILS_ENV=production rbenv exec bundle install --without test development mysql - -echo "Stoppe Zammad..." -systemctl stop {{ zammad_service }} - -echo "Migriere Datenbank..." -sudo -u {{ zammad_user }} RAILS_ENV=production rbenv exec bundle exec rake db:migrate - -echo "Assets vorkompilieren..." -sudo -u {{ zammad_user }} RAILS_ENV=production rbenv exec bundle exec rake assets:precompile - -echo "Synchronisiere Translation-Dateien..." -sudo -u {{ zammad_user }} RAILS_ENV=production rbenv exec rails r "Locale.sync" -sudo -u {{ zammad_user }} RAILS_ENV=production rbenv exec rails r "Translation.sync" - -echo "Starte Zammad..." -systemctl start {{ zammad_service }} -sleep 20 - -echo "Alles erledigt."