If you need to use a template without file generation, there is a handy lookup plugin for you: template.

You can use it with lookup function:

- debug: msg="{{ lookup('template', 'mytemplate.j2') }}"

Or with_ statement:

- debug: msg="{{ item }}"
  with_template: mytemplate.j2