Closed jbartak closed 1 year ago
The recommended syntax is salt["grains.get"]("roles")
. That should work in all template contexts, including salt-ssh.
I can confirm @OrangeDog that the proposed syntax works as you said. But still, I'm curious why this specifically doesn't work with salt-ssh.
It's not going to work with salt-ssh due to the way salt-ssh works under the covers by packaging up the thin
directory to then run on the client. I'm closing this as it was syntax issue in the state.
Description When I call:
This is raised:
Click to expand!
``` $ sudo salt-ssh 1.dummy.global-devel state.apply bootstrap test=true [ERROR ] Rendering exception occurred Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/salt/utils/templates.py", line 500, 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 "", line 35, in top-level template code File "/usr/lib/python3.6/site-packages/jinja2/sandbox.py", line 462, in call return __context.call(__obj, *args, **kwargs) TypeError: get() missing 1 required positional argument: 'default' 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 262, in render_tmpl output = render_str(tmplstr, context, tmplpath) File "/usr/lib/python3.6/site-packages/salt/utils/templates.py", line 546, in render_jinja_tmpl "Jinja error: {}{}".format(exc, out), line, tmplstr, trace=tracestr salt.exceptions.SaltRenderError: Jinja error: get() missing 1 required positional argument: 'default' Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/salt/utils/templates.py", line 500, 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 "", line 35, in top-level template code File "/usr/lib/python3.6/site-packages/jinja2/sandbox.py", line 462, in call return __context.call(__obj, *args, **kwargs) TypeError: get() missing 1 required positional argument: 'default' ; line 35 --- [...] {% endif %} {% endwith %} {% endwith %} {% endif %} master_finger: {{ salt.key.finger_master() }} {% if 'opensips' in salt.grains.get('roles') %} <====================== mysql.default_file: /root/.my.cnf {% endif %} - formatter: yaml - merge_if_exists: true - makedirs: true [...] --- [CRITICAL] Rendering SLS 'base:salt.salt-minion' failed: Jinja error: get() missing 1 required positional argument: 'default' Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/salt/utils/templates.py", line 500, 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 "", line 35, in top-level template code File "/usr/lib/python3.6/site-packages/jinja2/sandbox.py", line 462, in call return __context.call(__obj, *args, **kwargs) TypeError: get() missing 1 required positional argument: 'default' ; line 35 --- [...] {% endif %} {% endwith %} {% endwith %} {% endif %} master_finger: {{ salt.key.finger_master() }} {% if 'opensips' in salt.grains.get('roles') %} <====================== mysql.default_file: /root/.my.cnf {% endif %} - formatter: yaml - merge_if_exists: true - makedirs: true [...] --- 1.dummy.global-devel: - Rendering SLS 'base:salt.salt-minion' failed: Jinja error: get() missing 1 required positional argument: 'default' Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/salt/utils/templates.py", line 500, 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 "", line 35, in top-level template code File "/usr/lib/python3.6/site-packages/jinja2/sandbox.py", line 462, in call return __context.call(__obj, *args, **kwargs) TypeError: get() missing 1 required positional argument: 'default' ; line 35 --- [...] {% endif %} {% endwith %} {% endwith %} {% endif %} master_finger: {{ salt.key.finger_master() }} {% if 'opensips' in salt.grains.get('roles') %} <====================== mysql.default_file: /root/.my.cnf {% endif %} - formatter: yaml - merge_if_exists: true - makedirs: true [...] --- ```Moreover, when I explicitly define
default
positional argument with:This is raised:
Click to expand!
``` $ sudo salt-ssh 1.dummy.global-devel state.apply bootstrap test=true [ERROR ] Rendering exception occurred Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/salt/utils/templates.py", line 500, 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 "", line 35, in top-level template code TypeError: argument of type 'function' is not iterable 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 262, in render_tmpl output = render_str(tmplstr, context, tmplpath) File "/usr/lib/python3.6/site-packages/salt/utils/templates.py", line 546, in render_jinja_tmpl "Jinja error: {}{}".format(exc, out), line, tmplstr, trace=tracestr salt.exceptions.SaltRenderError: Jinja error: argument of type 'function' is not iterable Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/salt/utils/templates.py", line 500, 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 "", line 35, in top-level template code TypeError: argument of type 'function' is not iterable ; line 35 --- [...] {% endif %} {% endwith %} {% endwith %} {% endif %} master_finger: {{ salt.key.finger_master() }} {% if 'opensips' in salt.grains.get('roles', default='') %} <====================== mysql.default_file: /root/.my.cnf {% endif %} - formatter: yaml - merge_if_exists: true - makedirs: true [...] --- [CRITICAL] Rendering SLS 'base:salt.salt-minion' failed: Jinja error: argument of type 'function' is not iterable Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/salt/utils/templates.py", line 500, 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 "", line 35, in top-level template code TypeError: argument of type 'function' is not iterable ; line 35 --- [...] {% endif %} {% endwith %} {% endwith %} {% endif %} master_finger: {{ salt.key.finger_master() }} {% if 'opensips' in salt.grains.get('roles', default='') %} <====================== mysql.default_file: /root/.my.cnf {% endif %} - formatter: yaml - merge_if_exists: true - makedirs: true [...] --- 1.dummy.global-devel: - Rendering SLS 'base:salt.salt-minion' failed: Jinja error: argument of type 'function' is not iterable Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/salt/utils/templates.py", line 500, 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 "", line 35, in top-level template code TypeError: argument of type 'function' is not iterable ; line 35 --- [...] {% endif %} {% endwith %} {% endwith %} {% endif %} master_finger: {{ salt.key.finger_master() }} {% if 'opensips' in salt.grains.get('roles', default='') %} <====================== mysql.default_file: /root/.my.cnf {% endif %} - formatter: yaml - merge_if_exists: true - makedirs: true [...] --- ```Setup
Steps to Reproduce the behavior This is already referenced in the Description of this issue.
Expected behavior To have working
salt.grains.get()
withsalt-ssh
.Screenshots N/A
Versions Report
salt --versions-report
(Provided by running salt --versions-report. Please also mention any differences in master/minion versions.) ```yaml $ salt --versions-report Salt Version: Salt: 3003.5 Dependency Versions: cffi: 1.15.0 cherrypy: unknown dateutil: Not Installed docker-py: Not Installed gitdb: Not Installed gitpython: Not Installed Jinja2: 2.11.1 libgit2: Not Installed M2Crypto: 0.35.2 Mako: Not Installed msgpack: 0.6.2 msgpack-pure: Not Installed mysql-python: Not Installed pycparser: 2.21 pycrypto: Not Installed pycryptodome: Not Installed pygit2: Not Installed Python: 3.6.8 (default, Nov 16 2020, 16:55:22) python-gnupg: 0.4.9 PyYAML: 3.13 PyZMQ: 17.0.0 smmap: Not Installed timelib: Not Installed Tornado: 4.5.3 ZMQ: 4.1.4 System Versions: dist: centos 7 Core locale: UTF-8 machine: x86_64 release: 3.10.0-1160.66.1.el7.x86_64 system: Linux version: CentOS Linux 7 Core ```Additional context Curious is, that this is working without any problem under
salt-minion
on the same version, so it's not working only withsalt-ssh
.