Add mail test

This commit is contained in:
paskao 2016-05-15 19:45:07 +02:00
parent 618734e0de
commit b986762f49
5 changed files with 60 additions and 0 deletions

34
local_actions/send-mail Executable file
View file

@ -0,0 +1,34 @@
#!/usr/bin/env python
import argparse
import smtplib
from email.mime.text import MIMEText
text_subtype = 'plain'
content="""\
Test message
"""
subject="Erre test"
def send_mail(server, username, password, destination):
msg = MIMEText(content, text_subtype)
msg['Subject']= subject
msg['From'] = username
conn = smtplib.SMTP(server)
conn.set_debuglevel(True)
conn.login(username, password)
conn.sendmail(username, destination, msg.as_string())
conn.quit()
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--server', action='store', dest='server')
parser.add_argument('-u', '--username', action='store', dest='username')
parser.add_argument('-p', '--password', action='store', dest='password')
parser.add_argument('-d', '--destination', action='store', dest='destination')
args = parser.parse_args()
send_mail(args.server, args.username, args.password, args.destination)

4
test.yml Normal file
View file

@ -0,0 +1,4 @@
---
- include: tests/networking/all.yml
- include: tests/services/all.yml

3
tests/networking/all.yml Normal file
View file

@ -0,0 +1,3 @@
---
- include: internal-ping.yml

3
tests/services/all.yml Normal file
View file

@ -0,0 +1,3 @@
---
- include: mail.yml

16
tests/services/mail.yml Normal file
View file

@ -0,0 +1,16 @@
---
- name: Create fm network
hosts: frontend
vars:
network_name: "{{ fb_network_name }}"
tasks:
- name: Set test email
vars:
server: "{{ hostvars[inventory_hostname].public_ip }}"
username: "{{ item }}@{{ domain }}"
password: "{{ lookup('password', credentials_path + '/users/' + domain + '/' + item ) }}"
local_action: command local_actions/send-mail -s {{ server}} -u {{ username }} -p {{ password }} -d {{ username }}
with_items: "{{ groups['backend'] }}"