# looking for optimizations

**URL:** <https://forum.ansible.com/t/looking-for-optimizations/28404>\
**Category:** Ansible Project\
**Created:** [August 23, 2018, 1:04pm UTC](https://forum.ansible.com/t/looking-for-optimizations/28404 "2018-08-23T13:04:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul3](https://avatars.discourse-cdn.com/v4/letter/p/ce7236/32.png) [@Paul3](https://forum.ansible.com/u/Paul3)\
**Post date:** [August 23, 2018, 1:04pm UTC](https://forum.ansible.com/t/looking-for-optimizations/28404/1 "2018-08-23T13:04:44Z")

</div>

Hey all, I am currently on the older 1.7 (looking to upgrade shortly). I have a question in regards to optimization of tasks.  
I have a role where I collect some output from other task actions and im trying to use them in the mail module.  
Unfortunately if I try to format subject: to how I want the output to look, not all the data is represented correctly in the body of the mail.

I spent some time looking around yesterday and I know that there is a possibility of using a template, but I got myself going with the following.

- name: Distributing files  
synchronize: src=“{{streams\_path}}/” dest=“{{prod\_config}}/” rsync\_opts=“–exclude=scripts/”  
register: sync\_out

- debug: var=sync\_out

`

- set\_fact:  
email1: “The following files have been distributed to the following DCS servers: \n\n”

- set\_fact:  
email2: “{{play\_hosts}}”

- set\_fact:  
email3: “\n\n”

- set\_fact:  
email4: “{{sync\_out.msg | regex\_replace('.\* ')}}”  
run\_once: true  
“{{sync\_out.msg | regex\_replace('.\* ')}}”  
`

- name: email  
local\_action:  
mail  
subject=“\*\*DCS Streams distribution”  
body=“{{email1}}{{email2}}{{email3}}{{email4}}”  
[from="test@foo.com](mailto:from=%22test@foo.com)"  
to=“{{mailto}}”  
run\_once: true

As mentioned, this gets me what I need to see in the body, but it seem excessive to me? was trying to combine everything into a multiline var but the vars “{{play\_hosts}}” and “{{sync\_out.msg | regex\_replace('.\* ')}}” were not being printed correctly as they are lists.

Thanks in advance for any comments…
