hi,
I want to conditionally import a yaml file if the minion has rhel7, and another one if the minion is rhel8.
This is what works without but no distinction between major os versions (so not what I want):
{%- from salt['pillar.get']('repository_file', tpldir ~ '/repositories_rhel7.jinja') import repositories %}
So the minion looks at the file and imports it and it works.
I want something like this:
{%- if grains['osmajorrelease'] == '7' %}
{%- from salt['pillar.get']('repository_file', tpldir ~ '/repositories_rhel7.jinja') import repositories %}
{%- elif grains['osmajorrelease'] == '8' %}
{%- from salt['pillar.get']('repository_file', tpldir ~ '/repositories_rhel8.jinja') import repositories %}
{%- endif %}
but then:
[ERROR ] Rendering exception occurred
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/salt/utils/templates.py", line 502, in render_jinja_tmpl
output = template.render(**decoded_context)
File "/usr/lib/python3.6/site-packages/jinja2/environment.py", line 1090, in render
self.environment.handle_exception()
File "/usr/lib/python3.6/site-packages/jinja2/environment.py", line 832, in handle_exception
reraise(*rewrite_traceback_stack(source=source))
File "/usr/lib/python3.6/site-packages/jinja2/_compat.py", line 28, in reraise
raise value.with_traceback(tb)
File "<template>", line 12, in top-level template code
File "/usr/lib/python3.6/site-packages/jinja2/sandbox.py", line 407, in getattr
value = getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'repositories' is undefined
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/salt/utils/templates.py", line 261, in render_tmpl
output = render_str(tmplstr, context, tmplpath)
File "/usr/lib/python3.6/site-packages/salt/utils/templates.py", line 509, in render_jinja_tmpl
raise SaltRenderError("Jinja variable {}{}".format(exc, out), buf=tmplstr)
salt.exceptions.SaltRenderError: Jinja variable 'repositories' is undefined
[CRITICAL] Rendering SLS 'username:redhat.localyumrepo' failed: Jinja variable 'repositories' is undefined
local:
Data failed to compile:
----------
Rendering SLS 'dev_username:redhat.localyumrepo' failed: Jinja variable 'repositories' is undefined
What am I doing wrong? I understand the error, the variable is not defined, but why?
Thanks