Looping over email addresses in Mail module

Hey everyone,

I’m still a bit new to Ansible, so sorry if this has an obvious answer

Basically, I’ve got a list of email addresses that I want to send an email to one at a time and I’m using the Community.General Mail module to send the emails. I can get it working with a static list of emails that I manually enter into the recipient list.

However when I try to loop over a list of emails, it looks like Ansible just skips over the task and doesn’t even try to send an email. I’ve tried using garbage in the list in an attempt to throw an error, but nothing.

Here’s the code I’m using

[…]

mail:
host: “{{ smtp_host_var }}”
port: “{{ smtp_port_var }}”
username: “{{ smtp_username_var }}”
password: “{{ smtp_password_var }}”

I’m afraid the problem is in the first “[…]”. I.e., we’ll need to see more context. First thing I’d do if I were you is stick a debug task right before this (unnamed?) task to dump the value of users_to_add.objects. Guessing it isn’t what you think it is. (And we have no clue.)

Thanks for the feedback

Turns out you were exactly right - the list I was trying to iterate over was empty, hence the output being blank and obviously no email sending.

Appreciate the help!