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

26 views
Skip to first unread message

K Dawg

unread,
Sep 16, 2016, 2:47:50 PM9/16/16
to Ansible Project
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.

Dick Davies

unread,
Sep 16, 2016, 7:06:59 PM9/16/16
to ansible list
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.
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/4ebcbb4a-6e59-4b23-a65b-64c1d03cd3d3%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

bigK

unread,
Sep 16, 2016, 7:28:52 PM9/16/16
to Ansible Project
Sorry I meant the output of the templating process on jinja2 template (i.e., after all the replacements are done on the template).

pixel fairy

unread,
Sep 16, 2016, 10:44:54 PM9/16/16
to Ansible Project
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))
Reply all
Reply to author
Forward
0 new messages