Cannot attach multiple files to an email

24 views
Skip to first unread message

Matthieu Nantern

unread,
Sep 12, 2018, 10:54:57 AM9/12/18
to Ansible Project
Hi All !

I'm trying to attach multiple file to an email by using the mail module but it's not working at all because I have parameters in my files' name:

- name: send an email
mail:
host: email-smtp.eu-west-1.amazonaws.com
port: 587
username: xxx
password: xxx
from: xxx
to: "{{ item.firstname }} {{ item.lastname }} <{{ item.email }}>"
subject: configuration files
body: "{{ lookup('template', 'email_body.j2') }}"
secure: starttls
attach: "/mnt/data/users_config/{{ item.firstname }}_{{ item.lastname }}.txt /mnt/data/users_config/{{ item.firstname }}_{{ item.lastname }}.pdf"
loop: "{{ users }}"


I tried to add quotes almost everywhere but either it tries to load a single file (not splitting by space) resulting in a [Errno 2] No such file or directory or it ends up with an invalid yaml if I don't have the required quotes.

Any idea ?

Thank you !

Matthieu Nantern

unread,
Sep 13, 2018, 2:42:54 AM9/13/18
to Ansible Project
Ok, I found my mistake  !

I was reading the documentation for Ansible v2.3 which states that attach is:

A space-separated list of pathnames of files to attach to the message.

And I'm using Ansible v2.5 where attach is a classic list...

Using a list is working well.

Sorry for the noise
Reply all
Reply to author
Forward
0 new messages