LoginSignup
8
8

More than 5 years have passed since last update.

ansibleでpostfix2.11をソースで入れる

Last updated at Posted at 2014-02-26

課題

postfixの公式リリースノートによると、

Postfix stable release 2.11.0 is available. This release ends support for Postfix 2.7.

なるほど

おもむろにデフォルトとremiのパッケージを確認してみる

CentOS 6.4 デフォルトパッケージ

$ postconf  | grep mail_version
mail_version = 2.6.6

remi

remi
$ yum install postfix --enablerepo=remi

Package         Arch                   Version                         Repository       Size
=========================================================================================================
Updating:
postfix        x86_64                   2:2.6.6-6.el6_5                updates          2.0 M

見事に2.6.6なのでソースで2.11.0をインストールする

実施したいこと

  1. 依存パッケージをインストール
  2. ansibleを使うので冪等性を保つためソースを前もってwgetしたものをサーバにコピー
  3. ソースをmake [残課題あり:後述]
  4. postfixユーザを作成
  5. configファイルを配置
  6. 起動スクリプト配置
  7. postfix起動

ファイル配置

.
├── files
│   ├── main.cf
│   ├── postfix
│   └── postfix-2.11.0.tar.gz
├── handlers
│   
├── tasks
│   └── main.yml
├── templates
│   
└── vars
    └── main.yml
vars/main.yml
postfix_file: postfix-2.11.0
task/main.yml
      # postfix の停止
      - name: "Operation | be sure postfix is stopped"
        service: name=postfix state=stopped

      # 初期インストールされているpostfixを削除
      - name: "Remove | pre installed postfix"
        yum: name="postfix" state=absent

      # 必要なパッケージをインストール
      - name: "Install | dependent package"
        yum: name={{ item }} state=installed enablerepo=remi
        with_items:
         - db4*-devel
         - mysql
         - mysql-devel
         - pcre-devel
         - cyrus-sasl-devel
         - openldap-devel

      # postfixをソースでインストール
      - name: "Install | put postfix src file"
        copy: src=roles/postfix/files/{{ postfix_file }}.tar.gz dest=/usr/local/src

      - name: "Install | unpack postfix src [need 'make install' at the remote server]"
        shell: cd /usr/local/src; tar zxvf {{ postfix_file }}.tar.gz; cd {{ postfix_file }}; make

      # postfixをパッケージでインストール
      - name: "Install | postfix package [Don't need to install this when did from src]"
        yum: name=postfix state=installed enablerepo=remi

      # postfix userを追加
      - name: "Setup | add postfix user and group"
        user: name=postfix system=yes createhome=no home=/var/spool/postfix shell=/sbin/nologin

      # postfix confを設置
      - name: "Setup | put postfix conf"
        copy: src=roles/postfix/files/main.cf dest=/etc/postfix mode=644

      # postfix 起動ファイル設置
      - name: "Setup | put postfix init file"
        copy: src=roles/postfix/files/postfix dest=/etc/init.d mode=755

      # (うっかりインストール先を/usr/local/sbinにしてしまったので)シンボリックリンクを設定
      - name: "Setup | create symlink"
        file: src=/usr/local/sbin/{{ item }} dest=/usr/sbin/{{ item }} state=link
        with_items:
          - postconf
          - postlog
          - postalias
          - postcat
          - postdrop
          - postkick
          - postlock
          - postmap
          - postmulti
          - postqueue
          - postsuper

      # postfix の起動、自動起動設定
      - name: "Setup | be sure postfix is running and enabled"
        service: name=postfix state=running enabled=yes

残課題

だいたいのものはソースを展開した後にmake、make installをすれば終了なのだが、postfixでmake installした時にコンソールでインストール先のディレクトリなどをCUIで聞いてくる。

そのため、上記のansibleでやろうとすると入力待ちで延々と処理が進まなくなってしまう。(別のケースでも使えそうなので)このようなケースの時にどうしてるのか知りたい。。。

まとめ

メールサーバをそんなにクラスタ構成にすることはないから今のところは、それぞれのサーバでmake installして対応したけど、、、そこも楽したいw

8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8