From 2f570d06b0d8a1b93d5159db6655a2d9f0dfcc01 Mon Sep 17 00:00:00 2001 From: Mathieu Gauthier-Pilote Date: Wed, 29 Mar 2023 15:58:00 -0400 Subject: [PATCH 1/4] New role to install + upgrade Mattermost --- webapps/mattermost/LISEZMOI.md | 49 ++ webapps/mattermost/README.md | 49 ++ webapps/mattermost/defaults/main.yml | 11 + webapps/mattermost/handlers/main.yml | 2 + webapps/mattermost/meta/main.yml | 52 ++ webapps/mattermost/tasks/main.yml | 104 +++ webapps/mattermost/tasks/upgrade.yml | 63 ++ webapps/mattermost/templates/config.json.j2 | 605 ++++++++++++++++++ .../templates/mattermost.service.j2 | 20 + webapps/mattermost/templates/vhost.conf.j2 | 58 ++ webapps/mattermost/tests/inventory | 2 + webapps/mattermost/tests/test.yml | 5 + webapps/mattermost/vars/main.yml | 2 + 13 files changed, 1022 insertions(+) create mode 100644 webapps/mattermost/LISEZMOI.md create mode 100644 webapps/mattermost/README.md create mode 100644 webapps/mattermost/defaults/main.yml create mode 100644 webapps/mattermost/handlers/main.yml create mode 100644 webapps/mattermost/meta/main.yml create mode 100644 webapps/mattermost/tasks/main.yml create mode 100644 webapps/mattermost/tasks/upgrade.yml create mode 100644 webapps/mattermost/templates/config.json.j2 create mode 100644 webapps/mattermost/templates/mattermost.service.j2 create mode 100644 webapps/mattermost/templates/vhost.conf.j2 create mode 100644 webapps/mattermost/tests/inventory create mode 100644 webapps/mattermost/tests/test.yml create mode 100644 webapps/mattermost/vars/main.yml diff --git a/webapps/mattermost/LISEZMOI.md b/webapps/mattermost/LISEZMOI.md new file mode 100644 index 00000000..f552f536 --- /dev/null +++ b/webapps/mattermost/LISEZMOI.md @@ -0,0 +1,49 @@ +mattermost +===== + +Ce rôle installe un serveur mattermost. + +Notez qu'hormis le présent fichier LISEZMOI.md, tous les fichiers du rôle mattermost sont rédigés en anglais afin de suivre les conventions de la communauté Ansible, favoriser sa réutilisation et son amélioration, etc. Libre à vous cependant de faire appel à ce role dans un playbook rédigé principalement en français ou toute autre langue. + +Requis +------ + +... + +Variables du rôle +----------------- + +Plusieurs des valeurs par défaut dans defaults/main.yml doivent être changées soit directement dans defaults/main.yml ou mieux encore en les supplantant ailleurs, par exemple dans votre playbook (voir l'exemple ci-bas). + +Dépendances +------------ + +Ce rôle Ansible dépend des rôles suivants : + +- nodejs + +Exemple de playbook +------------------- + +``` +- name: "Déployer un serveur mattermost" + hosts: + - all + vars: + # Supplanter ici les variables du rôle + domains: ['votre-vrai-domaine.org'] + service: 'mon-mattermost' + + roles: + - { role: webapps/mattermost , tags: "mattermost" } +``` + +Licence +------- + +GPLv3 + +Infos sur l'auteur +------------------ + +Mathieu Gauthier-Pilote, administrateur de systèmes chez Evolix. diff --git a/webapps/mattermost/README.md b/webapps/mattermost/README.md new file mode 100644 index 00000000..14fe212f --- /dev/null +++ b/webapps/mattermost/README.md @@ -0,0 +1,49 @@ +mattermost +===== + +This role installs or upgrades the server for mattermost. + +FRENCH: Voir le fichier LISEZMOI.md pour le français. + +Requirements +------------ + +... + +Role Variables +-------------- + +Several of the default values in defaults/main.yml must be changed either directly in defaults/main.yml or better even by overwriting them somewhere else, for example in your playbook (see the example below). + +Dependencies +------------ + +This Ansible role depends on the following other roles: + +- nodejs + +Example Playbook +---------------- + +``` +- name: "Deploy a mattermost server" + hosts: + - all + vars: + # Overwrite the role variables here + domains: ['your-real-domain.org'] + service: 'my-mattermost' + + roles: + - { role: webapps/mattermost , tags: "mattermost" } +``` + +License +------- + +GPLv3 + +Author Information +------------------ + +Mathieu Gauthier-Pilote, sys. admin. at Evolix. diff --git a/webapps/mattermost/defaults/main.yml b/webapps/mattermost/defaults/main.yml new file mode 100644 index 00000000..0334ce94 --- /dev/null +++ b/webapps/mattermost/defaults/main.yml @@ -0,0 +1,11 @@ +--- +# defaults file for vars +system_dep: "['git', 'nginx', 'postgresql', 'python3-psycopg2', 'certbot', 'acl']" +version: '7.8.1' +download_url: "https://releases.mattermost.com/{{ version }}/mattermost-team-{{ version }}-linux-amd64.tar.gz" +domains: ['example.domain.org'] +mm_port: '8065' +db_host: '127.0.0.1' +db_name: "{{ service }}" +db_user: "{{ service }}" +db_password: 'UQ6_CHANGE_ME_Gzb' diff --git a/webapps/mattermost/handlers/main.yml b/webapps/mattermost/handlers/main.yml new file mode 100644 index 00000000..214734cf --- /dev/null +++ b/webapps/mattermost/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file diff --git a/webapps/mattermost/meta/main.yml b/webapps/mattermost/meta/main.yml new file mode 100644 index 00000000..b065fb2a --- /dev/null +++ b/webapps/mattermost/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: Mathieu Gauthier-Pilote + description: sys. admin. + company: Evolix + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license GPL-3.0-only + + min_ansible_version: 2.10 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/webapps/mattermost/tasks/main.yml b/webapps/mattermost/tasks/main.yml new file mode 100644 index 00000000..0fcf1c67 --- /dev/null +++ b/webapps/mattermost/tasks/main.yml @@ -0,0 +1,104 @@ +--- +# tasks file for mattermost install + +- name: Install main system dependencies + apt: + name: "{{ system_dep }}" + +- name: Add UNIX account + user: + name: "{{ service }}" + shell: /bin/bash + +- name: Add PostgreSQL user + postgresql_user: + name: "{{ db_user }}" + password: "{{ db_password }}" + no_password_changes: true + become_user: postgres + +- name: Add PostgreSQL database + postgresql_db: + name: "{{ db_name }}" + owner: "{{ db_user }}" + become_user: postgres + +- name: Unarchive mattermost archive + unarchive: + src: "{{ download_url }}" + dest: ~/ + remote_src: yes + become_user: "{{ service }}" + +- name: Create the mattermost data dir if needed + file: + path: ~/mattermost/data + state: directory + mode: '0750' + become_user: "{{ service }}" + +- name: Template mattermost conf file + template: + src: "config.json.j2" + dest: "~/mattermost/config/config.json" + become_user: "{{ service }}" + +- name: Template mattermost systemd unit + template: + src: "mattermost.service.j2" + dest: "/etc/systemd/system/mattermost@.service" + +- name: Start mattermost systemd unit + service: + name: "mattermost@{{ service }}" + state: started + +#~ - name: Check if SSL certificate is present and register result + #~ stat: + #~ path: "/etc/letsencrypt/live/{{ domains |first }}/fullchain.pem" + #~ register: ssl + +#~ - name: Generate certificate only if required (first time) + #~ block: + #~ - name: Template vhost without SSL for successfull LE challengce + #~ template: + #~ src: "vhost.conf.j2" + #~ dest: "/etc/nginx/sites-available/{{ service }}.conf" + #~ - name: Enable temporary nginx vhost for mattermost + #~ file: + #~ src: "/etc/nginx/sites-available/{{ service }}.conf" + #~ dest: "/etc/nginx/sites-enabled/{{ service }}.conf" + #~ state: link + #~ - name: Reload nginx conf + #~ service: + #~ name: nginx + #~ state: reloaded + #~ - name: Make sure /var/lib/letsencrypt exists and has correct permissions + #~ file: + #~ path: /var/lib/letsencrypt + #~ state: directory + #~ mode: '0755' + #~ - name: Generate certificate with certbot + #~ shell: certbot certonly --webroot --webroot-path /var/lib/letsencrypt -d {{ domains |first }} + #~ when: ssl.stat.exists == true + +#~ - name: (Re)check if SSL certificate is present and register result + #~ stat: + #~ path: "/etc/letsencrypt/live/{{ domains |first }}/fullchain.pem" + #~ register: ssl + +- name: (Re)template conf file for nginx vhost with SSL + template: + src: "vhost.conf.j2" + dest: "/etc/nginx/sites-available/{{ service }}.conf" + +- name: Enable nginx vhost for mattermost + file: + src: "/etc/nginx/sites-available/{{ service }}.conf" + dest: "/etc/nginx/sites-enabled/{{ service }}.conf" + state: link + +- name: Reload nginx conf + service: + name: nginx + state: reloaded diff --git a/webapps/mattermost/tasks/upgrade.yml b/webapps/mattermost/tasks/upgrade.yml new file mode 100644 index 00000000..ef3c895f --- /dev/null +++ b/webapps/mattermost/tasks/upgrade.yml @@ -0,0 +1,63 @@ +--- +# tasks file for mattermost upgrade + +- name: Start mattermost systemd unit + service: + name: "mattermost@{{ service }}" + state: stopped + +- name: set current date and time as a fact + set_fact: backup_date="{{ ansible_date_time.iso8601_basic_short }}" + +- name: backup current mattermost files + command: "mv ~/mattermost/ ~/mattermost_{{ backup_date }}" + become_user: "{{ service }}" + +- name: Dump database to a file with compression + postgresql_db: + name: "{{ db_name }}" + state: dump + target: "~/{{ db_name }}.sql.gz" + become_user: postgres + +- name: Unarchive new mattermost archive + unarchive: + src: "{{ download_url }}" + dest: ~/ + remote_src: yes + become_user: "{{ service }}" + +- name: restore dirs from backup + copy: + src: "{{ item }}" + dest: ~/mattermost + remote_src: true + loop: + - "~/mattermost_{{ backup_date }}/config" + - "~/mattermost_{{ backup_date }}/data" + - "~/mattermost_{{ backup_date }}/logs" + - "~/mattermost_{{ backup_date }}/plugins" + - "~/mattermost_{{ backup_date }}/client/plugins" + become_user: "{{ service }}" + +- name: Start mattermost systemd unit + service: + name: "mattermost@{{ service }}" + state: restarted + +- name: Reload nginx conf + service: + name: nginx + state: reloaded + +- name: Define variable to skip next task by default + set_fact: + keep_db_dump: true + +- name: Remove database dump + file: + path: "~/{{ db_name }}.sql.gz" + state: absent + become_user: postgres + when: keep_db_dump is undefined + tags: clean diff --git a/webapps/mattermost/templates/config.json.j2 b/webapps/mattermost/templates/config.json.j2 new file mode 100644 index 00000000..38859b11 --- /dev/null +++ b/webapps/mattermost/templates/config.json.j2 @@ -0,0 +1,605 @@ +{ + "ServiceSettings": { + "SiteURL": "http://{{ domains | first }}", + "WebsocketURL": "", + "LicenseFileLocation": "", + "ListenAddress": "127.0.0.1:{{ mm_port }}", + "ConnectionSecurity": "", + "TLSCertFile": "", + "TLSKeyFile": "", + "TLSMinVer": "1.2", + "TLSStrictTransport": false, + "TLSStrictTransportMaxAge": 63072000, + "TLSOverwriteCiphers": [], + "UseLetsEncrypt": false, + "LetsEncryptCertificateCacheFile": "./config/letsencrypt.cache", + "Forward80To443": false, + "TrustedProxyIPHeader": [], + "ReadTimeout": 300, + "WriteTimeout": 300, + "IdleTimeout": 60, + "MaximumLoginAttempts": 10, + "GoroutineHealthThreshold": -1, + "EnableOAuthServiceProvider": true, + "EnableIncomingWebhooks": true, + "EnableOutgoingWebhooks": true, + "EnableCommands": true, + "EnablePostUsernameOverride": false, + "EnablePostIconOverride": false, + "GoogleDeveloperKey": "", + "EnableLinkPreviews": true, + "EnablePermalinkPreviews": true, + "RestrictLinkPreviews": "", + "EnableTesting": false, + "EnableDeveloper": false, + "DeveloperFlags": "", + "EnableClientPerformanceDebugging": false, + "EnableOpenTracing": false, + "EnableSecurityFixAlert": true, + "EnableInsecureOutgoingConnections": false, + "AllowedUntrustedInternalConnections": "", + "EnableMultifactorAuthentication": false, + "EnforceMultifactorAuthentication": false, + "EnableUserAccessTokens": false, + "AllowCorsFrom": "", + "CorsExposedHeaders": "", + "CorsAllowCredentials": false, + "CorsDebug": false, + "AllowCookiesForSubdomains": false, + "ExtendSessionLengthWithActivity": true, + "SessionLengthWebInDays": 30, + "SessionLengthWebInHours": 720, + "SessionLengthMobileInDays": 30, + "SessionLengthMobileInHours": 720, + "SessionLengthSSOInDays": 30, + "SessionLengthSSOInHours": 720, + "SessionCacheInMinutes": 10, + "SessionIdleTimeoutInMinutes": 43200, + "WebsocketSecurePort": 443, + "WebsocketPort": 80, + "WebserverMode": "gzip", + "EnableGifPicker": true, + "GfycatAPIKey": "2_KtH_W5", + "GfycatAPISecret": "3wLVZPiswc3DnaiaFoLkDvB4X0IV6CpMkj4tf2inJRsBY6-FnkT08zGmppWFgeof", + "EnableCustomEmoji": true, + "EnableEmojiPicker": true, + "PostEditTimeLimit": -1, + "TimeBetweenUserTypingUpdatesMilliseconds": 5000, + "EnablePostSearch": true, + "EnableFileSearch": true, + "MinimumHashtagLength": 3, + "EnableUserTypingMessages": true, + "EnableChannelViewedMessages": true, + "EnableUserStatuses": true, + "ExperimentalEnableAuthenticationTransfer": true, + "ClusterLogTimeoutMilliseconds": 2000, + "EnablePreviewFeatures": true, + "EnableTutorial": true, + "EnableOnboardingFlow": true, + "ExperimentalEnableDefaultChannelLeaveJoinMessages": true, + "ExperimentalGroupUnreadChannels": "disabled", + "EnableAPITeamDeletion": false, + "EnableAPITriggerAdminNotifications": false, + "EnableAPIUserDeletion": false, + "ExperimentalEnableHardenedMode": false, + "ExperimentalStrictCSRFEnforcement": false, + "EnableEmailInvitations": false, + "DisableBotsWhenOwnerIsDeactivated": true, + "EnableBotAccountCreation": false, + "EnableSVGs": false, + "EnableLatex": false, + "EnableInlineLatex": true, + "PostPriority": true, + "EnableAPIChannelDeletion": false, + "EnableLocalMode": false, + "LocalModeSocketLocation": "/var/tmp/mattermost_local.socket", + "EnableAWSMetering": false, + "SplitKey": "", + "FeatureFlagSyncIntervalSeconds": 30, + "DebugSplit": false, + "ThreadAutoFollow": true, + "CollapsedThreads": "always_on", + "ManagedResourcePaths": "", + "EnableCustomGroups": true, + "SelfHostedPurchase": true, + "AllowSyncedDrafts": true + }, + "TeamSettings": { + "SiteName": "Mattermost", + "MaxUsersPerTeam": 50, + "EnableUserCreation": true, + "EnableOpenServer": false, + "EnableUserDeactivation": false, + "RestrictCreationToDomains": "", + "EnableCustomUserStatuses": true, + "EnableCustomBrand": false, + "CustomBrandText": "", + "CustomDescriptionText": "", + "RestrictDirectMessage": "any", + "EnableLastActiveTime": true, + "UserStatusAwayTimeout": 300, + "MaxChannelsPerTeam": 2000, + "MaxNotificationsPerChannel": 1000, + "EnableConfirmNotificationsToChannel": true, + "TeammateNameDisplay": "username", + "ExperimentalViewArchivedChannels": true, + "ExperimentalEnableAutomaticReplies": false, + "LockTeammateNameDisplay": false, + "ExperimentalPrimaryTeam": "", + "ExperimentalDefaultChannels": [] + }, + "ClientRequirements": { + "AndroidLatestVersion": "", + "AndroidMinVersion": "", + "IosLatestVersion": "", + "IosMinVersion": "" + }, + "SqlSettings": { + "DriverName": "postgres", + "DataSource": "postgres://{{ db_user }}:{{ db_password }}@{{ db_host }}:5432/{{ db_name }}?sslmode=disable&connect_timeout=10", + "DataSourceReplicas": [], + "DataSourceSearchReplicas": [], + "MaxIdleConns": 20, + "ConnMaxLifetimeMilliseconds": 3600000, + "ConnMaxIdleTimeMilliseconds": 300000, + "MaxOpenConns": 300, + "Trace": false, + "AtRestEncryptKey": "xcipqdpb6k5hrjpfhsdixyhsscmtsujz", + "QueryTimeout": 30, + "DisableDatabaseSearch": false, + "MigrationsStatementTimeoutSeconds": 100000, + "ReplicaLagSettings": [] + }, + "LogSettings": { + "EnableConsole": true, + "ConsoleLevel": "INFO", + "ConsoleJson": true, + "EnableColor": false, + "EnableFile": true, + "FileLevel": "INFO", + "FileJson": true, + "FileLocation": "", + "EnableWebhookDebugging": true, + "EnableDiagnostics": true, + "VerboseDiagnostics": false, + "EnableSentry": true, + "AdvancedLoggingConfig": "" + }, + "ExperimentalAuditSettings": { + "FileEnabled": false, + "FileName": "", + "FileMaxSizeMB": 100, + "FileMaxAgeDays": 0, + "FileMaxBackups": 0, + "FileCompress": false, + "FileMaxQueueSize": 1000, + "AdvancedLoggingConfig": "" + }, + "NotificationLogSettings": { + "EnableConsole": true, + "ConsoleLevel": "INFO", + "ConsoleJson": true, + "EnableColor": false, + "EnableFile": true, + "FileLevel": "INFO", + "FileJson": true, + "FileLocation": "", + "AdvancedLoggingConfig": "" + }, + "PasswordSettings": { + "MinimumLength": 8, + "Lowercase": false, + "Number": false, + "Uppercase": false, + "Symbol": false + }, + "FileSettings": { + "EnableFileAttachments": true, + "EnableMobileUpload": true, + "EnableMobileDownload": true, + "MaxFileSize": 104857600, + "MaxImageResolution": 33177600, + "MaxImageDecoderConcurrency": -1, + "DriverName": "local", + "Directory": "./data/", + "EnablePublicLink": false, + "ExtractContent": true, + "ArchiveRecursion": false, + "PublicLinkSalt": "yhe99kxqhhwyitn5eo47s61u4m4rmwci", + "InitialFont": "nunito-bold.ttf", + "AmazonS3AccessKeyId": "", + "AmazonS3SecretAccessKey": "", + "AmazonS3Bucket": "", + "AmazonS3PathPrefix": "", + "AmazonS3Region": "", + "AmazonS3Endpoint": "s3.amazonaws.com", + "AmazonS3SSL": true, + "AmazonS3SignV2": false, + "AmazonS3SSE": false, + "AmazonS3Trace": false, + "AmazonS3RequestTimeoutMilliseconds": 30000 + }, + "EmailSettings": { + "EnableSignUpWithEmail": true, + "EnableSignInWithEmail": true, + "EnableSignInWithUsername": true, + "SendEmailNotifications": false, + "UseChannelInEmailNotifications": false, + "RequireEmailVerification": false, + "FeedbackName": "", + "FeedbackEmail": "", + "ReplyToAddress": "", + "FeedbackOrganization": "", + "EnableSMTPAuth": false, + "SMTPUsername": "", + "SMTPPassword": "", + "SMTPServer": "localhost", + "SMTPPort": "10025", + "SMTPServerTimeout": 10, + "ConnectionSecurity": "", + "SendPushNotifications": true, + "PushNotificationServer": "https://push-test.mattermost.com", + "PushNotificationContents": "full", + "PushNotificationBuffer": 1000, + "EnableEmailBatching": false, + "EmailBatchingBufferSize": 256, + "EmailBatchingInterval": 30, + "EnablePreviewModeBanner": true, + "SkipServerCertificateVerification": false, + "EmailNotificationContentsType": "full", + "LoginButtonColor": "#0000", + "LoginButtonBorderColor": "#2389D7", + "LoginButtonTextColor": "#2389D7", + "EnableInactivityEmail": true + }, + "RateLimitSettings": { + "Enable": false, + "PerSec": 10, + "MaxBurst": 100, + "MemoryStoreSize": 10000, + "VaryByRemoteAddr": true, + "VaryByUser": false, + "VaryByHeader": "" + }, + "PrivacySettings": { + "ShowEmailAddress": true, + "ShowFullName": true + }, + "SupportSettings": { + "TermsOfServiceLink": "https://mattermost.com/terms-of-use/", + "PrivacyPolicyLink": "https://mattermost.com/privacy-policy/", + "AboutLink": "https://docs.mattermost.com/about/product.html/", + "HelpLink": "https://mattermost.com/default-help/", + "ReportAProblemLink": "https://mattermost.com/default-report-a-problem/", + "SupportEmail": "", + "CustomTermsOfServiceEnabled": false, + "CustomTermsOfServiceReAcceptancePeriod": 365, + "EnableAskCommunityLink": true + }, + "AnnouncementSettings": { + "EnableBanner": false, + "BannerText": "", + "BannerColor": "#f2a93b", + "BannerTextColor": "#333333", + "AllowBannerDismissal": true, + "AdminNoticesEnabled": true, + "UserNoticesEnabled": true, + "NoticesURL": "https://notices.mattermost.com/", + "NoticesFetchFrequency": 3600, + "NoticesSkipCache": false + }, + "ThemeSettings": { + "EnableThemeSelection": true, + "DefaultTheme": "default", + "AllowCustomThemes": true, + "AllowedThemes": [] + }, + "GitLabSettings": { + "Enable": false, + "Secret": "", + "Id": "", + "Scope": "", + "AuthEndpoint": "", + "TokenEndpoint": "", + "UserAPIEndpoint": "", + "DiscoveryEndpoint": "", + "ButtonText": "", + "ButtonColor": "" + }, + "GoogleSettings": { + "Enable": false, + "Secret": "", + "Id": "", + "Scope": "profile email", + "AuthEndpoint": "https://accounts.google.com/o/oauth2/v2/auth", + "TokenEndpoint": "https://www.googleapis.com/oauth2/v4/token", + "UserAPIEndpoint": "https://people.googleapis.com/v1/people/me?personFields=names,emailAddresses,nicknames,metadata", + "DiscoveryEndpoint": "", + "ButtonText": "", + "ButtonColor": "" + }, + "Office365Settings": { + "Enable": false, + "Secret": "", + "Id": "", + "Scope": "User.Read", + "AuthEndpoint": "https://login.microsoftonline.com/common/oauth2/v2.0/authorize", + "TokenEndpoint": "https://login.microsoftonline.com/common/oauth2/v2.0/token", + "UserAPIEndpoint": "https://graph.microsoft.com/v1.0/me", + "DiscoveryEndpoint": "", + "DirectoryId": "" + }, + "OpenIdSettings": { + "Enable": false, + "Secret": "", + "Id": "", + "Scope": "profile openid email", + "AuthEndpoint": "", + "TokenEndpoint": "", + "UserAPIEndpoint": "", + "DiscoveryEndpoint": "", + "ButtonText": "", + "ButtonColor": "#145DBF" + }, + "LdapSettings": { + "Enable": false, + "EnableSync": false, + "LdapServer": "", + "LdapPort": 389, + "ConnectionSecurity": "", + "BaseDN": "", + "BindUsername": "", + "BindPassword": "", + "UserFilter": "", + "GroupFilter": "", + "GuestFilter": "", + "EnableAdminFilter": false, + "AdminFilter": "", + "GroupDisplayNameAttribute": "", + "GroupIdAttribute": "", + "FirstNameAttribute": "", + "LastNameAttribute": "", + "EmailAttribute": "", + "UsernameAttribute": "", + "NicknameAttribute": "", + "IdAttribute": "", + "PositionAttribute": "", + "LoginIdAttribute": "", + "PictureAttribute": "", + "SyncIntervalMinutes": 60, + "SkipCertificateVerification": false, + "PublicCertificateFile": "", + "PrivateKeyFile": "", + "QueryTimeout": 60, + "MaxPageSize": 0, + "LoginFieldName": "", + "LoginButtonColor": "#0000", + "LoginButtonBorderColor": "#2389D7", + "LoginButtonTextColor": "#2389D7", + "Trace": false + }, + "ComplianceSettings": { + "Enable": false, + "Directory": "./data/", + "EnableDaily": false, + "BatchSize": 30000 + }, + "LocalizationSettings": { + "DefaultServerLocale": "en", + "DefaultClientLocale": "en", + "AvailableLocales": "" + }, + "SamlSettings": { + "Enable": false, + "EnableSyncWithLdap": false, + "EnableSyncWithLdapIncludeAuth": false, + "IgnoreGuestsLdapSync": false, + "Verify": true, + "Encrypt": true, + "SignRequest": false, + "IdpURL": "", + "IdpDescriptorURL": "", + "IdpMetadataURL": "", + "ServiceProviderIdentifier": "", + "AssertionConsumerServiceURL": "", + "SignatureAlgorithm": "RSAwithSHA1", + "CanonicalAlgorithm": "Canonical1.0", + "ScopingIDPProviderId": "", + "ScopingIDPName": "", + "IdpCertificateFile": "", + "PublicCertificateFile": "", + "PrivateKeyFile": "", + "IdAttribute": "", + "GuestAttribute": "", + "EnableAdminAttribute": false, + "AdminAttribute": "", + "FirstNameAttribute": "", + "LastNameAttribute": "", + "EmailAttribute": "", + "UsernameAttribute": "", + "NicknameAttribute": "", + "LocaleAttribute": "", + "PositionAttribute": "", + "LoginButtonText": "SAML", + "LoginButtonColor": "#34a28b", + "LoginButtonBorderColor": "#2389D7", + "LoginButtonTextColor": "#ffffff" + }, + "NativeAppSettings": { + "AppCustomURLSchemes": [ + "mmauth://", + "mmauthbeta://" + ], + "AppDownloadLink": "https://mattermost.com/download/#mattermostApps", + "AndroidAppDownloadLink": "https://mattermost.com/mattermost-android-app/", + "IosAppDownloadLink": "https://mattermost.com/mattermost-ios-app/" + }, + "ClusterSettings": { + "Enable": false, + "ClusterName": "", + "OverrideHostname": "", + "NetworkInterface": "", + "BindAddress": "", + "AdvertiseAddress": "", + "UseIPAddress": true, + "EnableGossipCompression": true, + "EnableExperimentalGossipEncryption": false, + "ReadOnlyConfig": true, + "GossipPort": 8074, + "StreamingPort": 8075, + "MaxIdleConns": 100, + "MaxIdleConnsPerHost": 128, + "IdleConnTimeoutMilliseconds": 90000 + }, + "MetricsSettings": { + "Enable": false, + "BlockProfileRate": 0, + "ListenAddress": ":8067" + }, + "ExperimentalSettings": { + "ClientSideCertEnable": false, + "ClientSideCertCheck": "secondary", + "LinkMetadataTimeoutMilliseconds": 5000, + "RestrictSystemAdmin": false, + "UseNewSAMLLibrary": false, + "EnableSharedChannels": false, + "EnableRemoteClusterService": false, + "EnableAppBar": false, + "PatchPluginsReactDOM": false + }, + "AnalyticsSettings": { + "MaxUsersForStatistics": 2500 + }, + "ElasticsearchSettings": { + "ConnectionURL": "http://localhost:9200", + "Username": "elastic", + "Password": "changeme", + "EnableIndexing": false, + "EnableSearching": false, + "EnableAutocomplete": false, + "Sniff": true, + "PostIndexReplicas": 1, + "PostIndexShards": 1, + "ChannelIndexReplicas": 1, + "ChannelIndexShards": 1, + "UserIndexReplicas": 1, + "UserIndexShards": 1, + "AggregatePostsAfterDays": 365, + "PostsAggregatorJobStartTime": "03:00", + "IndexPrefix": "", + "LiveIndexingBatchSize": 1, + "BatchSize": 10000, + "RequestTimeoutSeconds": 30, + "SkipTLSVerification": false, + "CA": "", + "ClientCert": "", + "ClientKey": "", + "Trace": "" + }, + "BleveSettings": { + "IndexDir": "", + "EnableIndexing": false, + "EnableSearching": false, + "EnableAutocomplete": false, + "BatchSize": 10000 + }, + "DataRetentionSettings": { + "EnableMessageDeletion": false, + "EnableFileDeletion": false, + "EnableBoardsDeletion": false, + "MessageRetentionDays": 365, + "FileRetentionDays": 365, + "BoardsRetentionDays": 365, + "DeletionJobStartTime": "02:00", + "BatchSize": 3000 + }, + "MessageExportSettings": { + "EnableExport": false, + "ExportFormat": "actiance", + "DailyRunTime": "01:00", + "ExportFromTimestamp": 0, + "BatchSize": 10000, + "DownloadExportResults": false, + "GlobalRelaySettings": { + "CustomerType": "A9", + "SMTPUsername": "", + "SMTPPassword": "", + "EmailAddress": "", + "SMTPServerTimeout": 1800 + } + }, + "JobSettings": { + "RunJobs": true, + "RunScheduler": true, + "CleanupJobsThresholdDays": -1, + "CleanupConfigThresholdDays": -1 + }, + "ProductSettings": { + "EnablePublicSharedBoards": false + }, + "PluginSettings": { + "Enable": true, + "EnableUploads": false, + "AllowInsecureDownloadURL": false, + "EnableHealthCheck": true, + "Directory": "./plugins", + "ClientDirectory": "./client/plugins", + "Plugins": { + "playbooks": { + "BotUserID": "fno5xebm33bhpbb7phdxmr91xe" + } + }, + "PluginStates": { + "com.mattermost.apps": { + "Enable": true + }, + "com.mattermost.calls": { + "Enable": true + }, + "com.mattermost.nps": { + "Enable": true + }, + "focalboard": { + "Enable": true + }, + "playbooks": { + "Enable": true + } + }, + "EnableMarketplace": true, + "EnableRemoteMarketplace": true, + "AutomaticPrepackagedPlugins": true, + "RequirePluginSignature": false, + "MarketplaceURL": "https://api.integrations.mattermost.com", + "SignaturePublicKeyFiles": [], + "ChimeraOAuthProxyURL": "" + }, + "DisplaySettings": { + "CustomURLSchemes": [], + "ExperimentalTimezone": true + }, + "GuestAccountsSettings": { + "Enable": false, + "AllowEmailAccounts": true, + "EnforceMultifactorAuthentication": false, + "RestrictCreationToDomains": "" + }, + "ImageProxySettings": { + "Enable": false, + "ImageProxyType": "local", + "RemoteImageProxyURL": "", + "RemoteImageProxyOptions": "" + }, + "CloudSettings": { + "CWSURL": "https://customers.mattermost.com", + "CWSAPIURL": "https://portal.internal.prod.cloud.mattermost.com" + }, + "ImportSettings": { + "Directory": "./import", + "RetentionDays": 30 + }, + "ExportSettings": { + "Directory": "./export", + "RetentionDays": 30 + } +} diff --git a/webapps/mattermost/templates/mattermost.service.j2 b/webapps/mattermost/templates/mattermost.service.j2 new file mode 100644 index 00000000..59668476 --- /dev/null +++ b/webapps/mattermost/templates/mattermost.service.j2 @@ -0,0 +1,20 @@ +[Unit] +Description=Mattermost +After=network.target +After=postgresql.service +Requires=postgresql.service + +[Service] +Type=notify +Restart=always +WorkingDirectory=/home/%i/mattermost +ExecStart=/home/%i/mattermost/bin/mattermost +TimeoutStartSec=3600 +LimitNOFILE=49152 +RestartSec=10 +User=%i +Group=%i + +[Install] +WantedBy=multi-user.target + diff --git a/webapps/mattermost/templates/vhost.conf.j2 b/webapps/mattermost/templates/vhost.conf.j2 new file mode 100644 index 00000000..4f5525c0 --- /dev/null +++ b/webapps/mattermost/templates/vhost.conf.j2 @@ -0,0 +1,58 @@ +upstream backend_{{ service }} { + server 127.0.0.1:{{ mm_port }}; + keepalive 32; +} + +#proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=mattermost_cache:10m max_size=3g inactive=120m use_temp_path=off; + +server { + listen 80; + listen [::]:80; + #listen 443 ssl; + #listen [::]:443 ssl; + + server_name {{ domains | first }}; + + #ssl_certificate /etc/ssl/certs/mattermost.example.com.pem; + #ssl_certificate_key /etc/ssl/private/mattermost.example.com.pem; + + location ~ /api/v[0-9]+/(users/)?websocket$ { + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + client_max_body_size 50M; + 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-Forwarded-Proto $scheme; + proxy_set_header X-Frame-Options SAMEORIGIN; + proxy_buffers 256 16k; + proxy_buffer_size 16k; + client_body_timeout 60; + send_timeout 300; + lingering_timeout 5; + proxy_connect_timeout 90; + proxy_send_timeout 300; + proxy_read_timeout 90s; + proxy_pass http://backend_{{ service }}; + } + + location / { + client_max_body_size 50M; + proxy_set_header Connection ""; + 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-Forwarded-Proto $scheme; + proxy_set_header X-Frame-Options SAMEORIGIN; + proxy_buffers 256 16k; + proxy_buffer_size 16k; + proxy_read_timeout 600s; + #proxy_cache mattermost_cache; + #proxy_cache_revalidate on; + #proxy_cache_min_uses 2; + #proxy_cache_use_stale timeout; + #proxy_cache_lock on; + proxy_http_version 1.1; + proxy_pass http://backend_{{ service }}; + } +} diff --git a/webapps/mattermost/tests/inventory b/webapps/mattermost/tests/inventory new file mode 100644 index 00000000..878877b0 --- /dev/null +++ b/webapps/mattermost/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/webapps/mattermost/tests/test.yml b/webapps/mattermost/tests/test.yml new file mode 100644 index 00000000..8a42bcf3 --- /dev/null +++ b/webapps/mattermost/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - mattermost diff --git a/webapps/mattermost/vars/main.yml b/webapps/mattermost/vars/main.yml new file mode 100644 index 00000000..2053e362 --- /dev/null +++ b/webapps/mattermost/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file -- 2.39.2 From c01c90fddcc3ec6c86b0eeee423d2257768839b0 Mon Sep 17 00:00:00 2001 From: Mathieu Gauthier-Pilote Date: Thu, 27 Apr 2023 14:49:12 -0400 Subject: [PATCH 2/4] Now installs a LE SSL cert via certbot by default + configurable base path for user's home --- webapps/mattermost/defaults/main.yml | 2 + webapps/mattermost/tasks/main.yml | 80 +++++++++++-------- .../mattermost/templates/letsencrypt.conf.j2 | 5 ++ .../templates/mattermost.service.j2 | 4 +- webapps/mattermost/templates/ssl.conf.j2 | 22 +++++ webapps/mattermost/templates/vhost.conf.j2 | 31 +++++-- 6 files changed, 102 insertions(+), 42 deletions(-) create mode 100644 webapps/mattermost/templates/letsencrypt.conf.j2 create mode 100644 webapps/mattermost/templates/ssl.conf.j2 diff --git a/webapps/mattermost/defaults/main.yml b/webapps/mattermost/defaults/main.yml index 0334ce94..ceb0e33e 100644 --- a/webapps/mattermost/defaults/main.yml +++ b/webapps/mattermost/defaults/main.yml @@ -4,6 +4,8 @@ system_dep: "['git', 'nginx', 'postgresql', 'python3-psycopg2', 'certbot', 'acl' version: '7.8.1' download_url: "https://releases.mattermost.com/{{ version }}/mattermost-team-{{ version }}-linux-amd64.tar.gz" domains: ['example.domain.org'] +certbot_admin_email: 'mgauthier@evolix.ca' +home_base: '/home' mm_port: '8065' db_host: '127.0.0.1' db_name: "{{ service }}" diff --git a/webapps/mattermost/tasks/main.yml b/webapps/mattermost/tasks/main.yml index 0fcf1c67..89391443 100644 --- a/webapps/mattermost/tasks/main.yml +++ b/webapps/mattermost/tasks/main.yml @@ -4,11 +4,13 @@ - name: Install main system dependencies apt: name: "{{ system_dep }}" + update_cache: yes - name: Add UNIX account user: name: "{{ service }}" shell: /bin/bash + home: "{{ home_base }}/{{ service }}" - name: Add PostgreSQL user postgresql_user: @@ -51,41 +53,55 @@ - name: Start mattermost systemd unit service: name: "mattermost@{{ service }}" - state: started + state: restarted -#~ - name: Check if SSL certificate is present and register result - #~ stat: - #~ path: "/etc/letsencrypt/live/{{ domains |first }}/fullchain.pem" - #~ register: ssl +- name: Template nginx snippet for Let's Encrypt/Certbot + template: + src: "letsencrypt.conf.j2" + dest: "/etc/nginx/snippets/letsencrypt.conf" -#~ - name: Generate certificate only if required (first time) - #~ block: - #~ - name: Template vhost without SSL for successfull LE challengce - #~ template: - #~ src: "vhost.conf.j2" - #~ dest: "/etc/nginx/sites-available/{{ service }}.conf" - #~ - name: Enable temporary nginx vhost for mattermost - #~ file: - #~ src: "/etc/nginx/sites-available/{{ service }}.conf" - #~ dest: "/etc/nginx/sites-enabled/{{ service }}.conf" - #~ state: link - #~ - name: Reload nginx conf - #~ service: - #~ name: nginx - #~ state: reloaded - #~ - name: Make sure /var/lib/letsencrypt exists and has correct permissions - #~ file: - #~ path: /var/lib/letsencrypt - #~ state: directory - #~ mode: '0755' - #~ - name: Generate certificate with certbot - #~ shell: certbot certonly --webroot --webroot-path /var/lib/letsencrypt -d {{ domains |first }} - #~ when: ssl.stat.exists == true +- name: Check if SSL certificate is present and register result + stat: + path: "/etc/letsencrypt/live/{{ domains |first }}/fullchain.pem" + register: ssl -#~ - name: (Re)check if SSL certificate is present and register result - #~ stat: - #~ path: "/etc/letsencrypt/live/{{ domains |first }}/fullchain.pem" - #~ register: ssl +- name: Generate certificate only if required (first time) + block: + - name: Template vhost without SSL for successfull LE challengce + template: + src: "vhost.conf.j2" + dest: "/etc/nginx/sites-available/{{ service }}.conf" + - name: Enable temporary nginx vhost for mattermost + file: + src: "/etc/nginx/sites-available/{{ service }}.conf" + dest: "/etc/nginx/sites-enabled/{{ service }}.conf" + state: link + - name: Reload nginx conf + service: + name: nginx + state: reloaded + - name: Make sure /var/lib/letsencrypt exists and has correct permissions + file: + path: /var/lib/letsencrypt + state: directory + mode: '0755' + - name: Generate certificate with certbot + shell: certbot certonly --webroot --webroot-path /var/lib/letsencrypt --non-interactive --agree-tos --email {{ certbot_admin_email }} -d {{ domains |first }} + - name: Create the ssl dir if needed + file: + path: /etc/nginx/ssl + state: directory + mode: '0750' + - name: Template ssl bloc for nginx vhost + template: + src: "ssl.conf.j2" + dest: "/etc/nginx/ssl/{{ domains |first }}.conf" + when: ssl.stat.exists != true + +- name: (Re)check if SSL certificate is present and register result + stat: + path: "/etc/letsencrypt/live/{{ domains |first }}/fullchain.pem" + register: ssl - name: (Re)template conf file for nginx vhost with SSL template: diff --git a/webapps/mattermost/templates/letsencrypt.conf.j2 b/webapps/mattermost/templates/letsencrypt.conf.j2 new file mode 100644 index 00000000..6b33847e --- /dev/null +++ b/webapps/mattermost/templates/letsencrypt.conf.j2 @@ -0,0 +1,5 @@ +location ~ /.well-known/acme-challenge { + alias /var/lib/letsencrypt/; + try_files $uri =404; + allow all; +} diff --git a/webapps/mattermost/templates/mattermost.service.j2 b/webapps/mattermost/templates/mattermost.service.j2 index 59668476..5bbd7710 100644 --- a/webapps/mattermost/templates/mattermost.service.j2 +++ b/webapps/mattermost/templates/mattermost.service.j2 @@ -7,8 +7,8 @@ Requires=postgresql.service [Service] Type=notify Restart=always -WorkingDirectory=/home/%i/mattermost -ExecStart=/home/%i/mattermost/bin/mattermost +WorkingDirectory={{ home_base }}/%i/mattermost +ExecStart=/{{ home_base }}/%i/mattermost/bin/mattermost TimeoutStartSec=3600 LimitNOFILE=49152 RestartSec=10 diff --git a/webapps/mattermost/templates/ssl.conf.j2 b/webapps/mattermost/templates/ssl.conf.j2 new file mode 100644 index 00000000..86194389 --- /dev/null +++ b/webapps/mattermost/templates/ssl.conf.j2 @@ -0,0 +1,22 @@ +## +# Certificates +# you need a certificate to run in production. see https://letsencrypt.org/ +## +ssl_certificate /etc/letsencrypt/live/{{ domains | first }}/fullchain.pem; +ssl_certificate_key /etc/letsencrypt/live/{{ domains | first }}/privkey.pem; + +## +# Security hardening (as of Nov 15, 2020) +# based on Mozilla Guideline v5.6 +## + +ssl_protocols TLSv1.2 TLSv1.3; +ssl_prefer_server_ciphers on; +ssl_ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256; # add ECDHE-RSA-AES256-SHA if you want compatibility with Android 4 +ssl_session_timeout 1d; # defaults to 5m +ssl_session_cache shared:SSL:10m; # estimated to 40k sessions +ssl_session_tickets off; +ssl_stapling on; +ssl_stapling_verify on; +# HSTS (https://hstspreload.org), requires to be copied in 'location' sections that have add_header directives +#add_header Strict-Transport-Security "max-age=63072000; includeSubDomains"; diff --git a/webapps/mattermost/templates/vhost.conf.j2 b/webapps/mattermost/templates/vhost.conf.j2 index 4f5525c0..1228cd12 100644 --- a/webapps/mattermost/templates/vhost.conf.j2 +++ b/webapps/mattermost/templates/vhost.conf.j2 @@ -3,18 +3,31 @@ upstream backend_{{ service }} { keepalive 32; } -#proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=mattermost_cache:10m max_size=3g inactive=120m use_temp_path=off; - server { - listen 80; - listen [::]:80; - #listen 443 ssl; - #listen [::]:443 ssl; + listen 80; + listen [::]:80; + server_name {{ domains | first }}; + + # For certbot + include /etc/nginx/snippets/letsencrypt.conf; + + {% if ssl.stat.exists %} + location / { return 301 https://$host$request_uri; } + {% endif %} +} + +{% if ssl.stat.exists %} +server { + listen 443 ssl; + listen [::]:443 ssl; server_name {{ domains | first }}; + + access_log /var/log/nginx/{{ service }}.access.log; + error_log /var/log/nginx/{{ service }}.error.log; - #ssl_certificate /etc/ssl/certs/mattermost.example.com.pem; - #ssl_certificate_key /etc/ssl/private/mattermost.example.com.pem; + include /etc/nginx/snippets/letsencrypt.conf; + include /etc/nginx/ssl/{{ domains | first }}.conf; location ~ /api/v[0-9]+/(users/)?websocket$ { proxy_set_header Upgrade $http_upgrade; @@ -47,6 +60,7 @@ server { proxy_buffers 256 16k; proxy_buffer_size 16k; proxy_read_timeout 600s; + #proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=mattermost_cache:10m max_size=3g inactive=120m use_temp_path=off; #proxy_cache mattermost_cache; #proxy_cache_revalidate on; #proxy_cache_min_uses 2; @@ -56,3 +70,4 @@ server { proxy_pass http://backend_{{ service }}; } } +{% endif %} -- 2.39.2 From 59189e0260432f0f55134f53b3c568a59f5d78a7 Mon Sep 17 00:00:00 2001 From: Mathieu Gauthier-Pilote Date: Thu, 16 May 2024 13:54:22 -0400 Subject: [PATCH 3/4] Prefix variables with mattermost_ --- webapps/mattermost/defaults/main.yml | 22 +++++----- webapps/mattermost/tasks/main.yml | 44 +++++++++---------- webapps/mattermost/tasks/upgrade.yml | 30 ++++++------- webapps/mattermost/templates/config.json.j2 | 6 +-- .../templates/mattermost.service.j2 | 4 +- webapps/mattermost/templates/ssl.conf.j2 | 4 +- webapps/mattermost/templates/vhost.conf.j2 | 18 ++++---- 7 files changed, 64 insertions(+), 64 deletions(-) diff --git a/webapps/mattermost/defaults/main.yml b/webapps/mattermost/defaults/main.yml index ceb0e33e..d8e73968 100644 --- a/webapps/mattermost/defaults/main.yml +++ b/webapps/mattermost/defaults/main.yml @@ -1,13 +1,13 @@ --- # defaults file for vars -system_dep: "['git', 'nginx', 'postgresql', 'python3-psycopg2', 'certbot', 'acl']" -version: '7.8.1' -download_url: "https://releases.mattermost.com/{{ version }}/mattermost-team-{{ version }}-linux-amd64.tar.gz" -domains: ['example.domain.org'] -certbot_admin_email: 'mgauthier@evolix.ca' -home_base: '/home' -mm_port: '8065' -db_host: '127.0.0.1' -db_name: "{{ service }}" -db_user: "{{ service }}" -db_password: 'UQ6_CHANGE_ME_Gzb' +mattermost_system_dep: "['git', 'nginx', 'postgresql', 'python3-psycopg2', 'certbot', 'acl']" +mattermost_version: '7.8.1' +mattermost_download_url: "https://releases.mattermost.com/{{ mattermost_version }}/mattermost-team-{{ mattermost_version }}-linux-amd64.tar.gz" +mattermost_domains: ['example.domain.org'] +mattermost_certbot_admin_email: 'mgauthier@evolix.ca' +mattermost_home_base: '/home' +mattermost_app_port: '8065' +mattermost_db_host: '127.0.0.1' +mattermost_db_name: "{{ mattermost_service }}" +mattermost_db_user: "{{ mattermost_service }}" +mattermost_db_password: 'UQ6_CHANGE_ME_Gzb' diff --git a/webapps/mattermost/tasks/main.yml b/webapps/mattermost/tasks/main.yml index 89391443..ffdab041 100644 --- a/webapps/mattermost/tasks/main.yml +++ b/webapps/mattermost/tasks/main.yml @@ -3,47 +3,47 @@ - name: Install main system dependencies apt: - name: "{{ system_dep }}" + name: "{{ mattermost_system_dep }}" update_cache: yes - name: Add UNIX account user: - name: "{{ service }}" + name: "{{ mattermost_service }}" shell: /bin/bash - home: "{{ home_base }}/{{ service }}" + home: "{{ mattermost_home_base }}/{{ mattermost_service }}" - name: Add PostgreSQL user postgresql_user: - name: "{{ db_user }}" - password: "{{ db_password }}" + name: "{{ mattermost_db_user }}" + password: "{{ mattermost_db_password }}" no_password_changes: true become_user: postgres - name: Add PostgreSQL database postgresql_db: - name: "{{ db_name }}" - owner: "{{ db_user }}" + name: "{{ mattermost_db_name }}" + owner: "{{ mattermost_db_user }}" become_user: postgres - name: Unarchive mattermost archive unarchive: - src: "{{ download_url }}" + src: "{{ mattermost_download_url }}" dest: ~/ remote_src: yes - become_user: "{{ service }}" + become_user: "{{ mattermost_service }}" - name: Create the mattermost data dir if needed file: path: ~/mattermost/data state: directory mode: '0750' - become_user: "{{ service }}" + become_user: "{{ mattermost_service }}" - name: Template mattermost conf file template: src: "config.json.j2" dest: "~/mattermost/config/config.json" - become_user: "{{ service }}" + become_user: "{{ mattermost_service }}" - name: Template mattermost systemd unit template: @@ -52,7 +52,7 @@ - name: Start mattermost systemd unit service: - name: "mattermost@{{ service }}" + name: "mattermost@{{ mattermost_service }}" state: restarted - name: Template nginx snippet for Let's Encrypt/Certbot @@ -62,7 +62,7 @@ - name: Check if SSL certificate is present and register result stat: - path: "/etc/letsencrypt/live/{{ domains |first }}/fullchain.pem" + path: "/etc/letsencrypt/live/{{ mattermost_domains |first }}/fullchain.pem" register: ssl - name: Generate certificate only if required (first time) @@ -70,11 +70,11 @@ - name: Template vhost without SSL for successfull LE challengce template: src: "vhost.conf.j2" - dest: "/etc/nginx/sites-available/{{ service }}.conf" + dest: "/etc/nginx/sites-available/{{ mattermost_service }}.conf" - name: Enable temporary nginx vhost for mattermost file: - src: "/etc/nginx/sites-available/{{ service }}.conf" - dest: "/etc/nginx/sites-enabled/{{ service }}.conf" + src: "/etc/nginx/sites-available/{{ mattermost_service }}.conf" + dest: "/etc/nginx/sites-enabled/{{ mattermost_service }}.conf" state: link - name: Reload nginx conf service: @@ -86,7 +86,7 @@ state: directory mode: '0755' - name: Generate certificate with certbot - shell: certbot certonly --webroot --webroot-path /var/lib/letsencrypt --non-interactive --agree-tos --email {{ certbot_admin_email }} -d {{ domains |first }} + shell: certbot certonly --webroot --webroot-path /var/lib/letsencrypt --non-interactive --agree-tos --email {{ mattermost_certbot_admin_email }} -d {{ mattermost_domains |first }} - name: Create the ssl dir if needed file: path: /etc/nginx/ssl @@ -95,23 +95,23 @@ - name: Template ssl bloc for nginx vhost template: src: "ssl.conf.j2" - dest: "/etc/nginx/ssl/{{ domains |first }}.conf" + dest: "/etc/nginx/ssl/{{ mattermost_domains |first }}.conf" when: ssl.stat.exists != true - name: (Re)check if SSL certificate is present and register result stat: - path: "/etc/letsencrypt/live/{{ domains |first }}/fullchain.pem" + path: "/etc/letsencrypt/live/{{ mattermost_domains |first }}/fullchain.pem" register: ssl - name: (Re)template conf file for nginx vhost with SSL template: src: "vhost.conf.j2" - dest: "/etc/nginx/sites-available/{{ service }}.conf" + dest: "/etc/nginx/sites-available/{{ mattermost_service }}.conf" - name: Enable nginx vhost for mattermost file: - src: "/etc/nginx/sites-available/{{ service }}.conf" - dest: "/etc/nginx/sites-enabled/{{ service }}.conf" + src: "/etc/nginx/sites-available/{{ mattermost_service }}.conf" + dest: "/etc/nginx/sites-enabled/{{ mattermost_service }}.conf" state: link - name: Reload nginx conf diff --git a/webapps/mattermost/tasks/upgrade.yml b/webapps/mattermost/tasks/upgrade.yml index ef3c895f..52711aff 100644 --- a/webapps/mattermost/tasks/upgrade.yml +++ b/webapps/mattermost/tasks/upgrade.yml @@ -3,29 +3,29 @@ - name: Start mattermost systemd unit service: - name: "mattermost@{{ service }}" + name: "mattermost@{{ mattermost_service }}" state: stopped - name: set current date and time as a fact set_fact: backup_date="{{ ansible_date_time.iso8601_basic_short }}" - name: backup current mattermost files - command: "mv ~/mattermost/ ~/mattermost_{{ backup_date }}" - become_user: "{{ service }}" + command: "mv ~/mattermost/ ~/mattermost_{{ mattermost_backup_date }}" + become_user: "{{ mattermost_service }}" - name: Dump database to a file with compression postgresql_db: - name: "{{ db_name }}" + name: "{{ mattermost_db_name }}" state: dump - target: "~/{{ db_name }}.sql.gz" + target: "~/{{ mattermost_db_name }}.sql.gz" become_user: postgres - name: Unarchive new mattermost archive unarchive: - src: "{{ download_url }}" + src: "{{ mattermost_download_url }}" dest: ~/ remote_src: yes - become_user: "{{ service }}" + become_user: "{{ mattermost_service }}" - name: restore dirs from backup copy: @@ -33,16 +33,16 @@ dest: ~/mattermost remote_src: true loop: - - "~/mattermost_{{ backup_date }}/config" - - "~/mattermost_{{ backup_date }}/data" - - "~/mattermost_{{ backup_date }}/logs" - - "~/mattermost_{{ backup_date }}/plugins" - - "~/mattermost_{{ backup_date }}/client/plugins" - become_user: "{{ service }}" + - "~/mattermost_{{ mattermost_backup_date }}/config" + - "~/mattermost_{{ mattermost_backup_date }}/data" + - "~/mattermost_{{ mattermost_backup_date }}/logs" + - "~/mattermost_{{ mattermost_backup_date }}/plugins" + - "~/mattermost_{{ mattermost_backup_date }}/client/plugins" + become_user: "{{ mattermost_service }}" - name: Start mattermost systemd unit service: - name: "mattermost@{{ service }}" + name: "mattermost@{{ mattermost_service }}" state: restarted - name: Reload nginx conf @@ -56,7 +56,7 @@ - name: Remove database dump file: - path: "~/{{ db_name }}.sql.gz" + path: "~/{{ mattermost_db_name }}.sql.gz" state: absent become_user: postgres when: keep_db_dump is undefined diff --git a/webapps/mattermost/templates/config.json.j2 b/webapps/mattermost/templates/config.json.j2 index 38859b11..c614c3ce 100644 --- a/webapps/mattermost/templates/config.json.j2 +++ b/webapps/mattermost/templates/config.json.j2 @@ -1,9 +1,9 @@ { "ServiceSettings": { - "SiteURL": "http://{{ domains | first }}", + "SiteURL": "http://{{ mattermost_domains | first }}", "WebsocketURL": "", "LicenseFileLocation": "", - "ListenAddress": "127.0.0.1:{{ mm_port }}", + "ListenAddress": "127.0.0.1:{{ mattermost_app_port }}", "ConnectionSecurity": "", "TLSCertFile": "", "TLSKeyFile": "", @@ -136,7 +136,7 @@ }, "SqlSettings": { "DriverName": "postgres", - "DataSource": "postgres://{{ db_user }}:{{ db_password }}@{{ db_host }}:5432/{{ db_name }}?sslmode=disable&connect_timeout=10", + "DataSource": "postgres://{{ mattermost_db_user }}:{{ mattermost_db_password }}@{{ mattermost_db_host }}:5432/{{ mattermost_db_name }}?sslmode=disable&connect_timeout=10", "DataSourceReplicas": [], "DataSourceSearchReplicas": [], "MaxIdleConns": 20, diff --git a/webapps/mattermost/templates/mattermost.service.j2 b/webapps/mattermost/templates/mattermost.service.j2 index 5bbd7710..044dcf2f 100644 --- a/webapps/mattermost/templates/mattermost.service.j2 +++ b/webapps/mattermost/templates/mattermost.service.j2 @@ -7,8 +7,8 @@ Requires=postgresql.service [Service] Type=notify Restart=always -WorkingDirectory={{ home_base }}/%i/mattermost -ExecStart=/{{ home_base }}/%i/mattermost/bin/mattermost +WorkingDirectory={{ mattermost_home_base }}/%i/mattermost +ExecStart=/{{ mattermost_home_base }}/%i/mattermost/bin/mattermost TimeoutStartSec=3600 LimitNOFILE=49152 RestartSec=10 diff --git a/webapps/mattermost/templates/ssl.conf.j2 b/webapps/mattermost/templates/ssl.conf.j2 index 86194389..a1f784e5 100644 --- a/webapps/mattermost/templates/ssl.conf.j2 +++ b/webapps/mattermost/templates/ssl.conf.j2 @@ -2,8 +2,8 @@ # Certificates # you need a certificate to run in production. see https://letsencrypt.org/ ## -ssl_certificate /etc/letsencrypt/live/{{ domains | first }}/fullchain.pem; -ssl_certificate_key /etc/letsencrypt/live/{{ domains | first }}/privkey.pem; +ssl_certificate /etc/letsencrypt/live/{{ mattermost_domains | first }}/fullchain.pem; +ssl_certificate_key /etc/letsencrypt/live/{{ mattermost_domains | first }}/privkey.pem; ## # Security hardening (as of Nov 15, 2020) diff --git a/webapps/mattermost/templates/vhost.conf.j2 b/webapps/mattermost/templates/vhost.conf.j2 index 1228cd12..a76b9d89 100644 --- a/webapps/mattermost/templates/vhost.conf.j2 +++ b/webapps/mattermost/templates/vhost.conf.j2 @@ -1,12 +1,12 @@ -upstream backend_{{ service }} { - server 127.0.0.1:{{ mm_port }}; +upstream backend_{{ mattermost_service }} { + server 127.0.0.1:{{ mattermost_app_port }}; keepalive 32; } server { listen 80; listen [::]:80; - server_name {{ domains | first }}; + server_name {{ mattermost_domains | first }}; # For certbot include /etc/nginx/snippets/letsencrypt.conf; @@ -21,13 +21,13 @@ server { listen 443 ssl; listen [::]:443 ssl; - server_name {{ domains | first }}; + server_name {{ mattermost_domains | first }}; - access_log /var/log/nginx/{{ service }}.access.log; - error_log /var/log/nginx/{{ service }}.error.log; + access_log /var/log/nginx/{{ mattermost_service }}.access.log; + error_log /var/log/nginx/{{ mattermost_service }}.error.log; include /etc/nginx/snippets/letsencrypt.conf; - include /etc/nginx/ssl/{{ domains | first }}.conf; + include /etc/nginx/ssl/{{ mattermost_domains | first }}.conf; location ~ /api/v[0-9]+/(users/)?websocket$ { proxy_set_header Upgrade $http_upgrade; @@ -46,7 +46,7 @@ server { proxy_connect_timeout 90; proxy_send_timeout 300; proxy_read_timeout 90s; - proxy_pass http://backend_{{ service }}; + proxy_pass http://backend_{{ mattermost_service }}; } location / { @@ -67,7 +67,7 @@ server { #proxy_cache_use_stale timeout; #proxy_cache_lock on; proxy_http_version 1.1; - proxy_pass http://backend_{{ service }}; + proxy_pass http://backend_{{ mattermost_service }}; } } {% endif %} -- 2.39.2 From c6393508f4f01f2a52a280df9c9ad1cabe173b36 Mon Sep 17 00:00:00 2001 From: Mathieu Gauthier-Pilote Date: Thu, 16 May 2024 14:11:07 -0400 Subject: [PATCH 4/4] ansible.builtin. prefix for modules --- webapps/mattermost/tasks/main.yml | 42 ++++++++++++++-------------- webapps/mattermost/tasks/upgrade.yml | 20 ++++++------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/webapps/mattermost/tasks/main.yml b/webapps/mattermost/tasks/main.yml index ffdab041..70d67028 100644 --- a/webapps/mattermost/tasks/main.yml +++ b/webapps/mattermost/tasks/main.yml @@ -2,45 +2,45 @@ # tasks file for mattermost install - name: Install main system dependencies - apt: + ansible.builtin.apt: name: "{{ mattermost_system_dep }}" update_cache: yes - name: Add UNIX account - user: + ansible.builtin.user: name: "{{ mattermost_service }}" shell: /bin/bash home: "{{ mattermost_home_base }}/{{ mattermost_service }}" - name: Add PostgreSQL user - postgresql_user: + ansible.builtin.postgresql_user: name: "{{ mattermost_db_user }}" password: "{{ mattermost_db_password }}" no_password_changes: true become_user: postgres - name: Add PostgreSQL database - postgresql_db: + ansible.builtin.postgresql_db: name: "{{ mattermost_db_name }}" owner: "{{ mattermost_db_user }}" become_user: postgres - name: Unarchive mattermost archive - unarchive: + ansible.builtin.unarchive: src: "{{ mattermost_download_url }}" dest: ~/ remote_src: yes become_user: "{{ mattermost_service }}" - name: Create the mattermost data dir if needed - file: + ansible.builtin.file: path: ~/mattermost/data state: directory mode: '0750' become_user: "{{ mattermost_service }}" - name: Template mattermost conf file - template: + ansible.builtin.template: src: "config.json.j2" dest: "~/mattermost/config/config.json" become_user: "{{ mattermost_service }}" @@ -51,70 +51,70 @@ dest: "/etc/systemd/system/mattermost@.service" - name: Start mattermost systemd unit - service: + ansible.builtin.service: name: "mattermost@{{ mattermost_service }}" state: restarted - name: Template nginx snippet for Let's Encrypt/Certbot - template: + ansible.builtin.template: src: "letsencrypt.conf.j2" dest: "/etc/nginx/snippets/letsencrypt.conf" - name: Check if SSL certificate is present and register result - stat: + ansible.builtin.stat: path: "/etc/letsencrypt/live/{{ mattermost_domains |first }}/fullchain.pem" register: ssl - name: Generate certificate only if required (first time) block: - name: Template vhost without SSL for successfull LE challengce - template: + ansible.builtin.template: src: "vhost.conf.j2" dest: "/etc/nginx/sites-available/{{ mattermost_service }}.conf" - name: Enable temporary nginx vhost for mattermost - file: + ansible.builtin.file: src: "/etc/nginx/sites-available/{{ mattermost_service }}.conf" dest: "/etc/nginx/sites-enabled/{{ mattermost_service }}.conf" state: link - name: Reload nginx conf - service: + ansible.builtin.service: name: nginx state: reloaded - name: Make sure /var/lib/letsencrypt exists and has correct permissions - file: + ansible.builtin.file: path: /var/lib/letsencrypt state: directory mode: '0755' - name: Generate certificate with certbot - shell: certbot certonly --webroot --webroot-path /var/lib/letsencrypt --non-interactive --agree-tos --email {{ mattermost_certbot_admin_email }} -d {{ mattermost_domains |first }} + ansible.builtin.shell: certbot certonly --webroot --webroot-path /var/lib/letsencrypt --non-interactive --agree-tos --email {{ mattermost_certbot_admin_email }} -d {{ mattermost_domains |first }} - name: Create the ssl dir if needed - file: + ansible.builtin.file: path: /etc/nginx/ssl state: directory mode: '0750' - name: Template ssl bloc for nginx vhost - template: + ansible.builtin.template: src: "ssl.conf.j2" dest: "/etc/nginx/ssl/{{ mattermost_domains |first }}.conf" when: ssl.stat.exists != true - name: (Re)check if SSL certificate is present and register result - stat: + ansible.builtin.stat: path: "/etc/letsencrypt/live/{{ mattermost_domains |first }}/fullchain.pem" register: ssl - name: (Re)template conf file for nginx vhost with SSL - template: + ansible.builtin.template: src: "vhost.conf.j2" dest: "/etc/nginx/sites-available/{{ mattermost_service }}.conf" - name: Enable nginx vhost for mattermost - file: + ansible.builtin.file: src: "/etc/nginx/sites-available/{{ mattermost_service }}.conf" dest: "/etc/nginx/sites-enabled/{{ mattermost_service }}.conf" state: link - name: Reload nginx conf - service: + ansible.builtin.service: name: nginx state: reloaded diff --git a/webapps/mattermost/tasks/upgrade.yml b/webapps/mattermost/tasks/upgrade.yml index 52711aff..c2c33b0b 100644 --- a/webapps/mattermost/tasks/upgrade.yml +++ b/webapps/mattermost/tasks/upgrade.yml @@ -2,33 +2,33 @@ # tasks file for mattermost upgrade - name: Start mattermost systemd unit - service: + ansible.builtin.service: name: "mattermost@{{ mattermost_service }}" state: stopped - name: set current date and time as a fact - set_fact: backup_date="{{ ansible_date_time.iso8601_basic_short }}" + ansible.builtin.set_fact: backup_date="{{ ansible_date_time.iso8601_basic_short }}" - name: backup current mattermost files - command: "mv ~/mattermost/ ~/mattermost_{{ mattermost_backup_date }}" + ansible.builtin.command: "mv ~/mattermost/ ~/mattermost_{{ mattermost_backup_date }}" become_user: "{{ mattermost_service }}" - name: Dump database to a file with compression - postgresql_db: + ansible.builtin.postgresql_db: name: "{{ mattermost_db_name }}" state: dump target: "~/{{ mattermost_db_name }}.sql.gz" become_user: postgres - name: Unarchive new mattermost archive - unarchive: + ansible.builtin.unarchive: src: "{{ mattermost_download_url }}" dest: ~/ remote_src: yes become_user: "{{ mattermost_service }}" - name: restore dirs from backup - copy: + ansible.builtin.copy: src: "{{ item }}" dest: ~/mattermost remote_src: true @@ -41,21 +41,21 @@ become_user: "{{ mattermost_service }}" - name: Start mattermost systemd unit - service: + ansible.builtin.service: name: "mattermost@{{ mattermost_service }}" state: restarted - name: Reload nginx conf - service: + ansible.builtin.service: name: nginx state: reloaded - name: Define variable to skip next task by default - set_fact: + ansible.builtin.set_fact: keep_db_dump: true - name: Remove database dump - file: + ansible.builtin.file: path: "~/{{ mattermost_db_name }}.sql.gz" state: absent become_user: postgres -- 2.39.2