Ansible mail module: how to include several files in 'body' option

Hi,
I managed to include a j2 file as ‘body’ option of the ansible mail module:

mail: body: “{{ lookup(‘template’, j2file) }}”

, but need now to include header and footer html files (header.html and footer.html) respectively before and after the j2 file. Is it possible to do it without including these html file in the j2 file? I can’t figure that out.

Note: the j2 file contains ansible variables whereas the html files don’t.

Best,
Sabrina

I would just do the include inside the template, this is what jinja2's
original purpose.

If you don't want to touch the template, you could just concatenate later:

mail: body: "{{ lookup('file', 'header.html') + lookup('template',
j2file) + lookup('file', 'footer.hml'}} "

Thanks Brian, this wroks like a charm :):

mail: body: "{{ lookup(‘file’, ‘header.html’) + lookup(‘template’,
j2file) + lookup(‘file’, ‘footer.hml’}} "

I was doing this:

mail: body: "lookup(‘file’, ‘header.html’) + {{ lookup(‘template’,
j2file) }} + lookup(‘file’, ‘footer.hml’) "

And this wasn’t working as it printed this:

lookup(‘files’, header.html) + "

" + lookup(‘files’, footer.html)

I thought that {{}} were only required to replace the variables in the j2 file.

lookup() <= this is a jinja2 construct in Ansible, so it won't
evaluate outside of a jinja2 context (what {{ }} is).