Salt: Unable to install salt-minion on windows using salt-cloud | NameError: name 'PsExecClient' is not defined

Created on 24 Oct 2019  路  8Comments  路  Source: saltstack/salt

I am spinning up a windows vm using salt-cloud. The VM works fine but there is no salt-minion installed on it. It fails with this error:

File "/usr/lib/python3.6/site-packages/salt/utils/cloud.py", line 1015, in wait_for_psexecsvc 'cmd.exe', '/c hostname', host, username, password, port=port File "/usr/lib/python3.6/site-packages/salt/utils/cloud.py", line 962, in run_psexec_command client = Client(host, username, password, port=port, encrypt=False, service_name=service_name) File "/usr/lib/python3.6/site-packages/salt/utils/cloud.py", line 875, in __init__ self._client = PsExecClient(server, username, password, port, encrypt) NameError: name 'PsExecClient' is not defined [DEBUG ] Retrying psexec connection to host 10.27.8.210 on port 445 (try 23)

my config is :

test:
   provider: opennebula
   template: test-appliance-vgautam
   image: test-appliance-vgautam-20191022_1100
   win_installer: /etc/salt/cloud.profiles.d/Salt-Minion-2019.2.1-Py2-x86-Setup.exe
   win_username: *****
   win_password: *****
   smb_port: 445

Salt Version:
           Salt: 2019.2.2

Dependency Versions:
           cffi: Not Installed
       cherrypy: unknown
       dateutil: Not Installed
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.8.1
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: 0.33.0
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.5.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: Not Installed
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 3.6.8 (default, Aug  7 2019, 17:28:10)
   python-gnupg: Not Installed
         PyYAML: 3.12
          PyZMQ: 15.3.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.4.2
            ZMQ: 4.1.4

System Versions:
           dist: centos 7.6.1810 Core
         locale: UTF-8
        machine: x86_64
        release: 3.10.0-957.5.1.el7.x86_64
         system: Linux
        version: CentOS Linux 7.6.1810 Core

Debug log :

[DEBUG   ] Closing IPCMessageClient instance
 [DEBUG   ] Deploying 10.27.8.210 at 1571950161.0 (Windows)
[DEBUG   ] Attempting connection to host 10.27.8.210 on port 445
[DEBUG   ] Caught exception in wait_for_port: [Errno 113] No route to host
[DEBUG   ] Retrying connection to host 10.27.8.210 on port 445 (try 1)
[DEBUG   ] Caught exception in wait_for_port: [Errno 113] No route to host
[DEBUG   ] Retrying connection to host 10.27.8.210 on port 445 (try 2)
[DEBUG   ] Caught exception in wait_for_port: [Errno 113] No route to host
[DEBUG   ] Retrying connection to host 10.27.8.210 on port 445 (try 3)
[DEBUG   ] Caught exception in wait_for_port: [Errno 113] No route to host
[DEBUG   ] Retrying connection to host 10.27.8.210 on port 445 (try 4)
[DEBUG   ] Caught exception in wait_for_port: [Errno 113] No route to host
[DEBUG   ] Retrying connection to host 10.27.8.210 on port 445 (try 5)
[DEBUG   ] Caught exception in wait_for_port: [Errno 113] No route to host
[DEBUG   ] Retrying connection to host 10.27.8.210 on port 445 (try 6)
[DEBUG   ] Caught exception in wait_for_port: [Errno 113] No route to host
[DEBUG   ] Retrying connection to host 10.27.8.210 on port 445 (try 7)
[DEBUG   ] Caught exception in wait_for_port: [Errno 113] No route to host
[DEBUG   ] Retrying connection to host 10.27.8.210 on port 445 (try 8)
[DEBUG   ] Caught exception in wait_for_port: [Errno 113] No route to host
[DEBUG   ] Retrying connection to host 10.27.8.210 on port 445 (try 9)
[DEBUG   ] Caught exception in wait_for_port: [Errno 113] No route to host
[DEBUG   ] Retrying connection to host 10.27.8.210 on port 445 (try 10)
[DEBUG   ] Caught exception in wait_for_port: [Errno 113] No route to host
[DEBUG   ] Retrying connection to host 10.27.8.210 on port 445 (try 11)
[DEBUG   ] Caught exception in wait_for_port: [Errno 113] No route to host
[DEBUG   ] Retrying connection to host 10.27.8.210 on port 445 (try 12)
[ERROR   ] Unable to execute command                                                                                                        
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/salt/utils/cloud.py", line 1015, in wait_for_psexecsvc
    'cmd.exe', '/c hostname', host, username, password, port=port
  File "/usr/lib/python3.6/site-packages/salt/utils/cloud.py", line 962, in run_psexec_command
    client = Client(host, username, password, port=port, encrypt=False, service_name=service_name)
  File "/usr/lib/python3.6/site-packages/salt/utils/cloud.py", line 875, in __init__
    self._client = PsExecClient(server, username, password, port, encrypt)
