view mail.py @ 189:ef443257ae9c

new host 'squib'
author drewp@bigasterisk.com
date Mon, 12 Jun 2023 13:01:59 -0700
parents 087b84e68765
children 44b0da2e6d1f
line wrap: on
line source

from pyinfra import host
from pyinfra.operations import apt, files, server, systemd

if host.name == 'prime':
    apt.packages(packages=['postfix', 'isync'])
    files.template(src='templates/mail/main.cf.j2', dest='/etc/postfix/main.cf')
    files.template(src='templates/mail/mydestination.j2', dest='/etc/postfix/mydestination')
    files.put(src='secrets/mail/aliases', dest='/etc/postfix/aliases')
    files.put(src='secrets/mail/sender_access', dest='/etc/postfix/sender_access')
    files.put(src='secrets/mail/virtual', dest='/etc/postfix/virtual')

    server.shell(commands=[
        'postmap /etc/postfix/sender_access',
        'postmap /etc/postfix/virtual',
        'postmap /etc/postfix/aliases',
        'postfix reload',
    ])
    systemd.service(service='postfix@-.service', enabled=True, running=True)

    # something to run ~drewp/mbsync/go at startup

    server.shell(commands=[
        "cd /home/drewp/mbsync; /usr/bin/mbsync-get-cert 10.5.0.1 > servercert",
    ])

# other machines, route mail to bang or prime for delivery

if host.name == 'bang':
    apt.packages(packages=['postfix'])
    files.template(src='templates/mail/main.cf.j2', dest='/etc/postfix/main.cf')
    files.template(src='templates/mail/mydestination.j2', dest='/etc/postfix/mydestination')
    files.put(src='secrets/mail/aliases', dest='/etc/postfix/aliases')
    files.put(src='secrets/mail/sender_access', dest='/etc/postfix/sender_access')
    files.put(src='secrets/mail/virtual', dest='/etc/postfix/virtual')

    server.shell(commands=[
        'postmap /etc/postfix/sender_access',
        'postmap /etc/postfix/virtual',
        'postmap /etc/postfix/aliases',
        'postfix reload',
    ])
    systemd.service(service='postfix@-.service', enabled=True, running=True)

    # server.shell(commands=[
    #     # not working
    #     "cd /my/serv/dovecot; runuser -u drewp -- invoke certs",
    # ])