RH358 configuring e-mail transmission -- automated Postfix configuration

Posted by vinny69 on Tue, 04 Jan 2022 11:45:39 +0100

RH358 configuring e-mail transmission – automated Postfix configuration

Use Ansible to configure the SMTP of the Postfix system role. Are the superposition of commonly used modules.

RH358 column address: https://blog.csdn.net/qq_41765918/category_11532281.html

1. Configure SMTP with Postfix system role

The RHEL system roles package provides RHEL system roles Postfix (also known as linux-system-roles.postfix) Ansible role. This role makes it easy to configure postfix on a managed host. It installs the postfix package, configures postfix, and starts, reloads, or restarts services as needed.

**Important: * * RHEL system roles The postfix role does not modify the host's firewall rules, and a separate task must be used to manage the firewall rules.

Role according to Ansible postfix_conf variable to configure postfix. This variable defines a set of key value pairs that specify the configuration settings to apply to the managed host. You can specify any postfix parameter that can be configured with the postconf command. The name of the parameter is the key, and its value should be in / etc / postfix / main Cf the value assigned in the configuration file.

rhel-system-roles. The postfix role has two other variables: postfix_backup and postfix_backup_multiple. These variables control how to back up / etc / postfix / main CF postfix configuration file.

Postfix_ backup_ The multiple variable controls whether the role controls / etc / Postfix / main. Before modifying the Postfix configuration CF perform timestamp backup. When this variable is true, a new backup is created each time the role applies it to the managed host. This is the default.

Postfix_ The backup variable causes the role to copy / etc / Postfix / main before making configuration changes CF convert to a single backup file. Each time this role is executed, the role will copy the current Postfix configuration to / etc / Postfix / main cf.backup. If run multiple times, it overwrites the backup with the latest Postfix configuration. The default value of this variable is false.

**Important: * * when postfix_backup_ When multiple is set to true, the role ignores postfix_ The value of backup.

For example, you can define the following host variables and put them in the host of a specific host_ In the vars file, or in the group of a specific host group_ In the vars file:

postfix_conf:                          # Contains the postconf settings to apply.
  relayhost: "[smtp.example.com]"      # Define relayhost as the company mail relay.
  mynetworks: "127.0.0.0/8 [::1]/128"  # Send messages from 127.0.0.0/8 and [:: 1] / 128 networks.
  myorigin: "example.com"              # Rewrite the e-mail address of the sender who sends mail to the company domain example com
  mydestination: ""                    # Reject all domain transfers by setting the mydestination option to a null value.
  inet_interfaces: "loopback-only" 
postfix_backup_multiple: true          # Create / etc / postfix / main CF timestamp backup.

Even if the managed host is configured correctly, this role currently reapplies the changes and reports the changed tasks.

2 textbook exercises

[student@workstation ~]$ lab smtp-automation start

This command ensures that DNS, SMTP, and IMAP services are available for lab.example Com SMTP relay server.

The lab command in this exercise will set an incomplete Ansible project in ~ / SMTP auto so that it can be found in lab.example Configure a group of servers as empty Postfix clients in the COM domain. These empty clients will use SMTP without authentication lab.example.com mail relay.

At the end of the exercise, you will add a command line tool to the student@lab.example.com Send an email to verify your work. Then confirm that the message has been forwarded to the recipient's mail server.

1. Be familiar with the layout of Ansible project and the contents of list documents.

[student@workstation ~]$ cd ~/smtp-auto
[student@workstation smtp-auto]$ tree
[student@workstation smtp-auto]$ cat inventory
[nullclients]
servera.lab.example.com
serverb.lab.example.com
serverc.lab.example.com
serverd.lab.example.com

2. Review and complete playbook YML script.

The hosts of the script should be set to the nullclients host group.

[student@workstation smtp-auto]$ vim playbook.yml 
---
- name: Configure Null Client Email Service
  become: true
  hosts: nullclients

  vars:
    postfix_conf:
      relayhost: "[smtp.lab.example.com]"
      inet_interfaces: "loopback-only"
      mynetworks: "127.0.0.0/8 [::1]/128"
      myorigin: "lab.example.com"
      mydestination: ""

  roles:
    - linux-system-roles.postfix

3. Syntax check and run.

[student@workstation smtp-auto]$ ansible-playbook --syntax-check playbook.yml

playbook: playbook.yml
[student@workstation smtp-auto]$ ansible-playbook playbook.yml

4. Test the Postfix empty client configuration on the server.

Using the mail command student@lab.example.com Send a message, which uses the / usr/sbin/sendmail helper to send e-mail. Use the - s option to set Null client test as the subject, enter null client test content as the content, and then add a period (.) at the beginning of the line Mark the end of the content and send an email

[student@servera ~]$ mail -s 'Null client test' student@lab.example.com
null client test content
.
EOT

5. Verify the email status.

By checking the in the mailbox student@lab.example , verify whether the server has delivered the message to the mail relay and successfully passed IMAP lab.example. Com successfully delivered the message to the recipient's mail server.

[student@servera ~]$ mutt -f imaps://imap.lab.example.com
# Press a to accept the certificate and avoid prompting later.
Username at imap.lab.example.com: student
Password for student@imap.lab.example.com: student

Complete the experiment.

[student@workstation ~]$ lab smtp-automation finish

summary

  • Use Ansible to configure the SMTP of the Postfix system role.
  • If you like brother goldfish's article, please praise it. You can also pay attention, because the follow-up will continue to dry goods.

Topics: Linux Operation & Maintenance server