salt icon indicating copy to clipboard operation
salt copied to clipboard

Module win_service.create on Windows 2012 R2 fails

Open PabloLemos opened this issue 9 years ago • 5 comments

Description of Issue/Question

I use elasticsearch to receive the logs of all our machines (linux and windows). In windows I use winlogbeat to send the logs. To deploy the winlogbeat package, I created a spm repository and a state to configure the software.

The last version os salt (2016.11.3) the function of service.create is quite different from the last version of salt I had used in windows (2016.3.3) and give me a stranger error.

      ID: Create_Service
Function: module.run
    Name: service.create
  Result: False
 Comment: Module function service.create threw an exception. Exception: None is not a valid string in this context
 Started: 07:16:22.677000
Duration: 16.0 ms
 Changes:

Setup

This is the winlogbeat deploy state:

winlogbeat:
    pkg.latest

Create_Service:
    module.run:
        - name: service.create
        - m_name: winlogbeat
        - bin_path: C:\\Admin\\winlogbeat\\winlogbeat.exe
        - start_type: auto
        - load_order_group: Admins
        - watch:
          - pkg: winlogbeat

Start_Service:
    service:
        - running
        - name: winlogbeat
        - enable: True
        - restart: True
        - watch:
          -  module: Create_Service

Steps to Reproduce Issue

salt 'vmachine.localhost' state.apply deploy.win.winlogbeat

vmachine.localhost:

      ID: winlogbeat
Function: pkg.latest
  Result: True
 Comment: The following packages were successfully installed/upgraded: winlogbeat
 Started: 07:24:50.616000
Duration: 1515.0 ms
 Changes:
          ----------
          winlogbeat:
              ----------
              install status:
                  success

      ID: Create_Service
Function: module.run
    Name: service.create
  Result: False
 Comment: Module function service.create threw an exception. Exception: None is not a valid string in this context
 Started: 07:24:52.147000
Duration: 0.0 ms
 Changes:

      ID: Start_Service
Function: service.running
    Name: winlogbeat
  Result: False
 Comment: One or more requisite failed: deploy.win.winlogbeat.Create_Service
 Changes:

Summary for vmachine.localhost

Succeeded: 1 (changed=1) Failed: 2

Total states run: 3 Total run time: 1.515 s

Debug information:

Passed invalid arguments: None is not a valid string in this context. Traceback (most recent call last): File "C:\salt\bin\lib\site-packages\salt\cli\caller.py", line 197, in call ret['return'] = func(*args, **kwargs) File "C:\salt\bin\lib\site-packages\salt\modules\win_service.py", line 1104, i n create account_password) TypeError: None is not a valid string in this context

The Winlogbeat service runs under a LocalSystem account for that i not specify account_name and account_password.

Versions Report

minion

` C:\salt>salt-call.bat --versions Salt Version: Salt: 2016.11.3

Dependency Versions: cffi: 1.7.0 cherrypy: 7.1.0 dateutil: 2.5.3 gitdb: 0.6.4 gitpython: 2.0.8 ioflo: 1.5.5 Jinja2: 2.9.4 libgit2: Not Installed libnacl: 1.4.5 M2Crypto: Not Installed Mako: 1.0.4 msgpack-pure: Not Installed msgpack-python: 0.4.8 mysql-python: Not Installed pycparser: 2.14 pycrypto: 2.6.1 pygit2: Not Installed Python: 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.150 0 64 bit (AMD64)] python-gnupg: 0.3.8 PyYAML: 3.11 PyZMQ: 16.0.1 RAET: Not Installed smmap: 0.9.0 timelib: 0.2.4 Tornado: 4.4.1 ZMQ: 4.1.6

System Versions: dist: machine: AMD64 release: 2012ServerR2 system: Windows version: 2012ServerR2 6.3.9600 Multiprocessor Free `

master

