trombik.opensmtpd

ansible-role-opensmtpd

配置smtpd(8), 又名OpenSMTPD

需求

opensmtpd_include_x509_certificateyes时,trombik.x509-certificate必须可用,通常通过requirements.yml提供。

如果安装了opensmtpd-extras,则opensmtpd API版本必须与opensmtpd-extras的版本匹配。

角色变量

变量 描述 默认值
opensmtpd_user smtpd(8)的用户名 {{ __opensmtpd_user }}
opensmtpd_group smtpd(8)的组名 {{ __opensmtpd_group }}
opensmtpd_service smtpd(8)的服务名 {{ __opensmtpd_service }}
opensmtpd_conf_dir 配置目录的路径 {{ __opensmtpd_conf_dir }}
opensmtpd_conf_file smtpd.conf(5)的路径 {{ opensmtpd_conf_dir }}/smtpd.conf
opensmtpd_flags smtpd(8)的可选标志 ""
opensmtpd_package_name OpenSMTPD的包名 {{ __opensmtpd_package_name }}
opensmtpd_extra_packages 要安装的额外包列表 []
opensmtpd_config smtpd.conf(5)的内容 ""
opensmtpd_makemap_bin makemap(8)的路径 {{ __opensmtpd_makemap_bin }}
opensmtpd_virtual_user 用于将邮件发送到虚拟用户的虚拟用户。见下文。 {}
opensmtpd_extra_groups 要添加smtpd(8)用户的额外组列表 []
opensmtpd_tables 表的列表。见下文。 []
opensmtpd_include_x509_certificate 在执行过程中包含trombik.x509-certificate角色 no

opensmtpd_virtual_user

该字典变量定义要创建的虚拟用户。其键的解释如下。当字典非空时,将创建用户及其主目录。

描述 必需?
comment passwd(5)中的备注字段
group 用户的主组名
groups 用户的其他组
home 用户的主目录
name 用户名
uid 用户UID
mode 主目录的模式。如果省略,模式由系统默认设置

opensmtpd_tables

该列表变量定义table(5)的字典列表。

描述 必需?
name smtpd.conf(5)中使用的表名
path 文件的路径
type 支持的后端类型之一,默认安装仅接受filedb。安装OpenSMTPD-extra以支持其他类型
owner 文件的所有者
group 文件的组
dbtype 数据库支持的格式之一,默认是hash。除非typedb,否则被忽略
format 结果映射文件的格式,见makemap(8)中的-t type以获取可能的值。除非typedb,否则被忽略
mode 文件模式的字符串。注意几乎总是需要引用它。
values 文件的内容列表。见table(5)
no_log 当为yes时,在模板任务中启用no_log。将此设置为no会导致该变量中的所有内容被记录,包括凭据。默认值为yes

opensmtpd_include_x509_certificate

在执行过程中包含角色trombik.x509-certificate。在tests/serverspec/x509.yml中查看示例。

Debian

变量 默认值
__opensmtpd_user opensmtpd
__opensmtpd_group opensmtpd
__opensmtpd_service opensmtpd
__opensmtpd_conf_dir /etc
__opensmtpd_package_name opensmtpd
__opensmtpd_makemap_bin /usr/sbin/makemap

FreeBSD

变量 默认值
__opensmtpd_user _smtpd
__opensmtpd_group _smtpd
__opensmtpd_service smtpd
__opensmtpd_conf_dir /usr/local/etc/mail
__opensmtpd_package_name mail/opensmtpd
__opensmtpd_makemap_bin /usr/local/libexec/opensmtpd/makemap

OpenBSD

变量 默认值
__opensmtpd_user _smtpd
__opensmtpd_group _smtpd
__opensmtpd_service smtpd
__opensmtpd_conf_dir /etc/mail
__opensmtpd_package_name ""
__opensmtpd_makemap_bin /usr/sbin/makemap

RedHat

变量 默认值
__opensmtpd_user smtpd
__opensmtpd_group smtpd
__opensmtpd_service opensmtpd
__opensmtpd_conf_dir /etc/opensmtpd
__opensmtpd_package_name opensmtpd
__opensmtpd_makemap_bin /sbin/makemap

依赖

示例剧本

---

