# Updates PackageManagement to the required version so the module won't try and talk to PSGallery --- - name: create the required folder for the nuget provider dll win_file: path: C:\Program Files\PackageManagement\ProviderAssemblies\nuget\2.8.5.208 state: directory - name: download nuget provider dll win_get_url: url: https://ansible-ci-files.s3.amazonaws.com/test/integration/targets/setup_win_psget/Microsoft.PackageManagement.NuGetProvider-2.8.5.208.dll dest: C:\Program Files\PackageManagement\ProviderAssemblies\nuget\2.8.5.208\Microsoft.PackageManagement.NuGetProvider.dll - name: get version and install location of PackageManagement and PowerShellGet win_shell: | $info = @{} $modules = Get-Module -ListAvailable | Where-Object { ($_.Name -eq "PackageManagement" -and $_.Version -lt "1.1.7") -or ` ($_.Name -eq "PowerShellGet" -and $_.Version -lt "1.6.0") } | ForEach-Object { $module_version = switch($_.Name) { PackageManagement { "1.1.7.0" } PowerShellGet { "1.6.0" } } $module_info = @{ install_path = ([System.IO.Path]::Combine([System.IO.Path]::GetDirectoryName($_.ModuleBase), $module_version)) } $info.($_.Name) = $module_info } ConvertTo-Json -InputObject $info -Compress changed_when: False register: installed_modules - name: register installed_modules info set_fact: installed_modules: '{{ installed_modules.stdout | trim | from_json }}' - name: update the PackageManagement and PowerShellGet versions when: installed_modules.keys() | list | length > 0 block: - name: download newer PackageManagement and PowerShellGet nupkg win_get_url: url: '{{ item.url }}' dest: '{{ remote_tmp_dir }}\{{ item.name }}.zip' # .zip is required for win_unzip when: item.name in installed_modules loop: - name: PackageManagement url: https://ansible-ci-files.s3.amazonaws.com/test/integration/targets/setup_win_psget/packagemanagement.1.1.7.nupkg - name: PowerShellGet url: https://ansible-ci-files.s3.amazonaws.com/test/integration/targets/setup_win_psget/powershellget.1.6.0.nupkg - name: extract new modules to correct location win_unzip: src: '{{ remote_tmp_dir }}\{{ item.name }}.zip' dest: '{{ item.path }}' when: item.path != "" loop: - name: PackageManagement path: '{{ installed_modules.PackageManagement.install_path | default("") }}' - name: PowerShellGet path: '{{ installed_modules.PowerShellGet.install_path | default("") }}'