Debian version

will remove other MTAs, added Vagrantfile
This commit is contained in:
Unknown 2018-04-29 02:21:08 +08:00
parent 0a8f71fbbd
commit 7153155289
11 changed files with 211 additions and 97 deletions

18
.gitignore vendored Normal file
View File

@ -0,0 +1,18 @@
# OS generated files #
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
Icon?
ehthumbs.db
Thumbs.db
# Vagrant files #
.virtualbox/
.vagrant/
vagrant_ansible_inventory_*
ansible.cfg
# Other files #
!empty

View File

@ -1,20 +1,20 @@
[![Build Status](https://travis-ci.org/ahelal/ansible-msmtp.svg?branch=master)](https://travis-ci.org/ahelal/ansible-msmtp) [![Build Status](https://travis-ci.org/ahelal/ansible-msmtp.svg?branch=master)](https://travis-ci.org/ahelal/ansible-msmtp)
#Readme #Readme
This ansible role deploys msmtp for Ubuntu 12.04 (tested on vagrant) This ansible role deploys msmtp for Debian 9 stretch (tested on vagrant)
##Prerequisite ##Prerequisite
* Having ansible installed on your workstation. * Having ansible installed on your workstation.
* Having an SMTP server * Having an SMTP server
##How to install ##How to install
* Use github to clone/fork in your role directory * Use github to clone/fork in your role directory
* ansible galaxy ```ansible-galaxy install adham.helal.msmtp``` * ansible galaxy ```ansible-galaxy install adham.helal.msmtp```
##Variables ##Variables
All the default variables are located **defaults/main.yml**. Mostly you would need to configure the following variables. All the default variables are located **defaults/main.yml**. Mostly you would need to configure the following variables.
- *msmtp_accounts:* You can define one or more smtp account - *msmtp_accounts:* You can define one or more smtp account
``` ```
msmtp_accounts: msmtp_accounts:
- account : "gmail" - account : "gmail"
@ -30,23 +30,23 @@ This ansible role deploys msmtp for Ubuntu 12.04 (tested on vagrant)
user : "myuser" user : "myuser"
password : "123456" password : "123456"
``` ```
- *msmtp_default_account:* Default smtp account to use - *msmtp_default_account:* Default smtp account to use
```msmtp_default_account: "gmail"``` ```msmtp_default_account: "gmail"```
- *msmtp_from:* From field - *msmtp_from:* From field
```msmtp_from : "No Reply"``` ```msmtp_from : "No Reply"```
- Logging - Logging
- Option A (syslog) - Option A (syslog)
``` ```
msmtp_log : "syslog" msmtp_log : "syslog"
``` ```
- Option B (file logging) - Option B (file logging)
``` ```
msmtp_log : "file" msmtp_log : "file"
msmtp_logfile : /var/log/msmtp.log msmtp_logfile : /var/log/msmtp.log
@ -58,8 +58,8 @@ This ansible role deploys msmtp for Ubuntu 12.04 (tested on vagrant)
msmtp_log : "no" msmtp_log : "no"
``` ```
- Mail aliases - Mail aliases
- *msmtp_alias_default:* default email this required - *msmtp_alias_default:* default email this required
```msmtp_alias_default : ops@example.com``` ```msmtp_alias_default : ops@example.com```
@ -69,7 +69,7 @@ This ansible role deploys msmtp for Ubuntu 12.04 (tested on vagrant)
- *msmtp_alias_cron:* cron email this optional - *msmtp_alias_cron:* cron email this optional
```msmtp_alias_cron : cron@example.com``` ```msmtp_alias_cron : cron@example.com```
##Configure ##Configure
You can configure your variables in ansible with one of the following You can configure your variables in ansible with one of the following
@ -81,12 +81,12 @@ You can configure your variables in ansible with one of the following
##Run ##Run
**By default the mstmp will fail because the configuration uses a bogus smtp server you need to use a valid smtp server** **By default the mstmp will fail because the configuration uses a bogus smtp server you need to use a valid smtp server**
```ansible-playbook -l hostname msmtp.yml``` ```ansible-playbook -l hostname msmtp.yml```
##Test ##Test
You should get a test mail if it works on the root mail You should get a test mail if it works on the root mail
##Possible issues ##Possible issues
From field requires more work From field requires more work
[http://msmtp.sourceforge.net/doc/msmtp.html#Envelope_002dfrom-address](http://msmtp.sourceforge.net/doc/msmtp.html#Envelope_002dfrom-address) [http://msmtp.sourceforge.net/doc/msmtp.html#Envelope_002dfrom-address](http://msmtp.sourceforge.net/doc/msmtp.html#Envelope_002dfrom-address)

71
Vagrantfile vendored Normal file
View File

@ -0,0 +1,71 @@
# -*- mode: ruby -*-
# vi: set ft=ruby ts=2 sw=2 tw=0 et :
boxes = [
# {
# :name => "ubuntu-1204",
# :box => "bento/ubuntu-12.04",
# :ip => '10.0.0.11',
# :cpu => "50",
# :ram => "256"
# },
# {
# :name => "ubuntu-1404",
# :box => "bento/ubuntu-14.04",
# :ip => '10.0.0.12',
# :cpu => "50",
# :ram => "256"
# },
# {
# :name => "ubuntu-1604",
# :box => "bento/ubuntu-16.04",
# :ip => '10.0.0.13',
# :cpu => "50",
# :ram => "256"
# },
# {
# :name => "debian-7",
# :box => "bento/debian-7",
# :ip => '10.0.0.14',
# :cpu => "50",
# :ram => "256"
# },
# {
# :name => "debian-8",
# :box => "bento/debian-8",
# :ip => '10.0.0.15',
# :cpu => "50",
# :ram => "256"
# },
{
:name => "debian-9",
:box => "bento/debian-9",
:ip => '10.0.0.16',
:cpu => "50",
:ram => "512"
},
]
role = File.basename(File.expand_path(File.dirname(__FILE__)))
Vagrant.configure("2") do |config|
boxes.each do |box|
config.vm.define box[:name] do |vms|
vms.vm.box = box[:box]
vms.vm.hostname = "#{role}-#{box[:name]}"
vms.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--cpuexecutioncap", box[:cpu]]
v.customize ["modifyvm", :id, "--memory", box[:ram]]
end
vms.vm.network :private_network, ip: box[:ip]
vms.vm.provision :ansible do |ansible|
ansible.playbook = "tests/vagrant.yml"
ansible.verbose = "vv"
ansible.compatibility_mode = "2.0"
end
end
end
end

View File

@ -1,28 +1,30 @@
--- ---
msmtp_accounts: msmtp_accounts:
#Account 1 #Account 1
- account : "gmail" - account : gmail
host : "smtp.gmail.com" host : smtp.gmail.com
port : 587 port : 587
auth : "on" auth : "on"
user : "example@gmail.example" from : username@gmail.com
password : "some password" user : username@gmail.com
password : plain-text-password1
#Account 2 #Account 2
- account : "mysmtp" - account : mysmtp
host : "smtp.example" host : smtp.example
port : 587 port : 587
auth : "on" auth : "on"
user : "myuser" from : admin@example.org
password : "123456" user : myuser@example.org
password : plain-text-password2
msmtp_default_account: "gmail" msmtp_default_account: mysmtp
msmtp_from : "My Org" msmtp_domain : example.org
## Logging (Select A) "syslog" or B) "file" logging or C) "no" log ## Logging (Select A) "syslog" or B) "file" logging or C) "no" log
msmtp_log : "syslog" #msmtp_log : "syslog"
#msmtp_logfile : /var/log/msmtp.log msmtp_logfile : /var/log/msmtp.log
## Aliases mail account ( only msmtp_alias_default is required the rest is optional ) ## Aliases mail account ( only msmtp_alias_default is required the rest is optional )
msmtp_alias_default : ops@example. msmtp_alias_default : devops@example.org
msmtp_alias_root : root@example.com msmtp_alias_root : root@example.org
msmtp_alias_cron : cron@example.com msmtp_alias_cron : cron@example.org

View File

@ -1,5 +1,5 @@
--- ---
# send test mail to admin # send test mail to admin
- name: test mail - name: test mail
shell: echo "Test mail from new/updated MSTMP at" `hostname` | mail root -s "Test SMTP `hostname`" shell: echo "Test mail from new/updated MSTMP at" `hostname -f` | mail root -s "Test SMTP at `hostname -f`"
tags: mail tags: mail

View File

@ -1,11 +1,12 @@
galaxy_info: galaxy_info:
author: Adham Helal author: Adham Helal, modified by Christian Wagner
description: "Deploy msmtp mail for Ubuntu 12.04" description: "Deploy msmtp mail for Debian"
min_ansible_version: 1.4 min_ansible_version: 2.4
platforms: platforms:
- name: Ubuntu - name: Debian
versions: versions:
- precise - jessie
- stretch
categories: categories:
- system - system
- networking - networking

View File

@ -1,6 +0,0 @@
---
- hosts: all
sudo: True
roles:
- ansible-msmtp

View File

@ -1,3 +1,62 @@
--- ---
# Deploy msmtp
- name: Update apt cache.
apt:
upgrade: yes
update_cache: yes
cache_valid_time: 14400 # 4 hours
tags: mail
when: ansible_os_family == "Debian"
- include: msmtp.yml - name: Remove other MTAs.
apt:
pkg: "{{ item }}"
state: absent
autoremove: yes
purge: yes
with_items:
- exim4*
- postfix*
- sendmail*
tags:
- mail
- name: Install msmtp and mailx.
apt:
pkg: "{{item}}"
state: present
with_items:
- msmtp-mta
- bsd-mailx
tags: mail
notify: test mail
when: ansible_os_family == "Debian"
# not tested my modifications with Archlinux
- name: Install msmtp and mailx.
pacman: name={{item}} state=present
with_items:
- msmtp
- msmtp-mta
- mailutils
when: ansible_os_family == "Archlinux"
- name: Copy mstprc conf file.
template:
src: msmtprc.j2
dest: /etc/msmtprc
owner: root
group: root
mode: 0644
tags: mail
notify: test mail
- name: Copy aliases conf file.
template:
src: aliases.j2
dest: /etc/aliases
owner: root
group: root
mode: 0644
tags: mail
notify: test mail

View File

@ -1,44 +0,0 @@
---
# Author: Adham Helal
#
# Objective: Deploy msmtp
- name: Update apt cache
apt: update_cache=yes cache_valid_time=3600
tags: mail
when: ansible_os_family == "Debian"
- name: Install msmtp and mailx
apt: pkg={{item}} state=present
with_items:
- msmtp
- msmtp-mta
- bsd-mailx
tags: mail
notify: test mail
when: ansible_os_family == "Debian"
- name: Install msmtp and mailx
pacman: name={{item}} state=present
with_items:
- msmtp
- msmtp-mta
- mailutils
when: ansible_os_family == "Archlinux"
- name: Copy mstprc conf file
template:
src=msmtprc.j2
dest=/etc/msmtprc
owner=root
group=root
mode=0644
tags: mail
notify: test mail
- name: Copy aliases conf file
template: src=aliases.j2 dest=/etc/aliases
owner=root group=root mode=0644
tags: mail
notify: test mail

View File

@ -1,15 +1,17 @@
# {{ ansible_managed }} # {{ ansible_managed }}
# Default settings that all others account inherit
# Default settings that all others accounts inherit
defaults defaults
auth on auth on
tls on tls on
tls_starttls on
{% if msmtp_tls_trust_file is defined %} {% if msmtp_tls_trust_file is defined %}
tls_trust_file {{msmtp_tls_trust_file}} tls_trust_file {{msmtp_tls_trust_file}}
{% else %} {% else %}
tls_trust_file /etc/ssl/certs/ca-certificates.crt tls_trust_file /etc/ssl/certs/ca-certificates.crt
{% endif %} {% endif %}
# Logging # Logging
{% if msmtp_log is defined %} {% if msmtp_log is defined %}
{% if msmtp_log == "syslog" %} {% if msmtp_log == "syslog" %}
syslog on syslog on
@ -18,9 +20,12 @@ logfile {{msmtp_logfile}}
{% endif %} {% endif %}
{% endif %} {% endif %}
# default is localhost. Use domain part of your email address or FQDN of host.
from {{msmtp_from}} domain {{msmtp_domain}}
keepbcc on # default is off. When on, an envelope-from address of the form user@domain will be generated.
auto_from off
# The default is to remove BCC headers.
# remove_bcc_headers on|off
{% if msmtp_accounts is defined %} {% if msmtp_accounts is defined %}
{% for msmtp_account in msmtp_accounts %} {% for msmtp_account in msmtp_accounts %}
@ -29,6 +34,7 @@ account {{msmtp_account.account}}
host {{msmtp_account.host}} host {{msmtp_account.host}}
port {{msmtp_account.port}} port {{msmtp_account.port}}
auth {{msmtp_account.auth}} auth {{msmtp_account.auth}}
from {{msmtp_account.from}}
user {{msmtp_account.user}} user {{msmtp_account.user}}
password {{msmtp_account.password}} password {{msmtp_account.password}}
{% endfor %} {% endfor %}

7
tests/vagrant.yml Normal file
View File

@ -0,0 +1,7 @@
# test file for fail2ban
---
- hosts: all
remote_user: vagrant
become: true
roles:
- ../../