- hosts: localhost
  roles:
    - name: trombik.redhat_repo
      when: ansible_os_family == 'RedHat'
    - role: trombik.freebsd_pkg_repo
      when:
        - ansible_os_family == 'FreeBSD'
    - role: ansible-role-opensmtpd
  vars:
    os_default_group:
      FreeBSD: wheel
      OpenBSD: wheel
      Debian: root
      RedHat: root
    freebsd_pkg_repo:
      FreeBSD:
        enabled: "false"
        state: present
      FreeBSD_latest:
        enabled: "true"
        state: present
        url: pkg+https://pkg.FreeBSD.org/${ABI}/latest
        mirror_type: srv
        signature_type: fingerprints
        fingerprints: /usr/share/keys/pkg
        priority: 100
    redhat_repo:
      epel:
        mirrorlist: "http://mirrors.fedoraproject.org/mirrorlist?repo=epel-{{ ansible_distribution_major_version }}&arch={{ ansible_architecture }}"
        gpgcheck: yes
        enabled: yes

    test_user: [email protected]
    # smtpctl encrypt PassWord
    test_password: "$2b$08$LT/AdE2YSHb19d3hB27.4uXd1/Cj0qQIWc4FdfLlcuqnCUGbRu2Mq"
    # XXX table_passwd在Ubuntu包中,如果UID或GID字段为空会抛出错误
    os_passwd_postfix:
      FreeBSD: ":::::"
      OpenBSD: ":::::"
      Debian: ":12345:12345:::"
      RedHat: ":12345:12345:::"
    passwd_postfix: "{{ os_passwd_postfix[ansible_os_family] }}"

    os_opensmtpd_extra_packages:
      FreeBSD:
        - opensmtpd-extras-table-passwd
      OpenBSD:
        - opensmtpd-extras
      Debian: []
      RedHat: []
    opensmtpd_extra_packages: "{{ os_opensmtpd_extra_packages[ansible_os_family] }}"

    os_opensmtpd_extra_groups:
      FreeBSD:
        - nobody
      OpenBSD:
        - nobody
      Debian:
        - games
      RedHat:
        - games
    opensmtpd_extra_groups: "{{ os_opensmtpd_extra_groups[ansible_os_family] }}"
    opensmtpd_virtual_user:
      name: vmail
      group: vmail
      home: /var/vmail
      comment: 虚拟邮件用户
      mode: "0755"
    opensmtpd_tables:
      - name: aliases
        path: "{{ opensmtpd_conf_dir }}/aliases"
        type: file
        format: aliases
        mode: "644"
        no_log: no
        values:
          - "MAILER-DAEMON: postmaster"
          - "postmaster: root"
          - "daemon: root"
          - "ftp-bugs: root"
          - "operator: root"
          - "www:    root"
          - "foo: error:500 no such user"
          - "bar: | cat - >/dev/null"
      - name: secrets
        path: "{{ opensmtpd_conf_dir }}/secrets"
        type: file
        owner: root
        group: "{{ opensmtpd_group }}"
        mode: "0640"
        no_log: no
        values:
          - "{{ test_user }} {{ test_password }}"
      - name: passwd
        # XXX Ubuntu包不允许非默认路径的smtpd.conf(5)
        # 因此,所有文件都在opensmtpd_conf_dir下。使用smtpd_passwd,
        # 代替一致的文件名`passwd`。
        path: "{{ opensmtpd_conf_dir }}/smtpd_passwd"
        type: passwd
        owner: root
        group: "{{ opensmtpd_group }}"
        mode: "0640"
        no_log: no
        values:
          - "{{ test_user }}:{{ test_password }}{{ passwd_postfix }}"
      - name: domains
        path: "{{ opensmtpd_conf_dir }}/domains"
        type: file
        owner: root
        group: "{{ os_default_group[ansible_os_family] }}"
        mode: "0644"
        no_log: no
        values:
          - example.org
          - example.net
      - name: virtuals
        path: "{{ opensmtpd_conf_dir }}/virtuals"
        type: db
        dbtype: hash
        format: aliases
        owner: root
        group: vmail
        mode: "0444"
        no_log: no
        values:
          - [email protected] [email protected]
          - [email protected] [email protected]
          - [email protected] {{ opensmtpd_virtual_user.name }}
          - [email protected] [email protected]
          - [email protected] [email protected]
          - [email protected] {{ opensmtpd_virtual_user.name }}
      - name: mynetworks
        path: "{{ opensmtpd_conf_dir }}/mynetworks"
        type: db
        format: set
        no_log: no
        values:
          - 192.168.21.0/24

    opensmtpd_flags: -v
    os_listen_on_interface:
      FreeBSD: lo0
      OpenBSD: lo0
      Debian: lo
      RedHat: lo
    opensmtpd_config: |
      {% for list in opensmtpd_tables %}
      {% if list.type == 'passwd' and (ansible_os_family == 'Debian' or ansible_os_family == 'RedHat') %}
      # XXX 目前(2018/05/20),opensmtpd-extras的版本
      # 低于opensmtpd,导致“table-api: bad API version”。
      # https://packages.ubuntu.com/bionic/opensmtpd-extras
      #
      # 在同步版本发布之前跳过passwd表
      #
      # 此外,ubuntu 14.04的opensmtpd-extras已被移除
      {% else %}
      table {{ list.name }} {{ list.type }}:{{ list.path }}{% if list['type'] == 'db' %}.db{% endif %}
      {% endif %}

      {% endfor %}
      listen on {{ os_listen_on_interface[ansible_os_family] }} port 25

      {% if ansible_os_family == 'OpenBSD' or ansible_os_family == 'FreeBSD' %}
      # 新格式
      action "local_mail" maildir "{{ opensmtpd_virtual_user['home'] }}/%{dest.domain}/%{dest.user}/Maildir"
      action "outbound" relay
      match from any for domain <domains> action "local_mail"
      match from src <mynetworks> action "outbound"
      {% else %}
      # 旧格式
      accept from any for domain <domains> virtual <virtuals> \
        deliver to maildir "{{ opensmtpd_virtual_user['home'] }}/%{dest.domain}/%{dest.user}/Maildir"
      accept from any for domain <domains> \
        deliver to mbox
      {% endif %}

许可

版权所有 (c) 2017 Tomoyuki Sakurai <y@trombik.org>

在不收取费用的情况下,特此授予使用、复制、修改和分发本软件的权限,只要上面的版权声明和本许可声明出现在所有副本中。

本软件按“原样”提供,作者对本软件不承担任何担保责任,包括所有隐含的适销性和适用性担保。在任何情况下,作者均不对因使用或运行本软件而导致的任何特别、直接、间接或后果性损害或任何损害承担责任。

作者信息

Tomoyuki Sakurai y@trombik.org

此自述文件由qansible创建。

关于项目

Configures OpenSMTPD

安装
ansible-galaxy install trombik.opensmtpd
许可证
isc
下载
237
拥有者
PGP finger print: 03EB 3D97 5E04 9B0C AB21 93A2 D693 42A9 EFBC 3577 Makerspace and Coliving in Siem Reap, Cambodia: http://info.mkrsgh.org/