chocolatey / chocolatey-ansible

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

(#120) Fail win_chocolatey if dependency not met #125

Closed Windos closed 1 year ago

Windos commented 1 year ago

Description Of Changes

This PR tests to see what version of Chocolatey CLI is being installed and will fail the task if the version being installed has an unmet dependency.

Motivation and Context

With the release of Chocolatey CLI 2.0.0, there is now a dependency on having .NET Framework 4.8 installed. The win_chocolatey module installs the latest version of Chocolatey CLI by default and in the currently released version of the collection it is the Chocolatey install itself that fails with a complaint about .NET Framework not being present.

This change performs the dependency check on the "Ansible" side of things, giving more control of the task failure and the message returned to the end user.

Testing

I have built and tested this change locally against a Windows Server 2016 VM.

When no version is specified, and .NET Framework 4.8 isn't installed, the task fails as expected.

Expected failure when dependency not met

When a version (e.g. 1.4) is specified, it installs as the dependency does not apply.

Specifying a 1.x version installs

When .NET Framework 4.8 is already installed, Chocolatey CLI 2.0.0 can be installed.

installing 2.x works with the dependency in place

Note that the pipeline testing won't test this as the VM used for that is a Windows 10 version that has .NET Framework 4.8 already installed. If we wanted to include testing for this we would need to spin up an older VM to test against in addition.

Operating Systems Testing

Change Types Made

Change Checklist

Related Issue

Fixes #120

pauby commented 1 year ago

Note that the pipeline testing won't test this as the VM used for that is a Windows 10 version that has .NET Framework 4.8 already installed. If we wanted to include testing for this we would need to spin up an older VM to test against in addition.

Can we spin up that older VM and make sure we're testing it.

Windos commented 1 year ago

Note that the pipeline testing won't test this as the VM used for that is a Windows 10 version that has .NET Framework 4.8 already installed. If we wanted to include testing for this we would need to spin up an older VM to test against in addition.

Can we spin up that older VM and make sure we're testing it.

@pauby will do, will mark this as draft until that is added.

Windos commented 1 year ago

This now has tests and docs and is ready for review, though I'm still watching the Azure pipeline.

Windos commented 1 year ago

@vexx32

I'm wondering if we can construct this pipeline such that both VMs are created and destroyed in parallel, rather than separately.

I was wondering about this too and ummed and arred around it for a while. My biggest concern was I wasn't sure off hand if I'd end up with the Windows Server VM running for ~2 hours when the test being run on it only takes ~10 minutes. Ended up going the "easier" route to minimize the amount of time that VM was running and incurring costs.

Maybe we add an issue to come back to to optimize the pipeline? We could go as far as spinning up a handful of Windows 10 VMs and running each of the Ansible version tests in parallel too... would take the entire runtime down to 30-40 minutes but is a bit of re-work to the pipeline.

vexx32 commented 1 year ago

Yeah that's probably a good idea for us to do in future at least. Agreed.