Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jinja import: Jinja variable 'salt' is undefined #10206

Closed
rabits opened this issue Feb 5, 2014 · 11 comments
Closed

Jinja import: Jinja variable 'salt' is undefined #10206

rabits opened this issue Feb 5, 2014 · 11 comments
Labels
Documentation Relates to Salt documentation fixed-pls-verify fix is linked, bug author to confirm fix
Milestone

Comments

@rabits
Copy link

rabits commented Feb 5, 2014

Description:

I can't import an jinja template that uses predefined variables (like salt, pillar, grains etc) into another template.

Example:

  • openssl/init.sls:
#
# OpenSSL crypto library
#

{% import 'openssl/vars.sls' as ssl %}
  • openssl/vars.ssl
{% set var_home   = salt['pillar.get']('ssl:home', '/srv/ssl') %}
  • Output:
    Data failed to compile:
----------
    Rendering SLS "master:openssl" failed: Jinja variable 'salt' is undefined; line 1

---
#    <======================
# OpenSSL crypto library
#

{% import 'openssl/vars.sls' as ssl %}

[...]

---
  • Version:
ubuntu 12.04 $ salt --versions-report
           Salt: 0.17.5
         Python: 2.7.3 (default, Sep 26 2013, 16:35:25)
         Jinja2: 2.6
       M2Crypto: 0.21.1
 msgpack-python: 0.1.10
   msgpack-pure: Not Installed
       pycrypto: 2.6
         PyYAML: 3.10
          PyZMQ: 13.0.0
            ZMQ: 3.2.2

Thanks

@basepi
Copy link
Contributor

basepi commented Feb 6, 2014

I'm guessing this has something to do with the way that we're injecting those salt-specific variables into the template context. I'm unsure of what it will take (or if it's possible) to inject them into includes as well, but we'll definitely look into it!

@basepi basepi added Bug and removed Bug labels Feb 6, 2014
@basepi basepi added this to the Approved for future release milestone Feb 6, 2014
@kiorky
Copy link
Contributor

kiorky commented Feb 10, 2014

i thinked i may have fixed that via #10307

@rabits
Copy link
Author

rabits commented Feb 11, 2014

Thank you! For now I can't check this, but I will try later.

@rabits
Copy link
Author

rabits commented Mar 20, 2014

Seems like this patch #10307 is not working for my bug (tested on 2014.1.0 release)

@mway
Copy link

mway commented Apr 23, 2014

FWIW, this is still an issue on 2014.1.3 (via PPA). One (cheap) workaround is to wrap the included template in a macro and pass salt (etc) when calling it, but if you're not already using macros, that's certainly not ideal.

@basepi
Copy link
Contributor

basepi commented Apr 23, 2014

@mway This did not get cherry-picked, so the patch is not in 2014.1.3. Could you potentially try applying the patch in #10307 and see if it fixes your issue?

@mway
Copy link

mway commented Apr 23, 2014

Ah, thanks, should've realized. Went to test and realized that this was a silly oversight on my part (I forgot to re-add a with context to the import statement), so I'm no longer seeing the issue in general. Sorry for the noise!

@rabits
Copy link
Author

rabits commented Apr 23, 2014

Wow, seems like it's works with

{% import 'openssl/vars.sls' as ssl with context %}

in version 2013.1.1 without patches ))

@basepi
Copy link
Contributor

basepi commented Apr 24, 2014

Oh good call! I forgot about with context. I think that solves it nicely! We just need to add this prominently to the docs.

jacobhammons added a commit to jacobhammons/salt that referenced this issue Jun 14, 2016
Removes the "Full list of builtin ..." from each module reference list, leaving just the module type for scanability.

Refs saltstack#12470
Refs saltstack#10206
Refs saltstack#10480
Refs saltstack#23522
Refs saltstack#33023
@jacobhammons
Copy link
Contributor

I've added the note about 'with context' at https://docs.saltstack.com/en/latest/topics/jinja/index.html#including-context-during-include-import

@rabits if you think this fix is sufficient please close. Thanks.

@jacobhammons jacobhammons added the fixed-pls-verify fix is linked, bug author to confirm fix label Jun 14, 2016
@rabits
Copy link
Author

rabits commented Jun 14, 2016

Thank you) Totally forgot about closing

@rabits rabits closed this as completed Jun 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Relates to Salt documentation fixed-pls-verify fix is linked, bug author to confirm fix
Projects
None yet
Development

No branches or pull requests

5 participants