voxpupuli / puppet-windowsfeature

Library that uses ServerAdministration api that comes with Windows Server 2008 and Windows Server 2012 to add / remove windows features
https://forge.puppet.com/puppet/windowsfeature
MIT License
30 stars 49 forks source link

Invalid XML being returned on Windows 2008 R2 for get-windowsfeature #86

Closed oraziobattaglia closed 7 years ago

oraziobattaglia commented 7 years ago

Affected Puppet, Ruby, OS and module versions/distributions

How to reproduce (e.g Puppet code you use)

windowsfeature { 'Backup-Features': ensure => present, installsubfeatures => true, }

OR

windowsfeature { 'Backup-Tools': ensure => present, }

What are you seeing

The error I receive is

Error: Failed to apply catalog: malformed XML: missing tag start Line: 4894 Position: 197033 Last 80 unconsumed characters: < /Property> 3 <Property Name="Depends O

I suppose the error is related just to the features shown. I also use the module to install the SNMP feature and the Telnet client feature without problems.

What behaviour did you expect instead

Output log

Debug: Prefetching default resources for windowsfeature Debug: Executing: 'C:\Windows\system32\WindowsPowershell\v1.0\powershell.exe Imp ort-Module ServerManager; Get-WindowsFeature | ConvertTo-XML -As String -Depth 4 -NoTypeInformation' Debug: Storing state Debug: Stored state in 0.31 seconds Error: Failed to apply catalog: malformed XML: missing tag start Line: 4894 Position: 197033 Last 80 unconsumed characters: < /Property> 3 <Property Name="Depends O Debug: Dynamically-bound server lookup failed, falling back to report_server set ting Debug: Dynamically-bound port lookup failed; falling back to report_port setting

Any additional information you'd like to impart

fabiosurrage commented 7 years ago

USING: Windows 2008 R2 Puppet 4.10 Puppet Server 2.1.2 (on CentOS 7) Ruby 2.1.9 (on Windows)

I and my job mate have the same problem and we change the ruby code default.rb to fix that issue:

Original Code:

# if win2008 import ServerManager module
    result = if win2008 == true
               ps('Import-Module ServerManager; Get-WindowsFeature | ConvertTo-XML -As String -Depth 4 -NoTypeInformation')
             else
               ps('Get-WindowsFeature | ConvertTo-XML -As String -Depth 4 -NoTypeInformation')
             end
    # create the XML document and parse the objects
xml = Document.new result

Changed code:


# if win2008 import ServerManager module
    result = if win2008 == true
               ps('Import-Module ServerManager; Get-WindowsFeature | ConvertTo-XML -As String -Depth 4 -NoTypeInformation > C:/ProgramData/PuppetLabs/puppet/cache/lib/puppet/provider/windowsfeature/result.xml')
             else
               ps('Get-WindowsFeature | ConvertTo-XML -As String -Depth 4 -NoTypeInformation > C:/ProgramData/PuppetLabs/puppet/cache/lib/puppet/provider/windowsfeature/result.xml')
             end
    file = File.new "C:/ProgramData/PuppetLabs/puppet/cache/lib/puppet/provider/windowsfeature/result.xml"
    # create the XML document and parse the objects
    xml = Document.new file

Ps.: We dont know much of ruby, but we think when powershell gives the result to the string, it makes something odd... Using file, we preserve the output xml; You can put the file result.xml in another place

jarretlavallee commented 7 years ago

This issue looks pretty easy to reproduce as the XML response from Get-WindowsFeature returns invalid XML from File Services object. The issue can be seen when installing any feature on Windows 2008R2 since the ConvertTo-XML does not return a valid XML document.

