vbotka.freebsd_mailserver
freebsd_mailserver
Ansible role. FreeBSD。PostfixとDovecot2をインストールして設定します。
要件と依存関係
ロール
ロールはメタファイルには記載されていません。手動でインストールしてください。
- vbotka.ansible_lib Ansibleタスクのライブラリ。
コレクション
以下のコレクションは標準のAnsibleインストールの一部である必要があります。必要に応じて手動でインストールしてください。
- community.crypto
- community.general
推奨
- vbotka.freebsd_mailserver_spamassassin
- vbotka.freebsd-mailserver_sieve
- vbotka.freebsd_mailserver_roundcube
変数
デフォルトと例はvarsを参照してください。
ワークフロー
- 必要に応じてシェルを/bin/shに変更します。
shell> ansible mailserver -e 'ansible_shell_type=csh ansible_shell_executable=/bin/csh' -a 'sudo pw usermod freebsd -s /bin/sh'
- ロールをインストールします。
shell> ansible-galaxy role install vbotka.freebsd_mailserver
shell> ansible-galaxy role install vbotka.ansible_lib
オプションでロールをインストールします。
shell> ansible-galaxy role install vbotka.freebsd_mailserver_sieve
shell> ansible-galaxy role install vbotka.freebsd_mailserver_spamassassin
- 必要に応じてコレクションをインストールします。
shell> ansible-galaxy collection install community.crypto
shell> ansible-galaxy collection install community.general
変数をニーズに合わせて調整します。
OpenSSL Diffie-Hellmanパラメータを生成します。
デフォルトでは、dovecot_ssl_dhファイルはAnsibleモジュールopenssl_dhparamによって作成されます。
dovecot_ssl_dh_generate: true
dovecot_ssl_dh_cmd_generate: false
カスタムコマンドdovecot_ssl_dh_cmdを使用してdovecot_ssl_dhを作成することもできます。
dovecot_ssl_dh_generate: false
dovecot_ssl_dh_cmd_generate: true
dovecot_ssl_dh_cmd: "openssl dhparam -out {{ dovecot_ssl_dh }} {{dovecot_ssl_dh_bits }}"
オプションdovecot_ssl_dh_generate(デフォルト:true)とdovecot_ssl_dh_cmd_generate(デフォルト:false)は相互に排他的です。両方のオプションがfalseの場合、ファイルdovecot_ssl_dh_path(デフォルト:files/dh.pem)が使用されます。このファイルはテスト用にロールによって提供されています。本番環境では使用しないでください。
Diffie-Hellmanパラメータファイルの生成には長い時間がかかることがあります。例えば、4096ビットのパラメータはIntel(R) Core(TM) i5-8200Y CPU @ 1.30GHzで約40分かかります。設定の速度を上げるために、ファイルを別々に生成するのが良いアイデアです。
dovecot_ssl_dh_generate: false
dovecot_ssl_dh_cmd_generate: false
dovecot_ssl_dh_path: <生成されたDiffie-Hellmanファイルのパス>
- プレイブックとインベントリを作成します。
shell> cat freebsd-mailserver.yml
- hosts: mailserver
roles:
- vbotka.freebsd_mailserver
shell> cat hosts
[mailserver]
<mailserver-ip-or-fqdn>
[mailserver:vars]
ansible_connection=ssh
ansible_user=freebsd
ansible_become=true
ansible_become_method=sudo
ansible_python_interpreter=/usr/local/bin/python3.9
ansible_perl_interpreter=/usr/local/bin/perl
- 構文をチェックします。
shell> ansible-playbook freebsd-mailserver.yml --syntax-check
- パッケージをインストールします。
- vbotka.freebsd_mailserverロールからパッケージをインストールします。
shell> ansible-playbook freebsd-mailserver.yml -t fm-packages -e fm_install=true
- sieveを有効にした場合
freebsd_mailserver_dovecot_protocols: imap pop3 lmtp sieve
vbotka.freebsd_mailserver_sieveロールからパッケージをインストールします。
shell> ansible-playbook freebsd-mailserver-sieve.yml -t fm_ds_packages -e fm_ds_install=true
- spamassassinを有効にした場合
postfix_master_cf_service_def: "inet n - - - - smtpd -o content_filter=spamfilter"
vbotka.freebsd_mailserver_spamassassinロールからパッケージをインストールします。
shell> ansible-playbook freebsd-mailserver-spamassassin.yml -t fm_sa_packages -e fm_sa_install=true
- Dovecotのデフォルト構成を作成します。
shell> ansible-playbook freebsd-mailserver.yml -t dovecot_example_conf
- ドライランと変更点を表示します。
shell> ansible-playbook freebsd-mailserver.yml --check --diff
- メールサーバーをインストールして設定します。
shell> ansible-playbook freebsd-mailserver.yml
チェックモード
エラーの原因となるDovecotのデフォルト構成ファイルを作成します。
shell> ansible-playbook freebsd-mailserver.yml -t dovecot_example_conf
その後、チェックモードを実行します。
shell> ansible-playbook freebsd-mailserver.yml --check
Ansible lint
ansible-lintを実行する際には、*.ansible-lint.local*設定ファイルを使用します。一部のルールが無効化される場合や、一部の警告が無視される場合があります。設定ファイル内のノートを参照してください。
shell> ansible-lint -c .ansible-lint.local
参考文献
- FreeBSDハンドブック:31.5. メール転送エージェントの変更
- FreeBSDハンドブック:31.7.4. SMTP認証
- PostfixによるSMTPメールサーバー
- FreeBSD-Postfix-MySQL-SpamAssassin-Maia-Virtualセットアップ
- OpenSMTPD、DovecotおよびRspamdを使用したメールサーバーの設定
- Postfixドキュメント
- Postfix SMTPリレーとアクセス制御
- Postfix SASLの使い方
- Postfix SMTP/LMTPクライアントでのSASL認証
- postfix-logwatch - Postfixログパーサーと分析ユーティリティ
- Dovecotマニュアル
- OpenDKIM + SPF FreeBSDフォーラム
- OpenDKIM Debianウィキ
- OpenDKIM ArchLinuxウィキ