from fabric.api import env, local, put, run, sudo, task env.hosts = ['theos.kyriasis.com', 'lucifer.kyriasis.com'] def checksum_match(local_file, remote_file): md5 = '/usr/bin/md5sum {}' local_sum = local(md5.format(local_file), capture=True).split()[0] remote_sum = run(md5.format(remote_file)).split()[0] return local_sum == remote_sum @task def deploy(): upload_users() upload_conf() @task def upload_conf(): from fabric.colors import green local_file = '{}/smtpd.conf'.format(env.host) if not checksum_match(local_file, '/etc/smtpd/smtpd.conf'): print(green('==> Config changed, uploading new file...')) put(local_path=local_file, remote_path='/etc/smtpd/smtpd.conf', use_sudo=True) sudo('systemctl restart smtpd.service') @task def upload_users(): from fabric.colors import green local_file = 'common/users' if not checksum_match(local_file, '/etc/smtpd/users'): print(green('==> Users changed, uploading new file...')) put(local_path=local_file, remote_path='/etc/smtpd/users', use_sudo=True) sudo('smtpctl update table users')