Ansible Chocolatey fails with 404 not found when using artifactory as a source

  ansible, artifactory, chocolatey, windows

I am using Ansible win_chocolatey module to setup packages to my remote servers and I am using custom source (artifactory here). In Artifactory I have a remote repository pointing to chocolatey.org. The repo type is nuget and i am using virtual to have this remote repo mapped to it.

I have tried using both virtual endpoint and remote repo endpoint however they both fail with error:

27-Jan-2021 17:27:22    +             $install_script = $client.DownloadString($script_url)
27-Jan-2021 17:27:22    +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27-Jan-2021 17:27:22        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
27-Jan-2021 17:27:22        + FullyQualifiedErrorId : WebException
27-Jan-2021 17:27:22    
27-Jan-2021 17:27:22    ScriptStackTrace:
27-Jan-2021 17:27:22    at Install-Chocolatey, <No file>: line 268
27-Jan-2021 17:27:22    at <ScriptBlock>, <No file>: line 675
27-Jan-2021 17:27:22    failed: [srv03598.xx.corp] (item={'name': 'chocolatey', 'version': '0.10.15'}) => {
27-Jan-2021 17:27:22        "ansible_loop_var": "item",
27-Jan-2021 17:27:22        "changed": false,
27-Jan-2021 17:27:22        "invocation": {
27-Jan-2021 17:27:22            "module_args": {
27-Jan-2021 17:27:22                "allow_empty_checksums": false,
27-Jan-2021 17:27:22                "allow_multiple": false,
27-Jan-2021 17:27:22                "allow_prerelease": false,
27-Jan-2021 17:27:22                "architecture": "default",
27-Jan-2021 17:27:22                "force": false,
27-Jan-2021 17:27:22                "ignore_checksums": false,
27-Jan-2021 17:27:22                "ignore_dependencies": false,
27-Jan-2021 17:27:22                "install_args": null,
27-Jan-2021 17:27:22                "name": [
27-Jan-2021 17:27:22                    "chocolatey"
27-Jan-2021 17:27:22                ],
27-Jan-2021 17:27:22                "package_params": null,
27-Jan-2021 17:27:22                "pinned": null,
27-Jan-2021 17:27:22                "proxy_password": null,
27-Jan-2021 17:27:22                "proxy_url": null,
27-Jan-2021 17:27:22                "proxy_username": null,
27-Jan-2021 17:27:22                "skip_scripts": false,
27-Jan-2021 17:27:22                "source": "https://url.com/artifactory/api/nuget/nuget-chocolatey",
27-Jan-2021 17:27:22                "source_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
27-Jan-2021 17:27:22                "source_username": "allreaders",
27-Jan-2021 17:27:22                "state": "present",
27-Jan-2021 17:27:22                "timeout": 2700,
27-Jan-2021 17:27:22                "validate_certs": true,
27-Jan-2021 17:27:22                "version": "0.10.15"
27-Jan-2021 17:27:22            }
27-Jan-2021 17:27:22        },
27-Jan-2021 17:27:22        "item": {
27-Jan-2021 17:27:22            "name": "chocolatey",
27-Jan-2021 17:27:22            "version": "0.10.15"
27-Jan-2021 17:27:22        },
27-Jan-2021 17:27:22        "msg": "Failed to download Chocolatey script from 'https://url.com/install.ps1'; Exception calling "DownloadString" with "1" argument(s): "The remote server returned an error: (404) Not Found."",
27-Jan-2021 17:27:22        "rc": 0
27-Jan-2021 17:27:22    }
27-Jan-2021 17:27:22    The full traceback is:
27-Jan-2021 17:27:22    Exception calling "DownloadString" with "1" argument(s): "The remote server returned an error: (404) Not Found."
27-Jan-2021 17:27:22    At line:268 char:13

These are the following sources I have tried:

https://url.com/artifactory/api/nuget/nuget-chocolatey
https://url.com/artifactory/api/nuget/v3/nuget-chocolatey
https://url.com/artifactory/api/nuget/nuget-public
https://url.com/artifactory/api/nuget/v3/nuget-public

And this is my code:

- name: Ansible Task for Installing packages via win_chocolatey
  win_chocolatey:
    name: "{{ item.name }}"
    version: "{{ item.version }}"
    state: present
    source: https://url.com/artifactory/api/nuget/nuget-chocolatey
    source_username: '{{ artifactory_user }}'
    source_password: '{{ artifactory_password }}'
  loop:
    - { name: 'chocolatey', version: 0.10.15 }
    - { name: 'openjdk8', version: 8.282.08 }
    - { name: 'openjdk11', version: 11.0.8.10 }
    - { name: 'python2', version: 2.7.14 }
  tags:
  - pkg-install

Could someone please help me here figuring out what is going wrong here?

Btw, I do have the packages cached in Artifactory because this did work for me once but not anymore and I am not sure why this is now failing.

Thanks in advance.

Source: Windows Questions

LEAVE A COMMENT