We have an Ansible script that sends an email when a server has been updated. In the script I want to to use variables from two different locations for the send to addresses. The first location is from the inventory itself and is called owner_email the second is from the vars section of the roles called mb_addresses. In the script I am trying to figure out how to set it up. The relevant section is this:
- name: Send the report
mail:
host: our.mailserver.com
port: 25
to:
- "{{ owner_email }}"
- "{{ mb_addresses }}"
from: Tower@thiscompany.com
subject: Linux monthly patch results
body: "{{ lookup('file', '/depot/reports/patch/{{inventory_hostname}}_patch_report.txt') }}"
delegate_to: localhost
become: no
In the main.yml of the vars section mb_address is set up this way:
mb_addresses: "first.email@thiscompany.com,second.email@thiscompany.com"
The problem with that is I get the first email but the second is ignored.
The same happens if I set it up like this:
mb_addresses: '"first.email@thiscompany.com" "second.email@thiscompany.com"'
I have tried it like this:
mb_addresses:
- "first.email@thiscompany.com"
- "second.email@thiscompany.com"
When it is done this way neither email is picked up.
What I am trying to avoid is to go into each inventory item and add in a stock group to receive the completion emails.
What am I missing?