# best way to switch ansible mode to simply dump the output of jinja2 templating

**URL:** <https://forum.ansible.com/t/best-way-to-switch-ansible-mode-to-simply-dump-the-output-of-jinja2-templating/22572>\
**Category:** Ansible Project\
**Created:** [September 16, 2016, 6:47pm UTC](https://forum.ansible.com/t/best-way-to-switch-ansible-mode-to-simply-dump-the-output-of-jinja2-templating/22572 "2016-09-16T18:47:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![K\_Dawg](https://avatars.discourse-cdn.com/v4/letter/k/3ec8ea/32.png) [@K\_Dawg](https://forum.ansible.com/u/K_Dawg)\
**Post date:** [September 16, 2016, 6:47pm UTC](https://forum.ansible.com/t/best-way-to-switch-ansible-mode-to-simply-dump-the-output-of-jinja2-templating/22572/1 "2016-09-16T18:47:50Z")

</div>

Is there a way to simply tell ansible to output any jinja2 templates it would have created when an ansible playbook is run?

I.e., not deploy them but just dump them to local host

Thanks a bunch.

---

<div class="post-metadata">

**Author:** ![bigK](https://avatars.discourse-cdn.com/v4/letter/b/48db29/32.png) [@bigK](https://forum.ansible.com/u/bigK)\
**Post date:** [September 16, 2016, 6:50pm UTC](https://forum.ansible.com/t/best-way-to-switch-ansible-mode-to-simply-dump-the-output-of-jinja2-templating/22572/2 "2016-09-16T18:50:09Z")

</div>

Sorry I meant the output of the templating process on jinja2 template (i.e., after all the replacements are done on the template).

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [September 16, 2016, 11:06pm UTC](https://forum.ansible.com/t/best-way-to-switch-ansible-mode-to-simply-dump-the-output-of-jinja2-templating/22572/3 "2016-09-16T23:06:51Z")

</div>

I don't know of a flag, no (wouldn't be easy to disable handlers,  
prevent local filename collisions, etc).

You \_could\_ use the lookup() function to load the template as a  
string, then use debug: to print the string out.

But you'd have to get any vars the template needed into scope to be  
sure the template ran it would on a host.

So, not easy.

If you're asking because you want to test run a play, i find local VMs  
much simpler.

---

<div class="post-metadata">

**Author:** ![pixel\_fairy](https://avatars.discourse-cdn.com/v4/letter/p/6f9a4e/32.png) [@pixel\_fairy](https://forum.ansible.com/u/pixel_fairy)\
**Post date:** [September 17, 2016, 2:44am UTC](https://forum.ansible.com/t/best-way-to-switch-ansible-mode-to-simply-dump-the-output-of-jinja2-templating/22572/4 "2016-09-17T02:44:54Z")

</div>

Ive thought about this too, and would also like a way to do this, in the mean time, i wrote this script that i call jinjacat.py

`

#!/usr/bin/env python

# public domain

import sys  
import yaml  
import jinja2

if len(sys.argv) != 3:  
print “usage: jinjacat.py template.j2 variables.yaml”  
exit()

with open(sys.argv[1]) as fp:  
template = jinja2.Template(fp.read())

with open(sys.argv[2]) as fp:  
vars = yaml.load(fp.read())

print(template.render(vars))

`
