salt: grains.filter_by grain value doesn't support list
Description of Issue/Question
grains.filter_by grain value doesn’t support a list when use list ,return AttributeError: ‘list’ object has no attribute ‘split’
Setup
map.jinja:
{% set fluentd = salt['grains.filter_by']({
'Ubuntu-12.04': {'pkg': 'td-agent_2.3.4-0.precise.amd64.deb'},
'Ubuntu-14.04': {'pkg': 'td-agent_2.3.4-0.precise.amd64.deb'},
'Ubuntu-16.04': {'pkg': 'td-agent_2.3.4-0.precise.amd64.deb'},
'CentOS-6': {'pkg': 'td-agent_2.3.4-0.el6.amd64.deb'},
'CentOS-7': {'pkg': 'td-agent_2.3.4-0.precise.amd64.deb'},
'Debian': {'pkg': 'td-agent_2.3.4-0.precise.amd64.deb'},
'RedHat': {'pkg': 'td-agent_2.3.4-0.elrh.amd64.deb'},
},grain=['osfinger','os_family'], default='RedHat') %}
init.sls:
{% from "install/fluentd/map.jinja" import fluentd with context %}
/tmp/salt.debug:
file.managed:
- contents: |
{%- for k,v in fluentd.items() %}
{{ k }} => {{ v }}
{%- endfor %}
Steps to Reproduce Issue
salt -S 192.168.12.192 state.sls install.fluentd
192.168.12.192:
Data failed to compile:
----------
Rendering SLS 'base:install.fluentd' failed: Jinja error: 'list' object has no attribute 'split'
/var/cache/salt/minion/files/base/install/fluentd/map.jinja(1):
---
{% set fluentd = salt['grains.filter_by']({ <======================
'Ubuntu-12.04': {'pkg': 'td-agent_2.3.4-0.precise.amd64.deb'},
'Ubuntu-14.04': {'pkg': 'td-agent_2.3.4-0.precise.amd64.deb'},
'Ubuntu-16.04': {'pkg': 'td-agent_2.3.4-0.precise.amd64.deb'},
'CentOS-6': {'pkg': 'td-agent_2.3.4-0.el6.amd64.deb'},
'CentOS-7': {'pkg': 'td-agent_2.3.4-0.precise.amd64.deb'},
[...]
---
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/salt/utils/templates.py", line 368, in render_jinja_tmpl
output = template.render(**decoded_context)
File "/usr/lib64/python2.6/site-packages/jinja2/environment.py", line 669, in render
return self.environment.handle_exception(exc_info, True)
File "<template>", line 1, in top-level template code
File "/usr/lib64/python2.6/site-packages/jinja2/environment.py", line 713, in make_module
return TemplateModule(self, self.new_context(vars, shared, locals))
File "/usr/lib64/python2.6/site-packages/jinja2/environment.py", line 769, in __init__
self._body_stream = list(template.root_render_func(context))
File "/var/cache/salt/minion/files/base/install/fluentd/map.jinja", line 1, in top-level template code
{% set fluentd = salt['grains.filter_by']({
File "/usr/lib/python2.6/site-packages/salt/modules/grains.py", line 555, in filter_by
val = salt.utils.traverse_dict_and_list(__grains__, grain, [])
File "/usr/lib/python2.6/site-packages/salt/utils/__init__.py", line 1547, in traverse_dict_and_list
for each in key.split(delimiter):
AttributeError: 'list' object has no attribute 'split'
Versions Report
Salt Version:
Salt: 2016.11.2
Dependency Versions:
cffi: Not Installed
cherrypy: Not Installed
dateutil: 1.5
gitdb: 0.5.4
gitpython: 0.3.2 RC1
ioflo: Not Installed
Jinja2: 2.7.2
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: Not Installed
Mako: 0.9.1
msgpack-pure: Not Installed
msgpack-python: 0.4.6
mysql-python: 1.2.3
pycparser: Not Installed
pycrypto: 2.6.1
pygit2: Not Installed
Python: 2.7.6 (default, Jun 22 2015, 17:58:13)
python-gnupg: Not Installed
PyYAML: 3.10
PyZMQ: 14.0.1
RAET: Not Installed
smmap: 0.8.2
timelib: Not Installed
Tornado: 4.2.1
ZMQ: 4.0.5
System Versions:
dist: Ubuntu 14.04 trusty
machine: x86_64
release: 3.19.0-25-generic
system: Linux
version: Ubuntu 14.04 trusty
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 22 (8 by maintainers)
Still relevant. I can replicate it as follows:
test_grains.jinja
test_grains.sls
The part in the docs that suggests this should be possible: https://docs.saltstack.com/en/master/ref/modules/all/salt.modules.grains.html#salt.modules.grains.filter_by
Trying
grain='os_family,osfinger'also does not work.Same problem at my side, doing grain=‘osfinger,os_family’ does not work either, it will fall back to default then.
I cannot find evidence that this is possible because this value is undergone split if it is str or not. A traversal is applied to this string, but this will give you an empty list if you do ‘osfinger:os_family’ because there is no dict behind osfinger that holds the key os_family. And yes, the only delimiter you can apply here is ‘:’.
For completeness, the current version I’m running all that on.
@SaltStackSupport Can we please have the stalebot not be so aggressive. 30 days is way too aggressive