NameError: name 'PsExecClient' is not defined
[DEBUG   ] Retrying psexec connection to host 10.27.8.210 on port 445 (try 1)
[ERROR   ] Unable to execute command
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/salt/utils/cloud.py", line 1015, in wait_for_psexecsvc
    'cmd.exe', '/c hostname', host, username, password, port=port
  File "/usr/lib/python3.6/site-packages/salt/utils/cloud.py", line 962, in run_psexec_command
    client = Client(host, username, password, port=port, encrypt=False, service_name=service_name)
  File "/usr/lib/python3.6/site-packages/salt/utils/cloud.py", line 875, in __init__
    self._client = PsExecClient(server, username, password, port, encrypt)
NameError: name 'PsExecClient' is not defined
[DEBUG   ] Retrying psexec connection to host 10.27.8.210 on port 445 (try 2)
[ERROR   ] Unable to execute command
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/salt/utils/cloud.py", line 1015, in wait_for_psexecsvc
    'cmd.exe', '/c hostname', host, username, password, port=port
  File "/usr/lib/python3.6/site-packages/salt/utils/cloud.py", line 962, in run_psexec_command
    client = Client(host, username, password, port=port, encrypt=False, service_name=service_name)
  File "/usr/lib/python3.6/site-packages/salt/utils/cloud.py", line 875, in __init__
    self._client = PsExecClient(server, username, password, port, encrypt)
NameError: name 'PsExecClient' is not defined
[DEBUG   ] Retrying psexec connection to host 10.27.8.210 on port 445 (try 3)
[ERROR   ] Unable to execute command
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/salt/utils/cloud.py", line 1015, in wait_for_psexecsvc
    'cmd.exe', '/c hostname', host, username, password, port=port
  File "/usr/lib/python3.6/site-packages/salt/utils/cloud.py", line 962, in run_psexec_command
    client = Client(host, username, password, port=port, encrypt=False, service_name=service_name)
  File "/usr/lib/python3.6/site-packages/salt/utils/cloud.py", line 875, in __init__
    self._client = PsExecClient(server, username, password, port, encrypt)
NameError: name 'PsExecClient' is not defined
[DEBUG   ] Retrying psexec connection to host 10.27.8.210 on port 445 (try 4)
[ERROR   ] Unable to execute command

I am following this documentation https://docs.saltstack.com/en/latest/topics/cloud/windows.html``

Bug Salt-Cloud v2019.2.2

Most helpful comment

@vg22, ok. That's very weird that the modules are the latest because in the salt.utils.cloud module, that PsExecClient class is supposed to be imported by the following code at the top of the file.

So essentially this first line that's being imported is responsible for it being declared.

try:
    from pypsexec.client import Client as PsExecClient
    from pypsexec.scmr import Service as ScmrService
    from pypsexec.exceptions import SCMRException
    from smbprotocol.tree import TreeConnect
    from smbprotocol.exceptions import SMBResponseException
    logging.getLogger('smbprotocol').setLevel(logging.WARNING)
    logging.getLogger('pypsexec').setLevel(logging.WARNING)
    HAS_PSEXEC = True
except ImportError:
    HAS_PSEXEC = False

