Skip to content

Logging template issue (KeyError: 'statefile') #2

@max-arnold

Description

@max-arnold

I understand that you explicitly set 'pillar_roots': {},, so this issue is not about 'salt.pillar object' has no attribute 'timezone' (and the example state should use proper defaults).

The relevant traceback ends with KeyError: 'statefile', and it looks like the logging template gets used somewhere else without the necessary key being supplied:

{{ pillar['timezone'] }}:
  timezone.system:
    - utc: True
  file.managed:
    - name: /etc/timezone
    - template: jinja
    - user: root
    - group: root
    - mode: 644
    - contents: {{ pillar['timezone'] }}
$ salint salt/timezone
--- Logging error ---
Traceback (most recent call last):
  File "/Users/user/.virtualenvs/salt/lib/python3.6/site-packages/salt/utils/templates.py", line 389, in render_jinja_tmpl
    output = template.render(**decoded_context)
  File "/Users/user/.virtualenvs/salt/lib/python3.6/site-packages/jinja2/asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "/Users/user/.virtualenvs/salt/lib/python3.6/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/Users/user/.virtualenvs/salt/lib/python3.6/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/user/.virtualenvs/salt/lib/python3.6/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 10, in top-level template code
jinja2.exceptions.UndefinedError: 'salt.pillar object' has no attribute 'timezone'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/user/.virtualenvs/salt/lib/python3.6/site-packages/salt/utils/templates.py", line 170, in render_tmpl
    output = render_str(tmplstr, context, tmplpath)
  File "/Users/user/.virtualenvs/salt/lib/python3.6/site-packages/salt/utils/templates.py", line 399, in render_jinja_tmpl
    buf=tmplstr)
salt.exceptions.SaltRenderError: Jinja variable 'salt.pillar object' has no attribute 'timezone'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py", line 993, in emit
    msg = self.format(record)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py", line 839, in format
    return fmt.format(record)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py", line 579, in format
    s = self.formatMessage(record)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py", line 548, in formatMessage
    return self._style.format(record)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py", line 391, in format
    return self._fmt % record.__dict__
KeyError: 'statefile'
Call stack:
  File "/Users/user/.virtualenvs/salt/bin/salint", line 11, in <module>
    sys.exit(main())
  File "/Users/user/.virtualenvs/salt/lib/python3.6/site-packages/salint/script.py", line 45, in main
    lint.lint_all()
  File "/Users/user/.virtualenvs/salt/lib/python3.6/site-packages/salint/__init__.py", line 137, in lint_all
    self.lint_sls(sls[:-4], path=dir_)
  File "/Users/user/.virtualenvs/salt/lib/python3.6/site-packages/salint/__init__.py", line 114, in lint_sls
    self.lowstate = self.get_low(sls)
  File "/Users/user/.virtualenvs/salt/lib/python3.6/site-packages/salint/__init__.py", line 71, in get_low
    high_, errors = st_.render_highstate({'base': mods})
  File "/Users/user/.virtualenvs/salt/lib/python3.6/site-packages/salt/state.py", line 3770, in render_highstate
    sls, saltenv, mods, matches)
  File "/Users/user/.virtualenvs/salt/lib/python3.6/site-packages/salt/state.py", line 3448, in render_state
    rendered_sls=mods
  File "/Users/user/.virtualenvs/salt/lib/python3.6/site-packages/salt/template.py", line 93, in compile_template
    ret = render(input_data, saltenv, sls, **render_kwargs)
  File "/private/var/folders/fh/j4kp2bt97gxb89plh9h4gxx80000gn/T/pip-install-sgg5ngij/salt/salt/renderers/jinja.py", line 70, in render
  File "/Users/user/.virtualenvs/salt/lib/python3.6/site-packages/salt/utils/templates.py", line 181, in render_tmpl
    log.exception('Rendering exception occurred')
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py", line 1342, in exception
    self.error(msg, *args, exc_info=exc_info, **kwargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py", line 1336, in error
    self._log(ERROR, msg, args, **kwargs)
  File "/Users/user/.virtualenvs/salt/lib/python3.6/site-packages/salt/log/setup.py", line 328, in _log
    self, level, msg, args, exc_info=exc_info, extra=extra
Message: 'Rendering exception occurred'
Arguments: ()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions