I am looking for a way to test if salt would render a jinja template the way I expect it to.
If I have a file template.sls
containing:
{% for usr in ['moe','larry','curly'] %}
{{ usr }}:
user.present
{% endfor %}
Can I run a salt command that will show me the rendered template?
NB: I understand that what's happening is Jinja doing the rendering, and I can template it in python. But I want to ensure that I am using the Jinja version used by salt. AFAIK salt embeds the jinja engine.
An example of what I am looking for is a salt command that would function similarly to the following ansible command:
The following was taken from accepted answer to: How can I test jinja2 templates in ansible?
3_Ansible (using --check)
Create test playbook jinja2test.yml:
---
- hosts: 127.0.0.1
tasks:
- name: Test jinja2template
template: src=test.j2 dest=test.conf
and run it:
ansible-playbook jinja2test.yml --check --diff --connection=local
sample output:
PLAY [127.0.0.1] **************************************************************
GATHERING FACTS ***************************************************************
ok: [127.0.0.1]
TASK: [Test jinja2template] ***************************************************
--- before: test.conf
+++ after: /Users/user/ansible/test.j2
@@ -0,0 +1,4 @@
+Mike
+Smith
+Klara
+Alex
changed: [127.0.0.1]
PLAY RECAP ********************************************************************
127.0.0.1 : ok=2 changed=1 unreachable=0 failed=0
In order to display the resulting SLS you can use the slsutil.renderer
It's quite easy, and should do the trick. In my case I'm using it like this:
salt 'test01' slsutil.renderer salt://blabla/test.sls 'jinja|yaml'