Debian version
will remove other MTAs, added Vagrantfile
This commit is contained in:
parent
0a8f71fbbd
commit
7153155289
18
.gitignore
vendored
Normal file
18
.gitignore
vendored
Normal 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
|
36
README.md
36
README.md
|
@ -1,20 +1,20 @@
|
|||
[![Build Status](https://travis-ci.org/ahelal/ansible-msmtp.svg?branch=master)](https://travis-ci.org/ahelal/ansible-msmtp)
|
||||
#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
|
||||
* Having ansible installed on your workstation.
|
||||
* Having an SMTP server
|
||||
* Having ansible installed on your workstation.
|
||||
* Having an SMTP server
|
||||
|
||||
##How to install
|
||||
* Use github to clone/fork in your role directory
|
||||
* ansible galaxy ```ansible-galaxy install adham.helal.msmtp```
|
||||
|
||||
##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
|
||||
|
||||
##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:
|
||||
- account : "gmail"
|
||||
|
@ -30,23 +30,23 @@ This ansible role deploys msmtp for Ubuntu 12.04 (tested on vagrant)
|
|||
user : "myuser"
|
||||
password : "123456"
|
||||
```
|
||||
- *msmtp_default_account:* Default smtp account to use
|
||||
- *msmtp_default_account:* Default smtp account to use
|
||||
|
||||
```msmtp_default_account: "gmail"```
|
||||
|
||||
- *msmtp_from:* From field
|
||||
|
||||
```msmtp_from : "No Reply"```
|
||||
|
||||
- Logging
|
||||
|
||||
- Logging
|
||||
- Option A (syslog)
|
||||
|
||||
|
||||
```
|
||||
msmtp_log : "syslog"
|
||||
```
|
||||
|
||||
- Option B (file logging)
|
||||
|
||||
|
||||
```
|
||||
msmtp_log : "file"
|
||||
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"
|
||||
```
|
||||
|
||||
- Mail aliases
|
||||
- *msmtp_alias_default:* default email this required
|
||||
- Mail aliases
|
||||
- *msmtp_alias_default:* default email this required
|
||||
|
||||
```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@example.com```
|
||||
```msmtp_alias_cron : cron@example.com```
|
||||
|
||||
##Configure
|
||||
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
|
||||
**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```
|
||||
|
||||
##Test
|
||||
You should get a test mail if it works on the root mail
|
||||
|
||||
##Possible issues
|
||||
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)
|
||||
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)
|
||||
|
|
71
Vagrantfile
vendored
Normal file
71
Vagrantfile
vendored
Normal 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
|
|
@ -1,28 +1,30 @@
|
|||
---
|
||||
msmtp_accounts:
|
||||
#Account 1
|
||||
- account : "gmail"
|
||||
host : "smtp.gmail.com"
|
||||
- account : gmail
|
||||
host : smtp.gmail.com
|
||||
port : 587
|
||||
auth : "on"
|
||||
user : "example@gmail.example"
|
||||
password : "some password"
|
||||
from : username@gmail.com
|
||||
user : username@gmail.com
|
||||
password : plain-text-password1
|
||||
#Account 2
|
||||
- account : "mysmtp"
|
||||
host : "smtp.example"
|
||||
- account : mysmtp
|
||||
host : smtp.example
|
||||
port : 587
|
||||
auth : "on"
|
||||
user : "myuser"
|
||||
password : "123456"
|
||||
from : admin@example.org
|
||||
user : myuser@example.org
|
||||
password : plain-text-password2
|
||||
|
||||
msmtp_default_account: "gmail"
|
||||
msmtp_from : "My Org"
|
||||
msmtp_default_account: mysmtp
|
||||
msmtp_domain : example.org
|
||||
|
||||
## Logging (Select A) "syslog" or B) "file" logging or C) "no" log
|
||||
msmtp_log : "syslog"
|
||||
#msmtp_logfile : /var/log/msmtp.log
|
||||
#msmtp_log : "syslog"
|
||||
msmtp_logfile : /var/log/msmtp.log
|
||||
|
||||
## Aliases mail account ( only msmtp_alias_default is required the rest is optional )
|
||||
msmtp_alias_default : ops@example.
|
||||
msmtp_alias_root : root@example.com
|
||||
msmtp_alias_cron : cron@example.com
|
||||
msmtp_alias_default : devops@example.org
|
||||
msmtp_alias_root : root@example.org
|
||||
msmtp_alias_cron : cron@example.org
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
# send test mail to admin
|
||||
- name: test mail
|
||||
shell: echo "Test mail from new/updated MSTMP at" `hostname` | mail root -s "Test SMTP `hostname`"
|
||||
tags: mail
|
||||
shell: echo "Test mail from new/updated MSTMP at" `hostname -f` | mail root -s "Test SMTP at `hostname -f`"
|
||||
tags: mail
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
galaxy_info:
|
||||
author: Adham Helal
|
||||
description: "Deploy msmtp mail for Ubuntu 12.04"
|
||||
min_ansible_version: 1.4
|
||||
author: Adham Helal, modified by Christian Wagner
|
||||
description: "Deploy msmtp mail for Debian"
|
||||
min_ansible_version: 2.4
|
||||
platforms:
|
||||
- name: Ubuntu
|
||||
- name: Debian
|
||||
versions:
|
||||
- precise
|
||||
- jessie
|
||||
- stretch
|
||||
categories:
|
||||
- system
|
||||
- networking
|
||||
- networking
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -1,15 +1,17 @@
|
|||
# {{ ansible_managed }}
|
||||
# Default settings that all others account inherit
|
||||
|
||||
# Default settings that all others accounts inherit
|
||||
defaults
|
||||
auth on
|
||||
tls on
|
||||
tls_starttls on
|
||||
{% if msmtp_tls_trust_file is defined %}
|
||||
tls_trust_file {{msmtp_tls_trust_file}}
|
||||
{% else %}
|
||||
tls_trust_file /etc/ssl/certs/ca-certificates.crt
|
||||
{% endif %}
|
||||
|
||||
# Logging
|
||||
# Logging
|
||||
{% if msmtp_log is defined %}
|
||||
{% if msmtp_log == "syslog" %}
|
||||
syslog on
|
||||
|
@ -18,9 +20,12 @@ logfile {{msmtp_logfile}}
|
|||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
|
||||
from {{msmtp_from}}
|
||||
keepbcc on
|
||||
# default is ‘localhost’. Use domain part of your email address or FQDN of host.
|
||||
domain {{msmtp_domain}}
|
||||
# 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 %}
|
||||
{% for msmtp_account in msmtp_accounts %}
|
||||
|
@ -29,6 +34,7 @@ account {{msmtp_account.account}}
|
|||
host {{msmtp_account.host}}
|
||||
port {{msmtp_account.port}}
|
||||
auth {{msmtp_account.auth}}
|
||||
from {{msmtp_account.from}}
|
||||
user {{msmtp_account.user}}
|
||||
password {{msmtp_account.password}}
|
||||
{% endfor %}
|
||||
|
|
7
tests/vagrant.yml
Normal file
7
tests/vagrant.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
# test file for fail2ban
|
||||
---
|
||||
- hosts: all
|
||||
remote_user: vagrant
|
||||
become: true
|
||||
roles:
|
||||
- ../../
|
Loading…
Reference in a new issue