Its usage is supposed to be guarded though by the following code that was listed in your backtrace. (This is just looking for winexe before calling Client which then triggering the exception you're encountering).

    if has_winexe() and not HAS_PSEXEC:
        ret_code = run_winexe_command(cmd, args, host, username, password, port)
        return None, None, ret_code
    ...
    client = Client(host, username, password, port=port, encrypt=False, service_name=service_name)

But yeah, that's the cause of the exception that's getting raised anyways. If from pypsexec.client import Client as PsExecClient is working in your Python3 instance, the only thing I can imagine it being is that salt-cloud is doing something crazy with the search module paths or something.

If that's the case, maybe a maintainer will know more.

All 8 comments

@vg22, can you output the versions of the pypsexec, and smbprotocol python modules? That error is likely happening because it's unable to import those.

On another note, I've personally had more success with the winrm and smbprotocol modules.

@arizvisa Here is the version of pypsexec and smbprotocol
FYI, I am trying to upgrade to salt to python3 as python2 is close to end of support

pip3 show smbprotocol
Name: smbprotocol
Version: 0.2.0
Summary: Interact with a server using the SMB 2/3 Protocol
Home-page: https://github.com/jborean93/smbprotocol
Author: Jordan Borean
Author-email: [email protected]
License: MIT
Location: /usr/local/lib/python3.6/site-packages
Requires: cryptography, ntlm-auth, six, pyasn1

```pip3 show pypsexec
Name: pypsexec
Version: 0.1.0
Summary: Run commands on a remote Windows host using SMB/RPC
Home-page: https://github.com/jborean93/pypsexec
Author: Jordan Borean
Author-email: [email protected]
License: MIT
Location: /usr/local/lib/python3.6/site-packages
Requires: six, smbprotocol

Also I was able to get it working with python2.7.

```Salt Version:
           Salt: 2019.2.2

Dependency Versions:
           cffi: 1.13.1
       cherrypy: unknown
       dateutil: Not Installed
      docker-py: Not Installed
          gitdb: 2.0.6
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.10.3
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 1.1.0
   msgpack-pure: Not Installed
 msgpack-python: 0.5.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.5 (default, Aug  7 2019, 00:51:29)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.3.0
           RAET: Not Installed
          smmap: 2.0.5
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4

System Versions:
           dist: centos 7.6.1810 Core
         locale: UTF-8
        machine: x86_64
        release: 3.10.0-957.5.1.el7.x86_64
         system: Linux
        version: CentOS Linux 7.6.1810 Core

``` pip show smbprotocol
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Name: smbprotocol
Version: 0.2.0
Summary: Interact with a server using the SMB 2/3 Protocol
Home-page: https://github.com/jborean93/smbprotocol
Author: Jordan Borean
Author-email: [email protected]
License: MIT
Location: /usr/lib/python2.7/site-packages
Requires: ntlm-auth, six, pyasn1, cryptography
Required-by: pypsexec

```pip show pypsexec
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Name: pypsexec
Version: 0.1.0
Summary: Run commands on a remote Windows host using SMB/RPC
Home-page: https://github.com/jborean93/pypsexec
Author: Jordan Borean
Author-email: [email protected]
License: MIT
Location: /usr/lib/python2.7/site-packages
Requires: six, smbprotocol
Required-by:

@vg22, ok. That's very weird that the modules are the latest because in the salt.utils.cloud module, that PsExecClient class is supposed to be imported by the following code at the top of the file.

So essentially this first line that's being imported is responsible for it being declared.

try:
    from pypsexec.client import Client as PsExecClient
    from pypsexec.scmr import Service as ScmrService
    from pypsexec.exceptions import SCMRException
    from smbprotocol.tree import TreeConnect
    from smbprotocol.exceptions import SMBResponseException
    logging.getLogger('smbprotocol').setLevel(logging.WARNING)
    logging.getLogger('pypsexec').setLevel(logging.WARNING)
    HAS_PSEXEC = True
except ImportError:
    HAS_PSEXEC = False

Its usage is supposed to be guarded though by the following code that was listed in your backtrace. (This is just looking for winexe before calling Client which then triggering the exception you're encountering).

    if has_winexe() and not HAS_PSEXEC:
        ret_code = run_winexe_command(cmd, args, host, username, password, port)
        return None, None, ret_code
    ...
    client = Client(host, username, password, port=port, encrypt=False, service_name=service_name)

But yeah, that's the cause of the exception that's getting raised anyways. If from pypsexec.client import Client as PsExecClient is working in your Python3 instance, the only thing I can imagine it being is that salt-cloud is doing something crazy with the search module paths or something.

If that's the case, maybe a maintainer will know more.

Hey @vg22 can you make sure you don't have impacket on your machine. We should be able to get a patch for this pretty soon.

Hey @xeacott I tried again after cleaning all previous installations on Windows 2016. It works now.
I dont have impacket installed as salt doesn't support impacket officially.

Salt Version:
           Salt: 2019.2.2

Dependency Versions:
           cffi: 1.13.2
       cherrypy: Not Installed
       dateutil: Not Installed
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.7.2
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.5.6
   mysql-python: Not Installed
      pycparser: 2.19
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.5 (default, Oct 30 2018, 23:45:53)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.3.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4

System Versions:
           dist: centos 7.6.1810 Core
         locale: UTF-8
        machine: x86_64
        release: 3.10.0-957.5.1.el7.x86_64
         system: Linux
        version: CentOS Linux 7.6.1810 Core

https://pip.pypa.io/en/latest/development/release-process/#python-2-support Name: pypsexec Version: 0.1.0 Summary: Run commands on a remote Windows host using SMB/RPC Home-page: https://github.com/jborean93/pypsexec Author: Jordan Borean Author-email: [email protected] License: MIT Location: /usr/lib/python2.7/site-packages Requires: six, smbprotocol Required-by:
pip show smbprotocol Name: smbprotocol Version: 0.2.0 Summary: Interact with a server using the SMB 2/3 Protocol Home-page: https://github.com/jborean93/smbprotocol Author: Jordan Borean Author-email: [email protected] License: MIT Location: /usr/lib/python2.7/site-packages Requires: ntlm-auth, six, pyasn1, cryptography Required-by: pypsexec

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

@vg22, if this problem was resolved. Can you close this issue?

Thank you for updating this issue. It is no longer marked as stale.

Was this page helpful?
0 / 5 - 0 ratings