From d45b59903604564766ab21e00adfd55be3db991a Mon Sep 17 00:00:00 2001 From: Shane Lee Date: Mon, 9 May 2016 10:45:11 -0600 Subject: [PATCH] Fix 33058 (#33099) * Fix servermanager module - Added check for 2008 version of windows - Added Import-Module ServerManager to _pshell_json. Apparently this needs to run each time we issue a servermanager command. * Fix list_available --- salt/modules/win_servermanager.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/salt/modules/win_servermanager.py b/salt/modules/win_servermanager.py index b201b34bf9..a491825b74 100644 --- a/salt/modules/win_servermanager.py +++ b/salt/modules/win_servermanager.py @@ -25,12 +25,17 @@ def __virtual__(): Load only on windows with servermanager module ''' if not salt.utils.is_windows(): - return False, 'Failed to load win_servermanager module:\n' \ + return False, 'Failed to load win_servermanager module: ' \ 'Only available on Windows systems.' + if salt.utils.version_cmp(__grains__['osversion'], '6.1.7600') == -1: + return False, 'Failed to load win_servermanager module: ' \ + 'Requires Remote Server Administration Tools which ' \ + 'is only available on Windows 2008 R2 and later.' + if not _check_server_manager(): - return False, 'Failed to load win_servermanager module:\n' \ - 'ServerManager module not available.\n' \ + return False, 'Failed to load win_servermanager module: ' \ + 'ServerManager module not available. ' \ 'May need to install Remote Server Administration Tools.' return __virtualname__ @@ -52,8 +57,9 @@ def _pshell_json(cmd, cwd=None): Execute the desired powershell command and ensure that it returns data in json format and load that into python ''' + cmd = 'Import-Module ServerManager; {0}'.format(cmd) if 'convertto-json' not in cmd.lower(): - cmd = ' '.join([cmd, '| ConvertTo-Json']) + cmd = '{0} | ConvertTo-Json'.format(cmd) log.debug('PowerShell: {0}'.format(cmd)) ret = __salt__['cmd.shell'](cmd, shell='powershell', cwd=cwd) try: @@ -76,7 +82,8 @@ def list_available(): salt '*' win_servermanager.list_available ''' - cmd = 'Get-WindowsFeature -erroraction silentlycontinue ' \ + cmd = 'Import-Module ServerManager; ' \ + 'Get-WindowsFeature -erroraction silentlycontinue ' \ '-warningaction silentlycontinue' return __salt__['cmd.shell'](cmd, shell='powershell')