Salt: Question: render templates in salt context

Created on 30 May 2016  路  11Comments  路  Source: saltstack/salt

Description of Issue/Question

Hi, I'm interested in rendering jinja templates for examining purposes. Basically, I need some cli tool, that takes sls of any template and renders it for particular case.
What I stumbled across is:

which kinda resolve my problem, but renders only sls and displays them in it's own way (which is not that bad, I just want to see plain yaml).

  • "Debugging" section in

https://docs.saltstack.com/en/latest/ref/renderers/all/salt.renderers.jinja.html

especially salt.renderers.jinja.render function (or is it not a function and something else?). Here I cannot understand how can I use it.

Thanks.

Versions Report

salt --versions-report
Salt Version:
Salt: 2015.8.0

Dependency Versions:
Jinja2: 2.7.3
M2Crypto: Not Installed
Mako: Not Installed
PyYAML: 3.11
PyZMQ: 14.5.0
Python: 2.7.9 (default, Apr 27 2015, 11:42:05)
RAET: Not Installed
Tornado: 4.2.1
ZMQ: 4.0.5
cffi: Not Installed
cherrypy: Not Installed
dateutil: 2.3
gitdb: Not Installed
gitpython: Not Installed
ioflo: Not Installed
libnacl: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.4.2
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pygit2: Not Installed
python-gnupg: Not Installed
smmap: Not Installed
timelib: Not Installed

System Versions:
dist:
machine: amd64
release: 10.2-STABLE-r286912

Core Feature stale

Most helpful comment

there already exists file.get_template on the minion to pull down files and render them.

All 11 comments

See if the yaml outputter does what you need: state.show_sls <state> --out yaml.

https://docs.saltstack.com/en/latest/ref/cli/salt.html#output-options

Thanks, @lorengordon, that's definitely what I need.
One more question: is it possible to render not only sls, but also templates in exact environment (I mean taking into account host's pillars, grains etc.)?

@mallniya, indeed, state.show_sls does exactly that.

As I see:
https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.state.html
salt.modules.state.show_sls "Display the state data from a specific sls or list of sls files on the master". So I assume this cannot render something else except sls (I need render templates, which are not sls too).
I need something like salt host state.apply state test=true output, when it's shown what content will be in (configuration typically) files, which initially was templates. salt host state.apply state test=true renders template and shows only diff in 褋omparsion with files on target host, when I just want to render and see config file.

Ahh, apologies, I was equating templates with sls files. But by template, you mean a file you pass to a state as a source of content. I'm not as certain on that one... There could be an execution module that does it, but I'd have to do some research.

@mallniya I don't believe this is possible currently. Is this something you want to set as a feature request?

I think command to render all files (sls and related to this sls files, which usually defined in source requisite of sls), related to the state would be nice to start with. It'd be very useful for debugging.

I agree. It is really tricky to debug now how your file templates are rendered.

I also think it would be really useful to have an easy way to see templatized file full content (maybe as an option of state.show_sls and state.show_low_sls).

there already exists file.get_template on the minion to pull down files and render them.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

seanacais picture seanacais  路  3Comments

Oloremo picture Oloremo  路  3Comments

sfozz picture sfozz  路  3Comments

lhost picture lhost  路  3Comments

qiushics picture qiushics  路  3Comments