saltstack-formulas / template-formula

SaltStack formula template filled with dummy content
http://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html
Other
119 stars 85 forks source link

[BUG] v5.0.0+ failed on Raspberry Pi 4 with error "Jinja variable 'opts' is undefined" #236

Closed nikAizuddin closed 3 years ago

nikAizuddin commented 3 years ago

Your setup

Formula commit hash / release tag

v5.0.2-14-g9ef82f4.

Version v4.3.8 doesn't have this issue. But starting on v5.0.0+, this issue occur Raspberry Pi 4 (x86_64 machines are not affected).

Versions reports (master & minion)

I have tested v5.0.2-14-g9ef82f4 with 3 different masterless minions. Out of 3, only 1 minion failed.

This is the minion that failed, which is running on Raspberry Pi 4:

Salt Version:
          Salt: 3003.1

Dependency Versions:
          cffi: Not Installed
      cherrypy: Not Installed
      dateutil: 2.8.1
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 3.0.1
       libgit2: Not Installed
      M2Crypto: Not Installed
          Mako: 1.1.3
       msgpack: 1.0.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: Not Installed
      pycrypto: Not Installed
  pycryptodome: 3.10.1
        pygit2: Not Installed
        Python: 3.9.5 (default, May 11 2021, 08:20:37)
  python-gnupg: Not Installed
        PyYAML: 5.4.1
         PyZMQ: 22.1.0
         smmap: Not Installed
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.1.4

System Versions:
          dist: ubuntu 21.04 hirsute
        locale: utf-8
       machine: aarch64
       release: 5.11.0-1015-raspi
        system: Linux
       version: Ubuntu 21.04 hirsute

This minion has no problem, running on WSL2:

Salt Version:
          Salt: 3003

Dependency Versions:
          cffi: Not Installed
      cherrypy: Not Installed
      dateutil: Not Installed
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 2.10.1
       libgit2: Not Installed
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 1.0.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: Not Installed
      pycrypto: Not Installed
  pycryptodome: 3.10.1
        pygit2: Not Installed
        Python: 3.8.10 (default, Jun  2 2021, 10:49:15)
  python-gnupg: Not Installed
        PyYAML: 5.3.1
         PyZMQ: 22.0.3
         smmap: Not Installed
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.3.4

System Versions:
          dist: ubuntu 20.04 focal
        locale: utf-8
       machine: x86_64
       release: 5.4.72-microsoft-standard-WSL2
        system: Linux
       version: Ubuntu 20.04 focal

This minion also has no problem, running on Fedora:

Salt Version:
          Salt: 3002.2

Dependency Versions:
          cffi: 1.14.1
      cherrypy: Not Installed
      dateutil: 2.8.1
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 2.11.3
       libgit2: Not Installed
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 1.0.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: 2.20
      pycrypto: Not Installed
  pycryptodome: 3.10.1
        pygit2: Not Installed
        Python: 3.9.6 (default, Jul 16 2021, 00:00:00)
  python-gnupg: Not Installed
        PyYAML: 5.4.1
         PyZMQ: 22.1.0
         smmap: Not Installed
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.3.4

System Versions:
          dist: fedora 33 
        locale: utf-8
       machine: x86_64
       release: 5.13.4-100.fc33.x86_64
        system: Linux
       version: Fedora 33

Pillar / config used

I didn't create pillar files for this test. However, this is /etc/salt/minion from my Raspberry Pi 4:

file_client: local
log_level: 'info'
log_level_logfile: 'info'
pillar_roots:
  base:
    - /srv/pillar
file_roots:
  base:
    - /srv/salt
    - /home/ubuntu/Documents/template-formula
use_superseded:
  - module.run

Bug details

Describe the bug

The following error message appear whenever I try to apply any state.sls states, such as TEMPLATE.config:

local:
    Data failed to compile:
----------
    Rendering SLS 'base:TEMPLATE.config.file' failed: Jinja variable 'opts' is undefined
/var/cache/salt/minion/files/base/TEMPLATE/libsaltcli.jinja(5):
---
# -*- coding: utf-8 -*-
# vim: ft=jinja

{#- Get the relevant values from the `opts` dict #}
{%- set opts_cli = opts.get('__cli', '') %}    <======================
{%- set opts_masteropts_cli = opts | traverse('__master_opts__:__cli', '') %}

{#- Determine the type of salt command being run #}
{%- if opts_cli == 'salt-minion' %}
{%-   set cli = 'minion' %}
[...]
---

Steps to reproduce the bug

Use Raspberry Pi 4.

Clone this template:

git clone https://github.com/saltstack-formulas/template-formula.git

Add path to template-formula into your /etc/salt/minion.

Then, apply TEMPLATE.config:

sudo salt-call -l debug state.sls TEMPLATE.config

Expected behaviour

Error message Rendering SLS 'base:TEMPLATE.config.file' failed: Jinja variable 'opts' is undefined should not occur.

Attempts to fix the bug

I haven't done any attempts yet, but I think the problem comes from TEMPLATE/libmatchers.jinja?

Additional context

myii commented 3 years ago

@nikAizuddin Thanks for the report. You're hitting this issue here:

I've linked directly to my comment with the workaround. We're waiting on a fix from the Salt team.

nikAizuddin commented 3 years ago

ah, i see. I have to downgrade jinja2 to version 2.11.3:

sudo python3 -m pip install jinja2==2.11.3

Thanks @myii . I'm closing this issue.