From bb0f789942d39229a91e83ace72995abfbf93646 Mon Sep 17 00:00:00 2001 From: vincent Date: Sat, 4 Jul 2020 15:10:01 +0200 Subject: [PATCH] chang mail to ssmtp --- defaults/main.yml | 9 +++++++++ files/main.yml | 0 handlers/main.yml | 0 meta/main.yml | 0 tasks/main.yml | 42 +++++++++++++++++++++++++++++++++++++++++ templates/aliases.j2 | 3 +++ templates/main.yml | 0 templates/msmtprc.j2 | 22 +++++++++++++++++++++ templates/ssmtp_conf.j2 | 12 ++++++++++++ vars/main.yml | 0 10 files changed, 88 insertions(+) create mode 100644 defaults/main.yml create mode 100644 files/main.yml create mode 100644 handlers/main.yml create mode 100644 meta/main.yml create mode 100644 tasks/main.yml create mode 100644 templates/aliases.j2 create mode 100644 templates/main.yml create mode 100644 templates/msmtprc.j2 create mode 100644 templates/ssmtp_conf.j2 create mode 100644 vars/main.yml diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..8d414aa --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,9 @@ +notification_mail: "{{inventory_hostname}}@ducamps.win" +msmtp_mailhub: smtp.ducamps.win +msmtp_mailhub_port: 587 +msmtp_hostname: ducamps.win +msmtp_auth_user: vincent@ducamps.win +msmtp_auth_pass: the_mandrill_api_key +msmtp_package: + - msmtp + - msmtp-mta \ No newline at end of file diff --git a/files/main.yml b/files/main.yml new file mode 100644 index 0000000..e69de29 diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..e69de29 diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..e69de29 diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..7c9733b --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,42 @@ + +- name: uninstall ssmtp + package: + state: absent + name: ssmtp + become: yes + +- name: Install msmtp + package: + state: present + name: "{{ msmtp_package }}" + become: yes + +- name: Set up msmtp.conf + template: + src: msmtprc.j2 + dest: /etc/msmtprc + owner: root + group: mail + mode: '0640' + become: yes + +- name: Set up aliases + template: + src: aliases.j2 + dest: /etc/aliases + owner: root + group: mail + mode: '0640' + become: yes + +#- name: set right on /usr/sbin/msmtp +# file: +# path: /usr/sbin/msmtp # required. Path to the file being managed. +# group: mail # not required. Name of the group that should own the file/directory, as would be fed to I(chown). +# mode: 2711 # not required. Mode the file or directory should be. For those used to I(/usr/bin/chmod) remember that modes are actually octal numbers. You must either add a leading zero so that Ansible's YAML parser knows it is an octal number (like C(0644) or C(01777)) or quote it (like C('644') or C('1777')) so Ansible receives a string and can do its own conversion from string into number. Giving Ansible a number without following one of these rules will end up with a decimal number which will have unexpected results. As of version 1.8, the mode may be specified as a symbolic mode (for example, C(u+rwx) or C(u=rw,g=r,o=r)). +# owner: root # not required. Name of the user that should own the file/directory, as would be fed to I(chown). +# become: yes + +#sudo chown root:mail /usr/sbin/msmtp /etc/msmtp{,/{msmtp.conf,revaliases}} +#sudo chmod 2711 /usr/sbin/msmtp +#sudo chmod o-rwx /etc/msmtp /etc/msmtp/msmtp.conf; \ No newline at end of file diff --git a/templates/aliases.j2 b/templates/aliases.j2 new file mode 100644 index 0000000..1f5751c --- /dev/null +++ b/templates/aliases.j2 @@ -0,0 +1,3 @@ + +root:{{msmtp_auth_user}} +{{ user.name }}:{{msmtp_auth_user}} \ No newline at end of file diff --git a/templates/main.yml b/templates/main.yml new file mode 100644 index 0000000..e69de29 diff --git a/templates/msmtprc.j2 b/templates/msmtprc.j2 new file mode 100644 index 0000000..57aa5ea --- /dev/null +++ b/templates/msmtprc.j2 @@ -0,0 +1,22 @@ +# Set default values for all following accounts. +defaults +auth on +tls on +tls_certcheck off +tls_starttls on +logfile /var/log/msmtp.log +aliases /etc/aliases + +# {{msmtp_auth_user}} +account {{msmtp_auth_user}} +host {{msmtp_mailhub}} +port {{msmtp_mailhub_port}} +from {{ notification_mail }} +user {{msmtp_auth_user}} +password {{ msmtp_auth_pass }} + + +# Set a default account +account default : {{msmtp_auth_user}} + + diff --git a/templates/ssmtp_conf.j2 b/templates/ssmtp_conf.j2 new file mode 100644 index 0000000..18b7d58 --- /dev/null +++ b/templates/ssmtp_conf.j2 @@ -0,0 +1,12 @@ + +# ---- basic config +root={{msmtp_auth_user}} +AuthMethod=LOGIN +UseSTARTTLS=Yes +UseTLS=NO +hostname={{msmtp_hostname}} +FromLineOverride=Yes + +AuthUser={{ msmtp_auth_user }} +mailhub={{ msmtp_mailhub }} +AuthPass={{ msmtp_auth_pass }} diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..e69de29