` ~> salt --versions-report Salt Version: Salt: 2016.11.3

Dependency Versions: cffi: Not Installed cherrypy: 3.2.2 dateutil: 1.4.1 gitdb: 0.5.4 gitpython: 0.3.2 RC1 ioflo: Not Installed Jinja2: 2.8.1 libgit2: Not Installed libnacl: Not Installed M2Crypto: 0.20.2 Mako: Not Installed msgpack-pure: Not Installed msgpack-python: 0.4.6 mysql-python: 1.2.5 pycparser: Not Installed pycrypto: 2.6.1 pygit2: Not Installed Python: 2.6.6 (r266:84292, Aug 19 2016, 02:44:53) python-gnupg: Not Installed PyYAML: 3.11 PyZMQ: 14.5.0 RAET: Not Installed smmap: 0.8.1 timelib: Not Installed Tornado: 4.3 ZMQ: 4.0.5

System Versions: dist: centos 6.8 Santiago machine: x86_64 release: 2.6.32-642.15.1.el6.x86_64 system: Linux version: Red Hat Enterprise Linux Server 6.8 Santiago `

PabloLemos avatar Mar 25 '17 06:03 PabloLemos

It looks like there were a lot of changes that went into win_service in 2016.11.

@twangboy it looks like you were working on changes to this module in https://github.com/saltstack/salt/commit/280d10af01c

Can you take a look at this bug report?

Thanks, Daniel

gtmanfred avatar Mar 27 '17 16:03 gtmanfred

@PabloLemos @gtmanfred The problem is that the display_name is a required parameter in the CreateService API function. I have submitted the above PR to address this issue where if display_name is not passed, then name will be used. To work around this issue until the next release, please define display_name in your state file.

twangboy avatar Mar 27 '17 17:03 twangboy

awesome, thanks @twangboy !!

gtmanfred avatar Mar 27 '17 17:03 gtmanfred

Marked as done and #40341 is merged. Closing this.

cachedout avatar Mar 27 '17 21:03 cachedout

Verificated. Its all correct!!

salt amachine.localhost state.apply deploy.win.winlogbeat vmachine.localhost:

      ID: winlogbeat
Function: pkg.latest
  Result: True
 Comment: The following packages were successfully installed/upgraded: winlogbeat
 Started: 06:20:29.700000
Duration: 2281.0 ms
 Changes:
          ----------
          winlogbeat:
              ----------
              install status:
                  success

      ID: Create_Service
Function: module.run
    Name: service.create
  Result: True
 Comment: Module function service.create executed
 Started: 06:20:31.981000
Duration: 4797.0 ms
 Changes:
          ----------
          ret:
              ----------
              BinaryPath:
                  C:\Admin\winlogbeat\winlogbeat.exe
              ControlsAccepted:
                  0
              Dependencies:
              Description:
                  None
              DisplayName:
                  winlogbeat
              ErrorControl:
                  Normal
              LoadOrderGroup:
                  Admins
              ServiceAccount:
                  LocalSystem
              ServiceType:
                  - Win32 Own Process
              StartType:
                  Auto
              StartTypeDelayed:
                  False
              Status:
                  Stopped
              Status_CheckPoint:
                  0
              Status_ExitCode:
                  1077
              Status_ServiceCode:
                  0
              Status_WaitHint:
                  0
              TagID:
                  0
              sid:
                  S-1-5-80-2105036658-982597227-136175363-611792960-2434065878

      ID: Start_Service
Function: service.running
    Name: winlogbeat
  Result: True
 Comment: Service winlogbeat is already enabled, and is running
 Started: 06:20:36.794000
Duration: 1848.0 ms
 Changes:
          ----------
          winlogbeat:
              True

Summary for vmachine.localhost

Succeeded: 3 (changed=3) Failed: 0

Total states run: 3 Total run time: 8.926 s `

Thanks a lot

PabloLemos avatar Mar 28 '17 04:03 PabloLemos