saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:
https://repo.saltproject.io/
Apache License 2.0
14.1k stars 5.47k forks source link

LGPO does not work on Python 3 #44165

Closed twangboy closed 6 years ago

twangboy commented 6 years ago

Description of Issue/Question

Applying Group Policy using the LGPO state module works fine on Py2 and fails on Py3 with an error similar to the following:

An exception occurred in this state: Traceback (most recent call last):
    File "c:\salt\bin\lib\site-packages\salt\state.py", line 1843, in call
      **cdata['kwargs'])
    File "c:\salt\bin\lib\site-packages\salt\loader.py", line 1795, in wrapper
      return f(*args, **kwargs)
    File "c:\salt\bin\lib\site-packages\salt\states\win_lgpo.py", line 301, in set_
      adml_language=adml_language)
    File "c:\salt\bin\lib\site-packages\salt\modules\win_lgpo.py", line 5444, in set_
      raise CommandExecutionError(msg)
    salt.exceptions.CommandExecutionError: Error while attempting to write Administrative Template Policy data.  Some changes may not be applied as expected

Setup

Create a state file as follows (for 2012r2):

configure_windows_update:
  lgpo.set:
    - computer_policy:
        Configure Automatic Updates:
          Configure automatic updating: 4 - Auto download and schedule the install
          Install during automatic maintenance: False
          Scheduled install day: 7 - Every Saturday
          Scheduled install time: '17:00'
          Install updates for other Microsoft products: True
        Turn on recommended updates via Automatic Updates: Enabled

Install Python 3 version of Salt 2017.7.2 Copy the patched win_lgpo.py from 2017.7 to c:\salt\bin\Lib\site-packages\salt\modules\

Steps to Reproduce Issue

Apply the above state: It will fail with the above stacktrace

Versions Report

2017.7.2 with patched win_lgpo.py

twangboy commented 6 years ago

@lomeroe ^^^

lomeroe commented 6 years ago

that section of code calls an os.path.join and then a salt file.file_exists -- I don't see any bugs filed for file.file_exists, but it seems the problem would like in one of those 2 calls.

I will take a deeper look

lomeroe commented 6 years ago

I took a fresh 2012R2 server with http://repo.saltstack.com/windows/Salt-Minion-2017.7.2-Py3-AMD64-Setup.exe installed and the state applied as expected.

I don't see "HealthService.admx or adml" on this system. What OS? Is there actually a HealthService.adml in the en-US folder?

rickh563 commented 6 years ago

ZD-1893

twangboy commented 6 years ago

The HealthService.admx and .adml gets installed with the System Center Operations Manager (SCOM) Agent. I had to install that to replicate this issue... Or I pasted the wrong stacktrace... let me check...

twangboy commented 6 years ago

OK, you have to patch the win_lgpo.py file in C:\salt\bin\Lib\site-packages\salt\modules with the one from the head of 2017.7... That's the one we fixed to handle the SCOM issue... then you get the real problem with Py3 support. I updated the StackTrace above... I wish I could attach the patched win_lgpo.py file...

https://github.com/saltstack/salt/blob/2017.7/salt/modules/win_lgpo.py

twangboy commented 6 years ago

I had to use a different state file as well... updated above... Sorry for all the changes...