ansible-collections / ansible.windows

Windows core collection for Ansible
https://galaxy.ansible.com/ansible/windows
GNU General Public License v3.0
245 stars 167 forks source link

RFE: Support for managing Windows Capabilities #660

Open myllynen opened 2 weeks ago

myllynen commented 2 weeks ago
SUMMARY

Recent Windows Server versions allow for adding, querying, and removing Windows capabilities which are separate from features, optional features, and packages. For example, to check the installation status of OpenSSH SSH Server (sshd) on Windows Server 2022 and install it if not installed already one could do:

if (Get-WindowsCapability -Name OpenSSH.Server -Online | ? State -ne 'Installed') {
  Add-WindowsCapability -Name OpenSSH.Server -Online
}

It would be helpful if there would be an Ansible Windows module available to do this without the need for writing PowerShell.

ISSUE TYPE
COMPONENT NAME

win_capability

ADDITIONAL INFORMATION

The Add-WindowsCapability, Get-WindowsCapability, and Remove-WindowsCapability PowerShell cmdlets seem to use Dism.exe. While the aforementioned example works as expected on Windows Server 2022 it doesn't seem to do anything on Windows 10. Also, when trying to install other capabilities such as languages the results seem inconsistent, I haven't been able to handle them reliably even if similar language enablement using Settings works as expected. Meaning that if creating this kind of module it should verify the outcome to the extent possible.

- name: Install OpenSSH SSH server (sshd)
  ansible.windows.win_capability:
    name: OpenSSH.Server
    state: present
  register: install_status

- name: Remove Azure Arc client setup
  ansible.windows.win_capability:
    name: AzureArcSetup
    state: absent
  register: remove_status

- name: Check available Windows Capabilities
  ansible.windows.win_capability:
    state: available
  register: available_capabilities

- name: Check already installed Windows Capabilities
  ansible.windows.win_capability:
    state: installed
  register: installed_capabilities
myllynen commented 9 hours ago

For reference, here are the most relevant documents available online, the DISM commands and PowerShell cmdlets use the term capability but the documents talk about Features on Demand (FODs):

https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/features-on-demand-v2--capabilities?view=windows-11 https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/features-on-demand-language-fod?view=windows-11 https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/features-on-demand-non-language-fod?view=windows-11

I think the issue I mentioned earlier about inconsistent results was probably due to a typo somewhere. For example, trying to install 'OpenSSH-Server~~0.0.1.0' doesn't really do anything but does not give a clear error either as some might except due to using wrong name, it should be 'OpenSSH.Server0.0.1.0' not 'OpenSSH-Server~~0.0.1.0'. Thanks.