chocolatey / chocolatey-ansible

The Chocolatey module collection for Ansible
GNU General Public License v3.0
47 stars 29 forks source link

Package parameters not taken into account #146

Closed mathstuf closed 2 weeks ago

mathstuf commented 3 months ago

Checklist

What You Are Seeing?

I have a set of Ansible rules that build up a string for package_params. If this changes, the package is not prodded to analyze the parameters again. For example, I build up the set of --add flags for visualstudio2022community. If I deploy once with one set of --add flags, further deployments with additional --add flags do not end up adding those components to the existing installation.

What is Expected?

Package parameters changing cause the new state to be realized.

How Did You Get This To Happen?

---
- name: 'Prepare key Visual Studio variable'
  ansible.builtin.set_fact:
    vs_year: '{{ item | replace("vs", "") }}'

- name: 'Prepare architecture variable (Intel)'
  ansible.builtin.set_fact:
    vs_arch: 'x86.x64'
  when: 'ansible_machine == "x86_64"'

- name: 'Prepare architecture variable (Intel)'
  ansible.builtin.set_fact:
    vs_arch: 'ARM64'
  when: 'ansible_machine == "arm64"'

- name: 'Build Visual Studio C++ component arguments'
  ansible.builtin.set_fact:
    vs_args: >-
      {{ vs_args | default("") }}
      --add Microsoft.VisualStudio.Component.VC.{{ toolchain }}.{{ vs_arch | mandatory }}
      --add Microsoft.VisualStudio.Component.VC.{{ toolchain }}.CLI.Support
      --add Microsoft.VisualStudio.Component.VC.{{ toolchain }}.MFC
  loop: '{{ software[item].cpp }}'
  loop_control:
    loop_var: 'toolchain'

- name: 'Build Visual Studio Windows SDK'
  ansible.builtin.set_fact:
    vs_args: >-
      {{ vs_args | default("") }}
      --add Microsoft.VisualStudio.Component.Windows11SDK.22621
      --add Microsoft.VisualStudio.Component.VC.Tools.{{ vs_arch | mandatory }}
      --add Microsoft.VisualStudio.Component.VC.CLI.Support
      --add Microsoft.VisualStudio.Component.VC.ATLMFC
  when: 'software[item].cpp is defined'

- name: 'Install Visual Studio {{ vs_year }}'
  chocolatey.chocolatey.win_chocolatey:
    name: 'visualstudio{{ vs_year }}community'
    package_params: '{{ vs_args | mandatory }}'
    state: latest

System Details

Installed Packages

Chocolatey v2.2.2
chocolatey 2.2.2
chocolatey-compatibility.extension 1.0.0
chocolatey-core.extension 1.4.0
chocolatey-dotnetfx.extension 1.0.1     
chocolatey-visualstudio.extension 1.11.1
dotnetfx 4.8.0.20220524
git 2.44.0
git.install 2.44.0
KB2919355 1.0.20160915
KB2919442 1.0.20160915
visualstudio2022community 117.9.5
visualstudio-installer 2.0.3     
12 packages installed.

Output Log

https://gist.github.com/mathstuf/9649614a99964e3057449e79f3e3a20b

Additional Context

No response

mathstuf commented 3 months ago

Even using force: true doesn't help; the existing components are the only ones installed.

mathstuf commented 3 months ago

state: reinstalled fails because the parameters are passed to the uninstaller and not understood.

mathstuf commented 3 months ago

Is there some mechanism by which the package could get some handle on the request to do its own syncup action? For example:

vexx32 commented 2 weeks ago

So... a couple things:

  1. Yes, force: true would be required, otherwise choco itself won't do the reinstallation. As far as I know, choco doesn't consider changed parameters to be sufficient for a reinstallation on their own.
  2. The exact behaviour of this would depend on how the package and the underlying software is written. There should be a way to handle this in the package, but you would need to contact the package maintainer if the existing package for this does not handle this use case, or roll your own package to handle this for your use case.

I don't think this is something we can handle in this collection, though, so I'm going to close out this issue for now.

mathstuf commented 2 weeks ago

Thanks. I think we came to the conclusion that using choco to install VS (component-less) but a specific VS Installer-aware action to manage its components is a better solution.