<Property Name="Value">&lt;!-- Copyright (c) Microsoft Corporation.  All rights reserved. --&gt;&lt;ViewerConfig&gt;&lt;QueryConfig&gt;&lt;QueryParams&gt;&lt;UserQuery /&gt;&lt;/QueryParams&gt;&lt;QueryNode&gt;&lt;Name ResourceId="%windir%\system32\svrmgrnc.dll,-412"&gt;File Server&lt;/Name&gt;&lt;Description ResourceId="%windir%\system32\svrmgrnc.dll,-413"&gt;System events for File Server&lt;/Description&gt;&lt;SuppressQueryExecutionErrors&gt;1&lt;/SuppressQueryExecutionErrors&gt;&lt;QueryList&gt;&lt;Query&gt;&lt;!-- FS Role optional components BEGIN --&gt;&lt;!-- FSRM events BEGIN --&gt;&lt;Select Path="System"&gt;*[System[Provider[@Name='DataScrn']]]&lt;/Select&gt;&lt;Select Path="System"&gt;*[System[Provider[@Name='Quota']]]&lt;/Select&gt;&lt;Select Path="Application"&gt;*[System[Provider[@Name='SrmSvc']]]&lt;/Select&gt;&lt;Select Path="Application"&gt;*[System[Provider[@Name='SrmReports']]]&lt;/Select&gt;&lt;!-- FSRM events END --&gt;&lt;!-- DFS Namespaces events BEGIN --&gt;&lt;Select Path="System"&gt;*[System[Provider[@Name='Microsoft-Windows-DfsSvc']]]&lt;/Select&gt;&lt;!-- DFS Namespaces events END  --&gt;&lt;!-- DFS Replication events BEGIN --&gt;&lt;Select Path="DFS Replication"&gt;*[System[Provider[@Name='DFS Replication']]]&lt;/Select&gt;&lt;Select Path="DFS Replication"&gt;*[System[Provider[@Name='DFSR']]]&lt;/Select&gt;&lt;!-- DFS Replication events END --&gt;&lt;!-- NTFRS events BEGIN --&gt;&lt;Select Path="File Replication Service"&gt;*[System[Provider[@Name='File Replication Service']]]&lt;/Select&gt;&lt;Select Path="File Replication Service"&gt;*[System[Provider[@Name='NtFrs']]]&lt;/Select&gt;&lt;!-- NTFRS events END --&gt;&lt;!-- NFS events BEGIN --&gt;&lt;Select Path="System"&gt;*[System[Provider[@Name='NfsSvr']]]&lt;/Select&gt;&lt;Select Path="System"&gt;*[System[Provider[@Name='Portmap']]]&lt;/Select&gt;&lt;Select Path="Application"&gt;*[System[Provider[@Name='NfsSvc']]]&lt;/Select&gt;&lt;!-- NFS events END --&gt;&lt;!-- SIS events BEGIN --&gt;&lt;Select Path="System"&gt;*[System[Provider[@Name='SIS']]]&lt;/Select&gt;&lt;Select Path="Application"&gt;*[System[Provider[@Name='Groveler']]]&lt;/Select&gt;&lt;!-- SIS events END --&gt;&lt;!-- Content Indexing events BEGIN --&gt;&lt;Select Path="Application"&gt;*[System[Provider[@Name='Ci']]]&lt;/Select&gt;&lt;!-- Content Indexing events END --&gt;&lt;!-- Windows Search events BEGIN --&gt;&lt;Select Path="Application"&gt;*[System[Provider[@Name='Microsoft-Windows-Search']]]&lt;/Select&gt;&lt;Select Path="Application"&gt;*[System[Provider[@Name='Microsoft-Windows-Search-ProfileNotify']]]&lt;/Select&gt;&lt;!-- Windows Search events END --&gt;&lt;!-- FS Role optional components END --&gt;&lt;!-- Core components important for FS Role BEGIN --&gt;&lt;!-- VDS, VolMgr events BEGIN --&gt;&lt;Select Path="System"&gt;*[System[Provider[@Name='partmgr']]]&lt;/Select&gt;&lt;Select Path="System"&gt;*[System[Provider[@Name='volmgr']]]&lt;/Select&gt;&lt;Select Path="System"&gt;*[System[Provider[@Name='Virtual Disk Service']]]&lt;/Select&gt;&lt;Select Path="System"&gt;*[System[Provider[@Name='VDS Basic Provider 1.0']]]&lt;/Select&gt;&lt;Select Path="System"&gt;*[System[Provider[@Name='VDS Dynamic Provider 2.0']]]&lt;/Select&gt;&lt;!-- VDS, VolMgr events END --&gt;&lt;!-- VSS, VolSnap events BEGIN --&gt;&lt;Select Path="System"&gt;*[System[Provider[@Name='Volsnap']]]&lt;/Select&gt;&lt;Select Path="Application"&gt;*[System[Provider[@Name='VSS']]]&lt;/Select&gt;&lt;!-- VSS, VolSnap events END --&gt;&lt;!-- NTFS, TxF, UDF, FAT, exFAT events BEGIN --&gt;&lt;Select Path="System"&gt;*[System[Provider[@Name='Ntfs']]]&lt;/Select&gt;&lt;!-- NTFS, TxF, UDF, FAT, exFAT events END --&gt;&lt;!-- SMB events BEGIN --&gt;&lt;Select Path="System"&gt;*[System[Provider[@Name='mrxsmb']]]&lt;/Select&gt;&lt;Select Path="System"&gt;*[System[Provider[@Name='Srv']]]&lt;/Select&gt;&lt;Select Path="System"&gt;*[System[Provider[@Name='Srv2']]]&lt;/Select&gt;&lt;Select Path="System"&gt;*[System[Provider[@Name='Workstation']]]&lt;/Select&gt;&lt;Select Path="System"&gt;*[System[Provider[@Name='Server']]]&lt;/Select&gt;&lt;!-- SMB events END --&gt;&lt;!-- Defrag events BEGIN --&gt;&lt;Select Path="Application"&gt;*[System[Provider[@Name='Microsoft-Windows-Defrag']]]&lt;/Select&gt;&lt;!-- Defrag events END --&gt;&lt;!-- CHKDSK events BEGIN --&gt;&lt;Select Path="Application"&gt;*[System[Provider[@Name='Chkdsk']]]&lt;/Select&gt;&lt;!-- CHKDSK events END --&gt;&lt;!-- Core components important for FS Role END --&gt;&lt;/Query&gt;&lt;/QueryList&gt;&lt;/QueryNode&gt;&lt;/QueryConfig&gt;&lt;/ViewerConfig&gt;</Property>

Since we are only using the name and if it is installed, we do not need to export the entirety of the objects to XML to parse it. A simple workaround is to just Select Name,Installed as a part of the Get-WindowsFeature to limit the unused input.