Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"The DISM PS module needs to be installed, this can be done through the windows-adk chocolately package" #557

Open
garyneville opened this issue Feb 13, 2024 · 1 comment

Comments

@garyneville
Copy link

SUMMARY

Getting the message "The DISM PS module needs to be installed, this can be done through the windows-adk chocolately package" even when the module has been installed - using Chocolatey.

ISSUE TYPE
  • Bug Report
COMPONENT NAME
ANSIBLE VERSION
2.16.3
COLLECTION VERSION
community.windows 2.1.0  

CONFIGURATION
ANSIBLE_HOME(env: ANSIBLE_HOME) = /home/ansibleadmin/ansible
CONFIG_FILE() = /etc/ansible/ansible.cfg
DEFAULT_FORKS(/etc/ansible/ansible.cfg) = 30
DEFAULT_LOG_PATH(/etc/ansible/ansible.cfg) = /home/ansibleadmin/ansible/logs/ansible.log
INVENTORY_ENABLED(/etc/ansible/ansible.cfg) = ['host_list', 'script', 'auto', 'yaml', 'ini', 'toml', 'vmware_vm_inventory']

OS / ENVIRONMENT
STEPS TO REPRODUCE

Other info - the suggested version of windows-adk is no longer available on Chocolatey (

- name: Install Windows ADK with DISM for Server 2008 R2
  chocolatey.chocolatey.win_chocolatey:
    name: windows-adk
    version: 8.100.26866.0
    state: present
    install_args: /features OptionId.DeploymentTools

So deleted the 'version' line and let it install the latest version.

This appears to be the problematic part of the module:

if (Get-Module -Name DISM -ListAvailable) {
    Import-Module -Name DISM
}
else {
    # Server 2008 R2 doesn't have the DISM module installed on the path, check the Windows ADK path
    $adk_root = [System.Environment]::ExpandEnvironmentVariables("%PROGRAMFILES(X86)%\Windows Kits\*\Assessment and Deployment Kit\Deployment Tools\amd64\DISM")
    if (Test-Path -LiteralPath $adk_root) {
        Import-Module -Name (Get-Item -LiteralPath $adk_root).FullName
    }
    else {
        Fail-Json $result "The DISM PS module needs to be installed, this can be done through the windows-adk chocolately package"
    }
}`

The path certainly does exist.

EXPECTED RESULTS

Expect to apply hotfix to my Windows Server 2008r2 server.

ACTUAL RESULTS

"The DISM PS module needs to be installed, this can be done through the windows-adk chocolately package"


@garyneville
Copy link
Author

I just want to add my own fix for this; I'm not an expert, and i'm sure it's not up to scratch as a proper fix, but it works for me.

if (Get-Module -Name DISM -ListAvailable) {
    Import-Module -Name DISM
}
else {
    # Correctly resolve the path to the Windows Kits directory, including handling the wildcard for version.
    $baseAdkPath = "${env:ProgramFiles(x86)}\Windows Kits"
    $adkVersionPaths = Get-ChildItem -Path $baseAdkPath -Directory | Where-Object { $_.Name -match '^\d+' } | Select-Object -ExpandProperty FullName

    $moduleImported = $false
    foreach ($versionPath in $adkVersionPaths) {
        $adkDismPath = "$versionPath\Assessment and Deployment Kit\Deployment Tools\amd64\DISM"
        $dismModulePath = Join-Path -Path $adkDismPath -ChildPath "DISM.psd1"
        
        if (Test-Path $dismModulePath) {
            Import-Module -Name $dismModulePath -ErrorAction SilentlyContinue
            if ($?) {
                $moduleImported = $true
                break
            }
        }
    }

    if (-not $moduleImported) {
        Fail-Json $result "The DISM PS module needs to be installed, this can be done through the windows-adk chocolately package"
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant