FAQ
I am trying to chain a templating renderer (jinja) to python renderer.

It looks like jinja renderer executes fine but python renderer operates
again on the raw file instead of the output produced by jinja.

webserver2.sls

#!jinja|py
{% include "someinclude.sls" %}

def run():
     config = {}
     return config

someinclude.sls

def test1():
     pass

running:
#salt-call --local state.sls webserver2 test=True

gives following output/error:

[DEBUG ] Rendered data from file: /srv/salt/webserver2.sls:
#!jinja|py
def test1():
     pass

def run():
     config = {}
     return config

[CRITICAL] Rendering SLS webserver2 failed, render error: invalid syntax (
webserver2.sls, line 2)
Traceback (most recent call last):
   File "/usr/lib/python2.7/dist-packages/salt/state.py", line 2350, in
render_state
     sls, rendered_sls=mods
   File "/usr/lib/python2.7/dist-packages/salt/template.py", line 84, in
compile_template
     ret = render(input_data, saltenv, sls, **render_kwargs)
   File "/usr/lib/python2.7/dist-packages/salt/renderers/py.py", line 108, in
render
     **kws)
   File "/usr/lib/python2.7/dist-packages/salt/utils/templates.py", line 369,
in py
     sfn
   File "/srv/salt/webserver2.sls", line 2
     {% include "someinclude.sls" %}
      ^
SyntaxError: invalid syntax
[DEBUG ] LazyLoaded .returner



salt version 2014.7.0 on ubuntu 12.04.5, jinja2 2.6, python 2.7.3

Any suggestions how to pipe a templating renderer to python renderer ?

