はじめに
ユーザーに届くメールがGmailで読めると、見落とす心配がありません。そのためにexim4をセットアップしてみます。環境はDebian 8、Ansible 2.1です。
基本的にGmailAndExim4 - Debian Wikiの通りですが、設定ファイルの分割はNO(false)にしています。また /etc/email-addresses だけではなく /etc/aliases も設定しています。
両者の違いは次の通りだと思いますがよく分かりません。
- /etc/email-addresses にはローカルユーザーが、メールを送信するときに使うアドレスを指定する。
- /etc/aliases にはローカルユーザーに届いたメールを、転送する先のアドレスを指定する。
ansible_playbooks/group_vars/all
mail_aliases:
- { user: 'root', mail: '<user>+root@gmail.com' }
- { user: 'taro', mail: '<user>+taro@gmail.com' }
smtp_servers:
- { server: '*.google.com', user: '<user>+root@gmail.com', password: '<password>' }
- { server: '*.google.com', user: '<user>+taro@gmail.com', password: '<password>' }
ansible_playbooks/roles/exim4/handlers/main.yml
- name: restart exim4
become: yes
command: "{{ item }}"
with_items:
- update-exim4.conf
- invoke-rc.d exim4 restart
- exim4 -qff
ansible_playbooks/roles/exim4/tasks/main.yml
- name: install exim4
become: yes
apt: name='exim4'
tags: exim4
- name: configure exim4
become: yes
lineinfile:
dest: '/etc/exim4/update-exim4.conf.conf'
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
with_items:
- regexp: '^dc_eximconfig_configtype='
line: "dc_eximconfig_configtype='smarthost'" # (1)メール設定の一般的なタイプ
- regexp: '^dc_local_interfaces='
line: "dc_local_interfaces='127.0.0.1'" # (3)入力側 SMTP 接続をリスンする IP アドレス
- regexp: '^dc_other_hostnames='
line: "dc_other_hostnames=''" # (4)メールを受け取るその他の宛先
- regexp: '^dc_relay_domains='
line: "dc_relay_domains=''" # (5)メールをリレーするマシン
- regexp: '^dc_smarthost='
line: "dc_smarthost='smtp.gmail.com::587'" # (6)送出スマートホストの IP アドレスまたはホスト名
- regexp: '^dc_hide_mailname='
line: "dc_hide_mailname='false'" # (7)送出するメールでローカルメール名を隠しますか?
- regexp: '^dc_minimaldns='
line: "dc_minimaldns='false'" # (8)DNS クエリの数を最小限に留めますか (ダイヤルオンデマンド)?
- regexp: '^dc_localdelivery='
line: "dc_localdelivery='mail_spool'" # (9)ローカルメールの配送方式
- regexp: '^dc_use_split_config='
line: "dc_use_split_config='false'" # (10)設定を小さなファイルに分割しますか?
notify: restart exim4
tags: exim4
- name: configure smtp server
become: yes
lineinfile:
dest: '/etc/exim4/passwd.client'
insertafter: EOF
line: "{{ item.server }}:{{ item.user }}:{{ item.password }}"
with_items: "{{ smtp_servers }}"
notify: restart exim4
tags: exim4
- name: configure mail from
become: yes
blockinfile:
dest: '/etc/email-addresses'
insertafter: EOF
marker: "# {mark} ANSIBLE MANAGED BLOCK {{ item.user }}"
content: |
{{ item.user }}: {{ item.mail }}
{{ item.user }}@localhost: {{ item.mail }}
{{ item.user }}@{{ ansible_hostname }}: {{ item.mail }}
{{ item.user }}@{{ ansible_fqdn }}: {{ item.mail }}
with_items: "{{ mail_aliases }}"
tags: exim4
- name: configure mail to
become: yes
lineinfile:
dest: '/etc/aliases'
insertafter: EOF
line: "{{ item.user }}: {{ item.mail }}"
with_items: "{{ mail_aliases }}"
tags: exim4