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

[BUG] Problem with mine.get in state #57808

Open
johje349 opened this issue Jun 26, 2020 · 1 comment
Open

[BUG] Problem with mine.get in state #57808

johje349 opened this issue Jun 26, 2020 · 1 comment
Labels
Bug broken, incorrect, or confusing behavior P3 Priority 3 severity-low 4th level, cosemtic problems, work around exists
Milestone

Comments

@johje349
Copy link

Description
After upgrading to 3001 one of my states started to fail with "Jinja variable list object has no element 0"

Setup
I narrowed it down to a simple test:

{% for sourceHost, sourceIp in salt['mine.get']('*', 'network.ip_addrs', 'compound').items() %}
isList: {{ sourceIp | is_list }}
sourceIpList: {{ sourceIp }}
sourceIp: {{ sourceIp[0] }}
{% endfor %}

Running salt-call state.apply test:

[ERROR   ] Rendering exception occurred
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/salt/utils/templates.py", line 400, in render_jinja_tmpl
    output = template.render(**decoded_context)
  File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 989, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 754, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3/dist-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 4, in top-level template code
jinja2.exceptions.UndefinedError: list object has no element 0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/salt/utils/templates.py", line 166, in render_tmpl
    output = render_str(tmplstr, context, tmplpath)
  File "/usr/lib/python3/dist-packages/salt/utils/templates.py", line 407, in render_jinja_tmpl
    raise SaltRenderError("Jinja variable {0}{1}".format(exc, out), buf=tmplstr)
salt.exceptions.SaltRenderError: Jinja variable list object has no element 0

Now if I replace '*' as target with a hostname I get the expected result:

{% for sourceHost, sourceIp in salt['mine.get']('asx-salt', 'network.ip_addrs', 'compound').items() %}
isList: {{ sourceIp | is_list }}
sourceIpList: {{ sourceIp }}
sourceIp: {{ sourceIp[0] }}
{% endfor %}
Running salt-call state.apply test
[DEBUG   ] Rendered data from file: /var/cache/salt/minion/files/base/test/init.sls:

isList: True
sourceIpList: ['10.133.45.67']
sourceIp: 10.133.45.67

Versions Report

salt --versions-report (Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)
Salt Version:
           Salt: 3001
 
Dependency Versions:
           cffi: Not Installed
       cherrypy: 3.5.0
       dateutil: 2.4.2
      docker-py: Not Installed
          gitdb: 0.6.4
      gitpython: 1.0.1
         Jinja2: 2.8
        libgit2: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.6.2
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: 3.4.7
         pygit2: Not Installed
         Python: 3.5.2 (default, Apr 16 2020, 17:47:17)
   python-gnupg: 0.3.8
         PyYAML: 3.11
          PyZMQ: 17.1.2
          smmap: 0.9.0
        timelib: 0.2.4
        Tornado: 4.5.3
            ZMQ: 4.1.4
 
System Versions:
           dist: ubuntu 16.04 Xenial Xerus
         locale: UTF-8
        machine: x86_64
        release: 4.4.0-166-generic
         system: Linux
        version: Ubuntu 16.04 Xenial Xerus

Additional context

salt-minion --versions-report
Salt Version:
           Salt: 3001
 
Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.4.2
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
         Jinja2: 2.8
        libgit2: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.6.2
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: Not Installed
   pycryptodome: 3.4.7
         pygit2: Not Installed
         Python: 3.5.2 (default, Oct  8 2019, 13:06:37)
   python-gnupg: 0.3.8
         PyYAML: 3.11
          PyZMQ: 17.1.2
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.1.4
 
System Versions:
           dist: ubuntu 16.04 Xenial Xerus
         locale: UTF-8
        machine: x86_64
        release: 4.4.0-169-generic
         system: Linux
        version: Ubuntu 16.04 Xenial Xerus
@johje349 johje349 added the Bug broken, incorrect, or confusing behavior label Jun 26, 2020
@krionbsd krionbsd added severity-low 4th level, cosemtic problems, work around exists P3 Priority 3 labels Jun 26, 2020
@krionbsd krionbsd added this to the Approved milestone Jun 26, 2020
@github-abcde
Copy link
Contributor

@johje349 Does this give you the same result as state.apply? salt-call cp.get_template salt://test/init.sls /tmp/foo && cat /tmp/foo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior P3 Priority 3 severity-low 4th level, cosemtic problems, work around exists
Projects
None yet
Development

No branches or pull requests

3 participants