saltstack / saltstack/salt

[BUG] salt-ssh ModuleNotFoundError: No module named 'jinja2.asyncsupport'

Open
#60,035 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Salt-SSH severity-medium
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

Description

salt-ssh 'srv1' state.apply check_pl --python3-bin=/usr/bin/python

returns:

Traceback (most recent call last):
  File "/var/tmp/.root_040010_salt/salt-call", line 27, in <module>
    salt_call()
  File "/var/tmp/.root_040010_salt/pyall/salt/scripts.py", line 437, in salt_call
    import salt.cli.call
  File "/var/tmp/.root_040010_salt/pyall/salt/cli/call.py", line 6, in <module>
    import salt.cli.caller
  File "/var/tmp/.root_040010_salt/pyall/salt/cli/caller.py", line 15, in <module>
    import salt.minion
  File "/var/tmp/.root_040010_salt/pyall/salt/minion.py", line 25, in <module>
    import salt.client
  File "/var/tmp/.root_040010_salt/pyall/salt/client/__init__.py", line 47, in <module>
    import salt.utils.minions
  File "/var/tmp/.root_040010_salt/pyall/salt/utils/minions.py", line 12, in <module>
    import salt.auth.ldap
  File "/var/tmp/.root_040010_salt/pyall/salt/auth/ldap.py", line 18, in <module>
    from jinja2 import Environment
  File "/var/tmp/.root_040010_salt/pyall/jinja2/__init__.py", line 81, in <module>
    _patch_async()
  File "/var/tmp/.root_040010_salt/pyall/jinja2/__init__.py", line 77, in _patch_async
    from jinja2.asyncsupport import patch_all
ModuleNotFoundError: No module named 'jinja2.asyncsupport'

Setup
salt-ssh from saltmaster (3002.5 @ debian9)
remote: ubuntu 18.04LTS

Steps to Reproduce the behavior

run state.apply or cmd.run via salt-ssh

Expected behavior

cmd.run /state.apply succeeed

Screenshots
If applicable, add screenshots to help explain your problem.

Versions Report

Salt Version:
          Salt: 3002.5
 
Dependency Versions:
          cffi: 1.13.2
      cherrypy: 3.5.0
      dateutil: 2.5.3
     docker-py: 1.9.0
         gitdb: 2.0.0
     gitpython: 2.1.1
        Jinja2: 2.9.4
       libgit2: 0.28.4
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 0.6.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: 2.19
      pycrypto: 2.6.1
  pycryptodome: 3.6.1
        pygit2: 1.0.2
        Python: 3.5.3 (default, Nov 18 2020, 21:09:16)
  python-gnupg: Not Installed
        PyYAML: 3.12
         PyZMQ: 17.1.2
         smmap: 2.0.1
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.2.1
 
System Versions:
          dist: debian 9 stretch
        locale: UTF-8
       machine: x86_64
       release: 4.9.0-14-amd64
        system: Linux
       version: Debian GNU/Linux 9 stretch

Additional context

It seems that salt-ssh does not send all modules files from jinja2 library. Because there is a jinja2 lib in /var/tmp/.root_040010_salt/pyall but without asyncsupport.py it throws this error error. Even if I have python3-jinja2 installed on remote server, it does not search jinja2 lib in another python path e.g /usr/lib/python3/dist-packages/

/usr/lib/python3/dist-packages/jinja2/asyncsupport.py

PoC:

root@srv1:/var/tmp/.root_040010_salt# python3
Python 3.6.9 (default, Jan 26 2021, 15:33:00) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages']
>>> from jinja2.asyncsupport import patch_all
>>> 

With /var/tmp/.root_040010_salt/pyall to sys.path:

root@srv1:/var/tmp/.root_040010_salt# python3
Python 3.6.9 (default, Jan 26 2021, 15:33:00) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.insert(0, '/var/tmp/.root_040010_salt/pyall')
>>> sys.path
['/var/tmp/.root_040010_salt/pyall', '', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages']
>>> 
>>> from jinja2.asyncsupport import patch_all
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/var/tmp/.root_040010_salt/pyall/jinja2/__init__.py", line 81, in <module>
    _patch_async()
  File "/var/tmp/.root_040010_salt/pyall/jinja2/__init__.py", line 77, in _patch_async
    from jinja2.asyncsupport import patch_all
ModuleNotFoundError: No module named 'jinja2.asyncsupport'

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the salt-ssh execution path that builds /var/tmp/.root_040010_salt/pyall and inspect the bundled jinja2/init.py, which imports jinja2.asyncsupport. Compare the bundled files with the remote Python installation shown in the report, then verify that salt-ssh state.apply and cmd.run complete successfully without the ModuleNotFoundError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devops, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.