LoginSignup
0
0

More than 1 year has passed since last update.

ansible-playbookでpostfixをインストール・設定する

Last updated at Posted at 2022-12-29

はじめに

Postfixをインストールして設定の反映までを実施するansible-playbookです
ansible-playbookの簡単な使い方はわかる前提で記載しています

環境の前提

  • Ubuntu 20.04
  • 導入するサーバは、内側から外側へインターネット接続できること
  • メール送信にはポート25を使用するためFW設定などは適切に設定すること

ファイル構成

L postfix
    - main.cf
- postfix_server.yml
- hosts

main.cfの作成

main.cfを事前に作成しておきます
mynetworksの値は、Postfixを導入するサーバを利用してメール送信をおこなうネットワークセグメントを指定してください

inet_protocols=ipv4
mynetworks=127.0.0.0/8, xxx.yyy.zzz.0/24
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no
append_dot_mydomain = no
readme_directory = no
compatibility_level = 2

hosts

IPアドレスは導入するサーバの値を指定します

[postfix_server]
aaa.bbb.ccc.ddd

postfix_server.yml

やっていることは、以下の3つです

  • Postfixをインストールする
  • main.cfのコピー(事前に作成したファイルに置き換える)
  • postfixサービスを再起動してmain.cfの設定を反映させる
- name: setup postfix server
  hosts: postfix_server
  tasks:
    - name: configure postfix using debconf
      become: true
      debconf:
        name: postfix
        question: "{{ item.question }}"
        value: "{{ item.value }}"
        vtype: "{{ item.vtype }}"
      with_items:
        - { question: postfix/main_mailer_type, value: "No configuration", vtype: select }
    - name: install postfix
      become: true
      apt:
        name: postfix
        update_cache: yes
    - name: copy main.cf
      become: true
      copy:
        src: ./postfix/main.cf
        dest: /etc/postfix
    - name: postfix service restart
      become: true
      systemd:
        name: postfix
        state: restarted
        enabled: yes

おわりに

gmailのようなSMTPサービスを使用する場合はプラスアルファが必要です
似たような内容になりますが別記事にします

0
0
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
0
0