--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Colton Myers at Nov 25, 2014 at 5:52 pm
    That is *very* strange. I can't imagine render piping is broken, or else a large percentage of existing state trees would be completely broken. I'm guessing this is a bug in the py renderer. Would you mind submitting an issue on Github?

    Thanks!

    --
    Colton Myers
    Platform Engineer, SaltStack
    @basepi on Github/Twitter/IRC
    On Nov 21, 2014, at 11:46 AM, John S. wrote:

    I am trying to chain a templating renderer (jinja) to python renderer.

    It looks like jinja renderer executes fine but python renderer operates again on the raw file instead of the output produced by jinja.

    webserver2.sls

    #!jinja|py
    {% include "someinclude.sls" %}

    def run():
    config = {}
    return config

    someinclude.sls

    def test1():
    pass

    running:
    #salt-call --local state.sls webserver2 test=True

    gives following output/error:

    [DEBUG ] Rendered data from file: /srv/salt/webserver2.sls:
    #!jinja|py
    def test1():
    pass

    def run():
    config = {}
    return config

    [CRITICAL] Rendering SLS webserver2 failed, render error: invalid syntax (webserver2.sls, line 2)
    Traceback (most recent call last):
    File "/usr/lib/python2.7/dist-packages/salt/state.py", line 2350, in render_state
    sls, rendered_sls=mods
    File "/usr/lib/python2.7/dist-packages/salt/template.py", line 84, in compile_template
    ret = render(input_data, saltenv, sls, **render_kwargs)
    File "/usr/lib/python2.7/dist-packages/salt/renderers/py.py", line 108, in render
    **kws)
    File "/usr/lib/python2.7/dist-packages/salt/utils/templates.py", line 369, in py
    sfn
    File "/srv/salt/webserver2.sls", line 2
    {% include "someinclude.sls" %}
    ^
    SyntaxError: invalid syntax
    [DEBUG ] LazyLoaded .returner



    salt version 2014.7.0 on ubuntu 12.04.5, jinja2 2.6, python 2.7.3

    Any suggestions how to pipe a templating renderer to python renderer ?


    --
    You received this message because you are subscribed to the Google Groups "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com For more options, visit https://groups.google.com/d/optout <https://groups.google.com/d/optout>.
    --
    You received this message because you are subscribed to the Google Groups "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • John S. at Nov 25, 2014 at 7:00 pm
    Colton,

    If you the check source code of the py renderer you can see that the
    variable 'template' is immediately overwritten with a path to the template
    file being rendered. Normally this variable contains content produced by a
    previous renderer (if any):

    https://github.com/saltstack/salt/blob/develop/salt/renderers/py.py

    def render(template, saltenv='base', sls='', tmplpath=None, **kws):

    template = tmplpath



    The reason for that may be in salt.utils.templates.py.py()

    https://github.com/saltstack/salt/blob/develop/salt/utils/templates.py

    def py(sfn, string=False, **kwargs):
    ....
    mod = imp.load_source(os.path.basename(sfn).split('.')[0], sfn)


    where 'imp' is a python builtin.

    According to the official documentation, imp.load_source() requires 'a real
    file object':

    https://docs.python.org/2/library/imp.html
    "*...It must currently be a real file object, not a user-defined class
    emulating a file*"

    I am not sure if that can be fixed easily. Let me know if you still think I
    should open an issue on Github.


    On Tuesday, November 25, 2014 12:52:55 PM UTC-5, basepi wrote:

    That is *very* strange. I can't imagine render piping is broken, or else a
    large percentage of existing state trees would be completely broken. I'm
    guessing this is a bug in the py renderer. Would you mind submitting an
    issue on Github?

    Thanks!

    --
    Colton Myers
    Platform Engineer, SaltStack
    @basepi on Github/Twitter/IRC

    On Nov 21, 2014, at 11:46 AM, John S. <cloud...@gmail.com <javascript:>>
    wrote:

    I am trying to chain a templating renderer (jinja) to python renderer.

    It looks like jinja renderer executes fine but python renderer operates
    again on the raw file instead of the output produced by jinja.

    webserver2.sls

    #!jinja|py
    {% include "someinclude.sls" %}

    def run():
    config = {}
    return config

    someinclude.sls

    def test1():
    pass

    running:
    #salt-call --local state.sls webserver2 test=True

    gives following output/error:

    [DEBUG ] Rendered data from file: /srv/salt/webserver2.sls:
    #!jinja|py
    def test1():
    pass

    def run():
    config = {}
    return config

    [CRITICAL] Rendering SLS webserver2 failed, render error: invalid syntax (
    webserver2.sls, line 2)
    Traceback (most recent call last):
    File "/usr/lib/python2.7/dist-packages/salt/state.py", line 2350, in
    render_state
    sls, rendered_sls=mods
    File "/usr/lib/python2.7/dist-packages/salt/template.py", line 84, in
    compile_template
    ret = render(input_data, saltenv, sls, **render_kwargs)
    File "/usr/lib/python2.7/dist-packages/salt/renderers/py.py", line 108,
    in render
    **kws)
    File "/usr/lib/python2.7/dist-packages/salt/utils/templates.py", line
    369, in py
    sfn
    File "/srv/salt/webserver2.sls", line 2
    {% include "someinclude.sls" %}
    ^
    SyntaxError: invalid syntax
    [DEBUG ] LazyLoaded .returner



    salt version 2014.7.0 on ubuntu 12.04.5, jinja2 2.6, python 2.7.3

    Any suggestions how to pipe a templating renderer to python renderer ?


    --
    You received this message because you are subscribed to the Google Groups
    "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to salt-users+...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/d/optout.

    --
    You received this message because you are subscribed to the Google Groups "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Colton Myers at Nov 25, 2014 at 7:13 pm
    Yes, please still open an issue so we have a record of it. Ping me on it (@basepi). We may just mark it as "won't fix" but I still want to have an issue for it.

    Thanks for the detective work.

    --
    Colton Myers
    Platform Engineer, SaltStack
    @basepi on Github/Twitter/IRC
    On Nov 25, 2014, at 12:00 PM, John S. wrote:

    Colton,

    If you the check source code of the py renderer you can see that the variable 'template' is immediately overwritten with a path to the template file being rendered. Normally this variable contains content produced by a previous renderer (if any):

    https://github.com/saltstack/salt/blob/develop/salt/renderers/py.py <https://github.com/saltstack/salt/blob/develop/salt/renderers/py.py>

    def render(template, saltenv='base', sls='', tmplpath=None, **kws):

    template = tmplpath



    The reason for that may be in salt.utils.templates.py.py()

    https://github.com/saltstack/salt/blob/develop/salt/utils/templates.py <https://github.com/saltstack/salt/blob/develop/salt/utils/templates.py>

    def py(sfn, string=False, **kwargs):
    ....
    mod = imp.load_source(os.path.basename(sfn).split('.')[0], sfn)


    where 'imp' is a python builtin.

    According to the official documentation, imp.load_source() requires 'a real file object':

    https://docs.python.org/2/library/imp.html <https://docs.python.org/2/library/imp.html>
    "...It must currently be a real file object, not a user-defined class emulating a file"

    I am not sure if that can be fixed easily. Let me know if you still think I should open an issue on Github.



    On Tuesday, November 25, 2014 12:52:55 PM UTC-5, basepi wrote:
    That is *very* strange. I can't imagine render piping is broken, or else a large percentage of existing state trees would be completely broken. I'm guessing this is a bug in the py renderer. Would you mind submitting an issue on Github?

    Thanks!

    --
    Colton Myers
    Platform Engineer, SaltStack
    @basepi on Github/Twitter/IRC
    On Nov 21, 2014, at 11:46 AM, John S. <cloud...@ <>gmail.com <http://gmail.com/>> wrote:

    I am trying to chain a templating renderer (jinja) to python renderer.

    It looks like jinja renderer executes fine but python renderer operates again on the raw file instead of the output produced by jinja.

    webserver2.sls

    #!jinja|py
    {% include "someinclude.sls" %}

    def run():
    config = {}
    return config

    someinclude.sls

    def test1():
    pass

    running:
    #salt-call --local state.sls webserver2 test=True

    gives following output/error:

    [DEBUG ] Rendered data from file: /srv/salt/webserver2.sls:
    #!jinja|py
    def test1():
    pass

    def run():
    config = {}
    return config

    [CRITICAL] Rendering SLS webserver2 failed, render error: invalid syntax (webserver2.sls, line 2)
    Traceback (most recent call last):
    File "/usr/lib/python2.7/dist-packages/salt/state.py", line 2350, in render_state
    sls, rendered_sls=mods
    File "/usr/lib/python2.7/dist-packages/salt/template.py", line 84, in compile_template
    ret = render(input_data, saltenv, sls, **render_kwargs)
    File "/usr/lib/python2.7/dist-packages/salt/renderers/py.py", line 108, in render
    **kws)
    File "/usr/lib/python2.7/dist-packages/salt/utils/templates.py", line 369, in py
    sfn
    File "/srv/salt/webserver2.sls", line 2
    {% include "someinclude.sls" %}
    ^
    SyntaxError: invalid syntax
    [DEBUG ] LazyLoaded .returner



    salt version 2014.7.0 on ubuntu 12.04.5, jinja2 2.6, python 2.7.3

    Any suggestions how to pipe a templating renderer to python renderer ?


    --
    You received this message because you are subscribed to the Google Groups "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@ <>googlegroups.com <http://googlegroups.com/>.
    For more options, visit https://groups.google.com/d/optout <https://groups.google.com/d/optout>.

    --
    You received this message because you are subscribed to the Google Groups "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com For more options, visit https://groups.google.com/d/optout <https://groups.google.com/d/optout>.
    --
    You received this message because you are subscribed to the Google Groups "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupsalt-users @
postedNov 21, '14 at 6:46p
activeNov 25, '14 at 7:13p
posts4
users2

2 users in discussion

John S.: 2 posts Colton Myers: 2 posts

People

Translate

site design / logo © 2022 Grokbase