2022-08-05 21:31:34 +02:00
|
|
|
---
|
2020-09-25 08:01:17 +02:00
|
|
|
####################################################################
|
|
|
|
# WARNING: These are designed specifically for Ansible tests #
|
|
|
|
# and should not be used as examples of how to write Ansible roles #
|
|
|
|
####################################################################
|
|
|
|
|
2022-08-05 21:31:34 +02:00
|
|
|
# Copyright (c) Ansible Project
|
|
|
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2020-03-09 10:11:07 +01:00
|
|
|
# TODO: Our current implementation does not handle SMTP authentication
|
|
|
|
|
2023-11-18 14:34:13 +01:00
|
|
|
- when:
|
|
|
|
# TODO: https://github.com/ansible-collections/community.general/issues/4656
|
|
|
|
- ansible_python.version.major != 3 or ansible_python.version.minor < 12
|
|
|
|
block:
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2023-11-18 14:34:13 +01:00
|
|
|
# NOTE: If the system does not support smtpd-tls (python 2.6 and older) we do basic tests
|
|
|
|
- name: Attempt to install smtpd-tls
|
|
|
|
pip:
|
|
|
|
name: smtpd-tls
|
|
|
|
state: present
|
|
|
|
ignore_errors: true
|
|
|
|
register: smtpd_tls
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2023-11-18 14:34:13 +01:00
|
|
|
- name: Install test smtpserver
|
|
|
|
copy:
|
|
|
|
src: '{{ item }}'
|
|
|
|
dest: '{{ remote_tmp_dir }}/{{ item }}'
|
|
|
|
loop:
|
|
|
|
- smtpserver.py
|
|
|
|
- smtpserver.crt
|
|
|
|
- smtpserver.key
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2023-11-18 14:34:13 +01:00
|
|
|
# FIXME: Verify the mail after it was send would be nice
|
|
|
|
# This would require either dumping the content, or registering async task output
|
|
|
|
- name: Start test smtpserver
|
|
|
|
shell: '{{ ansible_python.executable }} {{ remote_tmp_dir }}/smtpserver.py 10025:10465'
|
|
|
|
async: 45
|
|
|
|
poll: 0
|
|
|
|
register: smtpserver
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2023-11-18 14:34:13 +01:00
|
|
|
- name: Send a basic test-mail
|
|
|
|
mail:
|
|
|
|
port: 10025
|
|
|
|
subject: Test mail 1 (smtp)
|
|
|
|
secure: never
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2023-11-18 14:34:13 +01:00
|
|
|
- name: Send a test-mail with body and specific recipient
|
|
|
|
mail:
|
|
|
|
port: 10025
|
|
|
|
from: ansible@localhost
|
|
|
|
to: root@localhost
|
|
|
|
subject: Test mail 2 (smtp + body)
|
|
|
|
body: Test body 2
|
|
|
|
secure: never
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2023-11-18 14:34:13 +01:00
|
|
|
- name: Send a test-mail with attachment
|
|
|
|
mail:
|
|
|
|
port: 10025
|
|
|
|
from: ansible@localhost
|
|
|
|
to: root@localhost
|
|
|
|
subject: Test mail 3 (smtp + body + attachment)
|
|
|
|
body: Test body 3
|
|
|
|
attach: /etc/group
|
|
|
|
secure: never
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2023-11-18 14:34:13 +01:00
|
|
|
# NOTE: This might fail if smtpd-tls is missing or python 2.7.8 or older is used
|
|
|
|
- name: Send a test-mail using starttls
|
|
|
|
mail:
|
|
|
|
port: 10025
|
|
|
|
from: ansible@localhost
|
|
|
|
to: root@localhost
|
|
|
|
subject: Test mail 4 (smtp + starttls + body + attachment)
|
|
|
|
body: Test body 4
|
|
|
|
attach: /etc/group
|
|
|
|
secure: starttls
|
|
|
|
ignore_errors: true
|
|
|
|
register: starttls_support
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2023-11-18 14:34:13 +01:00
|
|
|
# NOTE: This might fail if smtpd-tls is missing or python 2.7.8 or older is used
|
|
|
|
- name: Send a test-mail using TLS
|
|
|
|
mail:
|
|
|
|
port: 10465
|
|
|
|
from: ansible@localhost
|
|
|
|
to: root@localhost
|
|
|
|
subject: Test mail 5 (smtp + tls + body + attachment)
|
|
|
|
body: Test body 5
|
|
|
|
attach: /etc/group
|
|
|
|
secure: always
|
|
|
|
ignore_errors: true
|
|
|
|
register: tls_support
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2023-11-18 14:34:13 +01:00
|
|
|
- fail:
|
|
|
|
msg: Sending mail using starttls failed.
|
|
|
|
when: smtpd_tls is succeeded and starttls_support is failed and tls_support is succeeded
|
2021-09-24 07:30:14 +02:00
|
|
|
|
2023-11-18 14:34:13 +01:00
|
|
|
- fail:
|
|
|
|
msg: Send mail using TLS failed.
|
|
|
|
when: smtpd_tls is succeeded and tls_support is failed and starttls_support is succeeded
|
|
|
|
|
|
|
|
- name: Send a test-mail with body, specific recipient and specific ehlohost
|
|
|
|
mail:
|
|
|
|
port: 10025
|
|
|
|
ehlohost: some.domain.tld
|
|
|
|
from: ansible@localhost
|
|
|
|
to: root@localhost
|
|
|
|
subject: Test mail 6 (smtp + body + ehlohost)
|
|
|
|
body: Test body 6
|
|
|
|
secure: never
|