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 50 forks source link

2008R2 all windowsfeature resources showing as absent. #76

Closed btoohey closed 7 years ago

btoohey commented 7 years ago

Affected Puppet, Ruby, OS and module versions/distributions

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

windowsfeature { 'SNMP-Service' :
    ensure => present,
  }
  windowsfeature { 'SNMP-WMI-Provider' :
    ensure => present,
  }
  windowsfeature { 'Telnet-Client' :
    ensure => present,
  } 

What are you seeing

PS C:\Users\Administrator> puppet resource windowsfeature --debug --verbose --trace
Debug: Executing 'C:\Windows\sysnative\WindowsPowershell\v1.0\powershell.exe Get-WindowsFeature | ConvertTo-JSON'
windowsfeature { 'ad-certificate':
  ensure => 'absent',
}
windowsfeature { 'ad-domain-services':
  ensure => 'absent',
}
windowsfeature { 'ad-federation-services':
  ensure => 'absent',
}
windowsfeature { 'adcs-cert-authority':
  ensure => 'absent',
}
windowsfeature { 'adcs-device-enrollment':
  ensure => 'absent',
}
windowsfeature { 'adcs-enroll-web-pol':
  ensure => 'absent',
}

...

}
windowsfeature { 'wireless-networking':
  ensure => 'absent',
}
windowsfeature { 'wsrm':
  ensure => 'absent',
}
windowsfeature { 'xps-viewer':
  ensure => 'absent',
}

Output is truncated but each windowsfeature shows as absent. Specifically setting the following in puppet code:

 windowsfeature { 'SNMP-Service' :
    ensure => present,
  }
  windowsfeature { 'SNMP-WMI-Provider' :
    ensure => present,
  }
  windowsfeature { 'Telnet-Client' :
    ensure => present,
  }

But after a puppet run, the resources still show as absent even though they are turned on:

windowsfeature { 'telnet-client':
  ensure => 'absent',
}
windowsfeature { 'snmp-services':
  ensure => 'absent',
}
windowsfeature { 'snmp-wmi-provider':
  ensure => 'absent',
}

What behaviour did you expect instead

Expected windowsfeature to turn on the features on a server's first puppet run and for Get-WindowsFeature | ConvertTo-JSON to show the features as turned on.

Output log

Pertinent puppet agent -t --debug output:

Debug: Prefetching default resources for windowsfeature
Debug: Executing 'C:\Windows\sysnative\WindowsPowershell\v1.0\powershell.exe Get-WindowsFeature | ConvertTo-JSON'
Debug: Executing 'C:\Windows\sysnative\WindowsPowershell\v1.0\powershell.exe Import-Module ServerManager; Add-WindowsFeature Telnet-Client'
Notice: /Stage[main]/Win_snmp/Windowsfeature[Telnet-Client]/ensure: created
Debug: /Stage[main]/Win_snmp/Windowsfeature[Telnet-Client]: The container Class[Win_snmp] will propagate my refresh event
Debug: Executing 'C:\Windows\sysnative\WindowsPowershell\v1.0\powershell.exe Import-Module ServerManager; Add-WindowsFeature SNMP-WMI-Provider'
Notice: /Stage[main]/Win_snmp/Windowsfeature[SNMP-WMI-Provider]/ensure: created
Debug: /Stage[main]/Win_snmp/Windowsfeature[SNMP-WMI-Provider]: The container Class[Win_snmp] will propagate my refresh event
Debug: Executing 'C:\Windows\sysnative\WindowsPowershell\v1.0\powershell.exe Import-Module ServerManager; Add-WindowsFeature SNMP-Service'
Notice: /Stage[main]/Win_snmp/Windowsfeature[SNMP-Service]/ensure: created
Debug: /Stage[main]/Win_snmp/Windowsfeature[SNMP-Service]: The container Class[Win_snmp] will propagate my refresh event
Debug: Class[Win_snmp]: The container Stage[main] will propagate my refresh event

Any additional information you'd like to impart

p-mcote commented 7 years ago

After investigation on my end I found that Win 2008 R2 does not output an "InstallState" value when running the get-windowsfeature cmdlet. A quick fix would be to validate "Installed" value instead. This is in fact already in place in the code I found on the project's GitHub URL (See code attached) while cloning the repository.

The 'default.rb' file has been edited to check "Installed" value into JSON file instead of "InstallState".

If the version currently available into project repository could be officially published it would fix the issue described above.

puppet-windowsfeature.zip

TraGicCode commented 7 years ago

Verifying this now.

TraGicCode commented 7 years ago

Seems to work fine for me unless. Closing this issue @p-mcote

image