From fcc145082a788ffcdc1f14169fb2bd2088bd74e7 Mon Sep 17 00:00:00 2001 From: Christoph Haas Date: Sun, 1 Dec 2019 17:22:38 +0100 Subject: [PATCH] Roles packages, certificate and roundcube fixed --- ansible/group_vars/all | 6 +- ansible/hosts | 3 +- ansible/ispmail.yml | 31 +++--- ansible/roles/ispmail-certificate/tasks/main.yml | 1 - ansible/roles/ispmail-database/tasks/main.yml | 48 ++++----- .../templates/dovecot-sql.conf.ext.j2 | 2 +- ansible/roles/ispmail-packages/tasks/main.yml | 42 ++++---- .../templates/mysql-email2email.cf.j2 | 2 +- .../templates/mysql-virtual-alias-maps.cf.j2 | 2 +- .../templates/mysql-virtual-mailbox-domains.cf.j2 | 2 +- .../templates/mysql-virtual-mailbox-maps.cf.j2 | 2 +- .../files/roundcube-managesieve-config.inc.php | 101 ------------------- .../handlers/main.yml | 5 + .../tasks/main.yml | 108 ++++++++++++++------- .../templates/config.inc.php.j2 | 90 +++++++++++++++++ .../plugins/managesieve/config.inc.php.j2 | 1 + .../templates/plugins/password/config.inc.php.j2 | 13 +++ .../templates/roundcube-password-config.inc.php.j2 | 2 +- .../templates/vhosts/http.j2 | 8 ++ .../templates/vhosts/https.j2 | 12 +++ 20 files changed, 277 insertions(+), 204 deletions(-) delete mode 100644 ansible/roles/ispmail-webmail-apache-roundcube/files/roundcube-managesieve-config.inc.php create mode 100644 ansible/roles/ispmail-webmail-apache-roundcube/handlers/main.yml create mode 100644 ansible/roles/ispmail-webmail-apache-roundcube/templates/config.inc.php.j2 create mode 100644 ansible/roles/ispmail-webmail-apache-roundcube/templates/plugins/managesieve/config.inc.php.j2 create mode 100644 ansible/roles/ispmail-webmail-apache-roundcube/templates/plugins/password/config.inc.php.j2 create mode 100644 ansible/roles/ispmail-webmail-apache-roundcube/templates/vhosts/http.j2 create mode 100644 ansible/roles/ispmail-webmail-apache-roundcube/templates/vhosts/https.j2 diff --git a/ansible/group_vars/all b/ansible/group_vars/all index 9100a67..100851c 100644 --- a/ansible/group_vars/all +++ b/ansible/group_vars/all @@ -2,8 +2,12 @@ # Set this to true to create a john@example.org account with password 'summersun' ispmail_populate_test_data: true +# Set the host name that will be used in the URL for webmail. +# Make sure its properly set in your DNS zone. +ispmail_fqdn: yoda.workaround.org + # MySQL password for read-only user -ispmail_mysql_mailuser_password: ChangeMe +ispmail_mysql_mailserver_password: ChangeMe # MySQL password for administrative root user ispmail_mysql_root_password: ChangeMeRoot diff --git a/ansible/hosts b/ansible/hosts index 05614f6..e932d40 100644 --- a/ansible/hosts +++ b/ansible/hosts @@ -1 +1,2 @@ -localhost ansible_connection=local \ No newline at end of file +localhost ansible_connection=local +yoda.workaround.org diff --git a/ansible/ispmail.yml b/ansible/ispmail.yml index aa961eb..88a3c17 100644 --- a/ansible/ispmail.yml +++ b/ansible/ispmail.yml @@ -4,20 +4,23 @@ - hosts: all tasks: - - name: "Checking operating system version" - assert: - that: ansible_distribution_release == 'buster' - fail_msg: 'This Ansible playbook is only supported on Debian Buster.' - success_msg: 'Debian Buster found - that makes me happy.' + - name: "Checking operating system version" + assert: + that: ansible_distribution_release == 'buster' + fail_msg: "This Ansible playbook is only supported on Debian Buster." + success_msg: "Debian Buster found - that makes me happy." - hosts: all roles: - #- dumpvars - - ispmail-packages -# - ispmail-certificate - - ispmail-database -# - ispmail-postfix -# - ispmail-dovecot -# - ispmail-webmail - - ispmail-webmail-apache-horde - - ispmail-tests + #- dumpvars + - role: ispmail-packages + tags: packages + - role: ispmail-certificate + tags: certificate + # - ispmail-database + # - ispmail-postfix + # - ispmail-dovecot + - role: ispmail-webmail-apache-roundcube + tags: roundcube + # - ispmail-webmail-apache-horde + #- ispmail-tests diff --git a/ansible/roles/ispmail-certificate/tasks/main.yml b/ansible/roles/ispmail-certificate/tasks/main.yml index 0ee1fb6..10dc8c5 100644 --- a/ansible/roles/ispmail-certificate/tasks/main.yml +++ b/ansible/roles/ispmail-certificate/tasks/main.yml @@ -12,4 +12,3 @@ creates: /etc/ssl/certs/mailserver.pem - name: Restrict access permissions of the private key file: path=/etc/ssl/private/mailserver.pem mode=0640 - diff --git a/ansible/roles/ispmail-database/tasks/main.yml b/ansible/roles/ispmail-database/tasks/main.yml index 626a231..8c81e02 100644 --- a/ansible/roles/ispmail-database/tasks/main.yml +++ b/ansible/roles/ispmail-database/tasks/main.yml @@ -1,8 +1,16 @@ --- - name: Installing required Python mysqldb module for Ansible to manage databases -# apt: name=python-mysqldb + # apt: name=python-mysqldb apt: name=python-pymysql +- name: Create .my.cnf + template: + src: "root-my-cnf.j2" + dest: "/root/.my.cnf" + owner: root + group: root + mode: 0600 + - name: Set a new root password mysql_user: check_implicit_admin: yes @@ -14,49 +22,41 @@ - localhost - 127.0.0.1 -- name: Create .my.cnf - template: - src: "root-my-cnf.j2" - dest: "/root/.my.cnf" - owner: root - group: root - mode: 0600 - - name: creating mailserver MySQL database #become: true mysql_db: name: mailserver # - name: creating Roundcube MySQL database -# mysql_db: +# mysql_db: # name: roundcube - name: copying MySQL database schema to server - copy: - src: schema.sql + copy: + src: schema.sql dest: /tmp - name: setting up SQL schema of mailserver database - mysql_db: - name: mailserver - state: import + mysql_db: + name: mailserver + state: import target: /tmp/schema.sql - name: creating MySQL user to read the mailserver database - mysql_user: - name: mailuser - password: "{{ispmail_mysql_mailuser_password}}" + mysql_user: + name: mailuser + password: "{{ispmail_mysql_mailserver_password}}" priv: mailserver.*:SELECT,INSERT,UPDATE,DELETE # - name: creating MySQL user for roundcube -# mysql_user: -# name: roundcube +# mysql_user: +# name: roundcube # password: "{{ispmail_mysql_roundcube_password}}" # priv: roundcube.*:ALL - name: copying MySQL test data to server - copy: + copy: src: test.sql dest: /tmp when: ispmail_populate_test_data == true - name: populating the database with test data - mysql_db: - name: mailserver - state: import + mysql_db: + name: mailserver + state: import target: /tmp/test.sql when: ispmail_populate_test_data == true diff --git a/ansible/roles/ispmail-dovecot/templates/dovecot-sql.conf.ext.j2 b/ansible/roles/ispmail-dovecot/templates/dovecot-sql.conf.ext.j2 index 9d044b7..568975a 100644 --- a/ansible/roles/ispmail-dovecot/templates/dovecot-sql.conf.ext.j2 +++ b/ansible/roles/ispmail-dovecot/templates/dovecot-sql.conf.ext.j2 @@ -141,7 +141,7 @@ #iterate_query = SELECT username AS user FROM users driver = mysql -connect = host=127.0.0.1 dbname=mailserver user=mailuser password={{ispmail_mysql_mailuser_password}} +connect = host=127.0.0.1 dbname=mailserver user=mailuser password={{ispmail_mysql_mailserver_password}} default_pass_scheme = SHA256-CRYPT password_query = SELECT email as user, password FROM virtual_users WHERE email='%u'; diff --git a/ansible/roles/ispmail-packages/tasks/main.yml b/ansible/roles/ispmail-packages/tasks/main.yml index fcf29ad..13b5803 100644 --- a/ansible/roles/ispmail-packages/tasks/main.yml +++ b/ansible/roles/ispmail-packages/tasks/main.yml @@ -5,23 +5,27 @@ update_cache: yes vars: packages: - - etckeeper - - certbot - - pwgen - - mariadb-server - - postfix - - postfix-mysql - # - roundcube - # - roundcube-mysql - # - roundcube-plugins - # - roundcube-plugins-extra - - swaks - - dovecot-mysql - - dovecot-pop3d - - dovecot-imapd - - dovecot-lmtpd - - dovecot-managesieved - - adminer - - rspamd - - fail2ban + - etckeeper + - certbot + - pwgen + - mariadb-server + - postfix + - postfix-mysql + # - roundcube + # - roundcube-mysql + # - roundcube-plugins + # - roundcube-plugins-extra + - swaks + - dovecot-mysql + - dovecot-pop3d + - dovecot-imapd + - dovecot-lmtpd + - dovecot-managesieved + - apache2 + - php + - adminer + - rspamd + - fail2ban + - ca-certificates + - mutt # TODO: shorewall diff --git a/ansible/roles/ispmail-postfix/templates/mysql-email2email.cf.j2 b/ansible/roles/ispmail-postfix/templates/mysql-email2email.cf.j2 index 0d6ea98..cdf6cee 100644 --- a/ansible/roles/ispmail-postfix/templates/mysql-email2email.cf.j2 +++ b/ansible/roles/ispmail-postfix/templates/mysql-email2email.cf.j2 @@ -1,5 +1,5 @@ user = mailuser -password = {{ispmail_mysql_mailuser_password}} +password = {{ispmail_mysql_mailserver_password}} hosts = 127.0.0.1 dbname = mailserver query = SELECT email FROM virtual_users WHERE email='%s' diff --git a/ansible/roles/ispmail-postfix/templates/mysql-virtual-alias-maps.cf.j2 b/ansible/roles/ispmail-postfix/templates/mysql-virtual-alias-maps.cf.j2 index ba49b2f..9aad48d 100644 --- a/ansible/roles/ispmail-postfix/templates/mysql-virtual-alias-maps.cf.j2 +++ b/ansible/roles/ispmail-postfix/templates/mysql-virtual-alias-maps.cf.j2 @@ -1,5 +1,5 @@ user = mailuser -password = {{ispmail_mysql_mailuser_password}} +password = {{ispmail_mysql_mailserver_password}} hosts = 127.0.0.1 dbname = mailserver query = SELECT destination FROM virtual_aliases WHERE source='%s' diff --git a/ansible/roles/ispmail-postfix/templates/mysql-virtual-mailbox-domains.cf.j2 b/ansible/roles/ispmail-postfix/templates/mysql-virtual-mailbox-domains.cf.j2 index 443f77c..bca5edb 100644 --- a/ansible/roles/ispmail-postfix/templates/mysql-virtual-mailbox-domains.cf.j2 +++ b/ansible/roles/ispmail-postfix/templates/mysql-virtual-mailbox-domains.cf.j2 @@ -1,5 +1,5 @@ user = mailuser -password = {{ispmail_mysql_mailuser_password}} +password = {{ispmail_mysql_mailserver_password}} hosts = 127.0.0.1 dbname = mailserver query = SELECT 1 FROM virtual_domains WHERE name='%s' diff --git a/ansible/roles/ispmail-postfix/templates/mysql-virtual-mailbox-maps.cf.j2 b/ansible/roles/ispmail-postfix/templates/mysql-virtual-mailbox-maps.cf.j2 index 0207bbb..46ced80 100644 --- a/ansible/roles/ispmail-postfix/templates/mysql-virtual-mailbox-maps.cf.j2 +++ b/ansible/roles/ispmail-postfix/templates/mysql-virtual-mailbox-maps.cf.j2 @@ -1,5 +1,5 @@ user = mailuser -password = {{ispmail_mysql_mailuser_password}} +password = {{ispmail_mysql_mailserver_password}} hosts = 127.0.0.1 dbname = mailserver query = SELECT 1 FROM virtual_users WHERE email='%s' diff --git a/ansible/roles/ispmail-webmail-apache-roundcube/files/roundcube-managesieve-config.inc.php b/ansible/roles/ispmail-webmail-apache-roundcube/files/roundcube-managesieve-config.inc.php deleted file mode 100644 index cc53cb0..0000000 --- a/ansible/roles/ispmail-webmail-apache-roundcube/files/roundcube-managesieve-config.inc.php +++ /dev/null @@ -1,101 +0,0 @@ -// Taken from /usr/share/roundcube/plugins/managesieve/config.inc.php.dist - array( -// 'verify_peer' => true, -// 'verify_depth' => 3, -// 'cafile' => '/etc/openssl/certs/ca.crt', -// ), -// ); -$config['managesieve_conn_options'] = null; - -// default contents of filters script (eg. default spam filter) -$config['managesieve_default'] = '/etc/dovecot/sieve/global'; - -// The name of the script which will be used when there's no user script -$config['managesieve_script_name'] = 'managesieve'; - -// Sieve RFC says that we should use UTF-8 endcoding for mailbox names, -// but some implementations does not covert UTF-8 to modified UTF-7. -// Defaults to UTF7-IMAP -$config['managesieve_mbox_encoding'] = 'UTF-8'; - -// I need this because my dovecot (with listescape plugin) uses -// ':' delimiter, but creates folders with dot delimiter -$config['managesieve_replace_delimiter'] = ''; - -// disabled sieve extensions (body, copy, date, editheader, encoded-character, -// envelope, environment, ereject, fileinto, ihave, imap4flags, index, -// mailbox, mboxmetadata, regex, reject, relational, servermetadata, -// spamtest, spamtestplus, subaddress, vacation, variables, virustest, etc. -// Note: not all extensions are implemented -$config['managesieve_disabled_extensions'] = array(); - -// Enables debugging of conversation with sieve server. Logs it into /sieve -$config['managesieve_debug'] = false; - -// Enables features described in http://wiki.kolab.org/KEP:14 -$config['managesieve_kolab_master'] = false; - -// Script name extension used for scripts including. Dovecot uses '.sieve', -// Cyrus uses '.siv'. Doesn't matter if you have managesieve_kolab_master disabled. -$config['managesieve_filename_extension'] = '.sieve'; - -// List of reserved script names (without extension). -// Scripts listed here will be not presented to the user. -$config['managesieve_filename_exceptions'] = array(); - -// List of domains limiting destination emails in redirect action -// If not empty, user will need to select domain from a list -$config['managesieve_domains'] = array(); - -// Enables separate management interface for vacation responses (out-of-office) -// 0 - no separate section (default), -// 1 - add Vacation section, -// 2 - add Vacation section, but hide Filters section -$config['managesieve_vacation'] = 0; - -// Default vacation interval (in days). -// Note: If server supports vacation-seconds extension it is possible -// to define interval in seconds here (as a string), e.g. "3600s". -$config['managesieve_vacation_interval'] = 0; - -// Some servers require vacation :addresses to be filled with all -// user addresses (aliases). This option enables automatic filling -// of these on initial vacation form creation. -$config['managesieve_vacation_addresses_init'] = false; - -// Supported methods of notify extension. Default: 'mailto' -$config['managesieve_notify_methods'] = array('mailto'); diff --git a/ansible/roles/ispmail-webmail-apache-roundcube/handlers/main.yml b/ansible/roles/ispmail-webmail-apache-roundcube/handlers/main.yml new file mode 100644 index 0000000..af398e8 --- /dev/null +++ b/ansible/roles/ispmail-webmail-apache-roundcube/handlers/main.yml @@ -0,0 +1,5 @@ +--- +- name: restart apache + service: + name: apache2 + state: restarted diff --git a/ansible/roles/ispmail-webmail-apache-roundcube/tasks/main.yml b/ansible/roles/ispmail-webmail-apache-roundcube/tasks/main.yml index 3019f6a..eff658e 100644 --- a/ansible/roles/ispmail-webmail-apache-roundcube/tasks/main.yml +++ b/ansible/roles/ispmail-webmail-apache-roundcube/tasks/main.yml @@ -5,40 +5,74 @@ update_cache: yes vars: packages: - #- roundcube - #- roundcube-plugins - - php-horde-imp - - php-horde-ingo - - php-horde-kronolith - - php-horde-turba -# - name: Creating random des_key for Roundcube -# shell: pwgen 24 -# register: roundcube_random_des_key -# - name: Deploying Roundcube configuration -# template: -# src: roundcube-config.inc.php.j2 -# dest: /etc/roundcube/config.inc.php -# owner: root -# group: www-data -# mode: 0640 -# - name: Deploying Roundcube managesieve plugin configuration -# copy: -# src: roundcube-managesieve-config.inc.php -# dest: /etc/roundcube/plugins/managesieve/config.inc.php -# mode: 0640 -# - name: Deploying Roundcube password plugin configuration -# template: -# src: roundcube-password-config.inc.php.j2 -# dest: /etc/roundcube/plugins/password/config.inc.php -# owner: root -# group: www-data -# mode: 0640 -# - name: Copy ISPmail logo -# copy: -# src: ispmail-logo.png -# dest: /var/lib/roundcube/ -# - name: Copy Roundcube database config file -# template: -# src: roundcube-debian-db.php.j2 -# dest: /etc/roundcube/debian-db.php -# mode: 0640 + - roundcube + - roundcube-plugins + - roundcube-plugins-extra + - roundcube-mysql +- name: Creating random des_key for Roundcube + shell: pwgen 24 1 + register: roundcube_random_des_key +- name: Deploying Roundcube configuration + template: + src: config.inc.php.j2 + dest: /etc/roundcube/config.inc.php + owner: root + group: www-data + mode: 0640 +- name: Deploying Roundcube managesieve plugin configuration + template: + src: plugins/managesieve/config.inc.php.j2 + dest: /etc/roundcube/plugins/managesieve/config.inc.php + owner: root + group: www-data + mode: 0640 +- name: Deploying Roundcube password plugin configuration + template: + src: plugins/password/config.inc.php.j2 + dest: /etc/roundcube/plugins/password/config.inc.php + owner: root + group: www-data + mode: 0640 +- name: Copy ISPmail logo + copy: + src: ispmail-logo.png + dest: /var/lib/roundcube/skins/larry/ +- name: Enable Apache rewrite and ssl module + shell: a2enmod {{item}} + args: + creates: /etc/apache2/mods-enabled/{{item}}.load + with_items: + - rewrite + - ssl + notify: restart apache +- name: Create DocumentRoot for HTTP vhost + file: + path: /var/www/{{ispmail_fqdn}} + state: directory + owner: www-data + group: www-data +- name: Remove Apache default vhost pointing to dummy page + file: + path: /etc/apache2/sites-enabled/000-default.conf + state: absent + notify: restart apache +- name: Configure HTTP vhost + template: + src: vhosts/http.j2 + dest: /etc/apache2/sites-available/{{ispmail_fqdn}}-http.conf + notify: restart apache +- name: Enable HTTP vhost + shell: a2ensite {{ispmail_fqdn}}-http.conf + args: + creates: /etc/apache2/sites-enabled/{{ispmail_fqdn}}-http.conf + notify: restart apache +- name: Configure HTTPS vhost + template: + src: vhosts/https.j2 + dest: /etc/apache2/sites-available/{{ispmail_fqdn}}-https.conf + notify: restart apache +- name: Enable HTTPS vhost + shell: a2ensite {{ispmail_fqdn}}-https.conf + args: + creates: /etc/apache2/sites-enabled/{{ispmail_fqdn}}-https.conf + notify: restart apache diff --git a/ansible/roles/ispmail-webmail-apache-roundcube/templates/config.inc.php.j2 b/ansible/roles/ispmail-webmail-apache-roundcube/templates/config.inc.php.j2 new file mode 100644 index 0000000..6bf304a --- /dev/null +++ b/ansible/roles/ispmail-webmail-apache-roundcube/templates/config.inc.php.j2 @@ -0,0 +1,90 @@ + + ServerName {{ispmail_fqdn}} + DocumentRoot /var/www/{{ispmail_fqdn}} + + RewriteEngine On + RewriteCond %{REQUEST_URI} !\.well-known/acme-challenge + RewriteRule ^(.*)$ https://%{SERVER_NAME}/ [R=301,L] + diff --git a/ansible/roles/ispmail-webmail-apache-roundcube/templates/vhosts/https.j2 b/ansible/roles/ispmail-webmail-apache-roundcube/templates/vhosts/https.j2 new file mode 100644 index 0000000..4a609c6 --- /dev/null +++ b/ansible/roles/ispmail-webmail-apache-roundcube/templates/vhosts/https.j2 @@ -0,0 +1,12 @@ + + ServerName {{ispmail_fqdn}} + DocumentRoot /var/lib/roundcube + + SSLEngine on + SSLCertificateKeyFile /etc/ssl/private/mailserver.pem + SSLCertificateFile /etc/ssl/certs/mailserver.pem + + # When using Let's Encrypt use these line instead: + # SSLCertificateKeyFile /etc/letsencrypt/live/{{ispmail_fqdn}}/privkey.pem + # SSLCertificateFile /etc/letsencrypt/live/{{ispmail_fqdn}}/fullchain.pem +