Reputation: 29
I am using Ansible to install Visual Studio Build Tools 2022. I am trying to install specific workloads and using the documentation from Microsoft , ansible and choco but still not able to install the workloads I want with Ansible. I am new with Ansible so not sure what I am doing wrong.
My playbook run seems to complete with no issue, when I go to the server it is installing the visual studio installer is there but the workloads I need are not installed.
- name: Install VS Tools
win_chocolatey:
name: visualstudio2022buildtools
state: latest
version: 117.9.0.0
install_args:
"--passive --wait ----includeOptional --add Microsoft.VisualStudio.Workload.NodeBuildTools --add Microsoft.VisualStudio.Workload.WebBuildTools --add Microsoft.VisualStudio.Workload.DataBuildTools --add Microsoft.VisualStudio.Workload.MSBuildTools"
register: vs_output
output:
TASK [register for vs tools] ****************************************************************************
ok: [win_test] => {
"msg": " {'changed': False, 'rc': 0, 'choco_cli_version': '2.2.2',
'failed': False}"
}
Upvotes: 0
Views: 403
Reputation: 3378
An improved version of @PanzerRage's answer - I don't see it on the module documentation page, but usually for package management modules it's recommended to pass the list of packages directly to the name
instead of running the module in a loop due to performance reasons:
- name: Install Visual Studio Build Tools
win_chocolatey:
name: visualstudio2022buildtools
state: latest
version: "117.9.0.0"
- name: Install specific workloads
win_chocolatey:
name:
- visualstudio2022-workload-nodebuildtools
- visualstudio2022-workload-webbuildtools
- visualstudio2022-workload-databuildtools
state: latest
Upvotes: 0
Reputation: 29
Got it to work by installing the workloads individually:
- name: Install Visual Studio Build Tools
win_chocolatey:
name: visualstudio2022buildtools
state: latest
version: "117.9.0.0"
- name: Install specific workloads
win_chocolatey:
name: "{{ item }}"
state: latest
loop:
- visualstudio2022-workload-nodebuildtools
- visualstudio2022-workload-webbuildtools
- visualstudio2022-workload-databuildtools
Upvotes: -1
Reputation: 18981
NOTE: I haven't directly tried the following, but I am basing this on how I believe the Visual Studio packages work.
The combination of Visual Studio Chocolatey packages rely on the usage of Package Parameters, or rather the package_params
argument, rather than the Installation Arguemnts, or rather install_args
, argument in your Ansible script.
This can be seen in the example from taken from here:
choco install visualstudio2022buildtools --package-parameters "--allWorkloads --includeRecommended --includeOptional --passive --locale en-US"
As such, I think the correct way of doing this would be:
- name: Install VS Tools
win_chocolatey:
name: visualstudio2022buildtools
state: present
version: '117.9.0.0'
package_params:
"--includeOptional --add Microsoft.VisualStudio.Workload.NodeBuildTools --add Microsoft.VisualStudio.Workload.WebBuildTools --add Microsoft.VisualStudio.Workload.DataBuildTools --add Microsoft.VisualStudio.Workload.MSBuildTools"
register: vs_output
Also, based on this (taken from here):
The package passes --norestart --wait by default, and --quiet, unless --passive is specified in the package parameters.
You may want to re-think your usage of the --wait
and --passive
arguments that you were attempting to pass in.
Upvotes: 2