ansible-collections / community.windows

Windows community collection for Ansible
https://galaxy.ansible.com/community/windows
GNU General Public License v3.0
199 stars 153 forks source link

Unable to Install 'VirtualMachinePlatform' Feature on Windows Server 2022 using win_feature Module #573

Closed tigitz closed 1 month ago

tigitz commented 1 month ago
SUMMARY

The task to enable the VirtualMachinePlatform feature on a Windows system fails with the error message: "The role, role service, or feature name is not valid: 'VirtualMachinePlatform'. The name was not found." However, running the Get-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform command shows that the feature is available and enabled on the system.

ISSUE TYPE
COMPONENT NAME

win_feature

ANSIBLE VERSION
ansible-playbook 2.9.27
  config file = /ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.10/site-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 3.10.14 (main, Mar 23 2024, 07:28:47) [GCC 12.2.1 20220924]
COLLECTION VERSION
amazon.aws                              8.1.0  
ansible.windows                         2.4.0  
bec.shell                               1.1.2  
chocolatey.chocolatey                   1.5.1  
community.aws                           8.0.0  
community.docker                        3.4.8  
community.general                       9.2.0  
community.mysql                         3.9.0  
community.windows                       2.2.0  
openstack.cloud                         2.2.0  
CONFIGURATION
ANSIBLE_SSH_ARGS(/ansible/ansible.cfg) = -C -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=/dev/shm/cp%h-%p-%r
DEFAULT_CALLBACK_WHITELIST(/ansible/ansible.cfg) = ['timer', 'profile_tasks']
DEFAULT_HOST_LIST(/ansible/hosts) = ['/ansible/hosts']
DEFAULT_LOAD_CALLBACK_PLUGINS(/ansible/ansible.cfg) = True
DEFAULT_STDOUT_CALLBACK(/ansible/ansible.cfg) = yaml
HOST_KEY_CHECKING(/ansible/ansible.cfg) = False
OS / ENVIRONMENT
STEPS TO REPRODUCE
- name: Enable features for WSL
  win_feature:
    name: "{{ item }}"
    state: present
  loop:
    - Microsoft-Windows-Subsystem-Linux
    - VirtualMachinePlatform
EXPECTED RESULTS

The VirtualMachinePlatform feature should be installed without errors.

ACTUAL RESULTS

The task to install the VirtualMachinePlatform feature fails with the message:

failed: [xxxxxxx] (item=VirtualMachinePlatform) => changed=false 
  ansible_loop_var: item
  item: VirtualMachinePlatform
  msg: 'Failed to install Windows Feature: ArgumentNotValid: The role, role service, or feature name is not valid: ''VirtualMachinePlatform''. The name was not found.'

However, running the following PowerShell command shows that the feature is available and enabled:

Get-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform

FeatureName      : VirtualMachinePlatform
DisplayName      : Virtual Machine Platform
Description      : Enables platform support for virtual machines
RestartRequired  : Possible
State            : Enabled
CustomProperties :
tigitz commented 1 month ago

Sorry, just noticed the win_optional_feature module:

- name: Enable "VirtualMachinePlatform" features for WSL
  win_optional_feature:
    name: VirtualMachinePlatform
    state: present