chocolatey / chocolatey-ansible

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

Add a mode that lets us set the version and will upgrade or downgrade without forcing the installation #143

Open rgl opened 6 months ago

rgl commented 6 months ago

Checklist

Is Your Feature Request Related To A Problem? Please describe.

I want to use Ansible to set the desirable state of specific package version. And have this module install, upgrade or downgrade iif the installed version is not the one I set. I do not want to use force: true because that would unnecessary reinstall the package every time.

Describe The Solution. Why is it needed?

- name: Install Inkscape
  chocolatey.chocolatey.win_chocolatey:
    # https://community.chocolatey.org/packages/inkscape
    name: inkscape
    # renovate: datasource=nuget:chocolatey depName=inkscape
    version: '1.3.1'
    state: upgrade-or-downgrade

or, have extra flags like:

- name: Install Inkscape
  chocolatey.chocolatey.win_chocolatey:
    # https://community.chocolatey.org/packages/inkscape
    name: inkscape
    # renovate: datasource=nuget:chocolatey depName=inkscape
    version: '1.3.1'
    state: present
    allow_upgrade: true
    allow_downgrade: true

Additional Context

No response

Related Issues

No response

Windos commented 5 months ago

@rgl - This is likely a docs issue, as setting the state to downgrade does, to my knowledge, what you're asking for here.

With that state set, if you don't specify a version it'll install the latest. If you do specify a version, then that version will be installed regardless of it it's a downgrade, upgrade, or fresh install.

vibe-stake commented 4 months ago

I just encountered this issue but didn't have chance to test downgrade. It just seems counterintuitive to set everything to downgrade just to get a specific package version installed or upgraded.

I would think this functionality would rather suit well with the state:present where it should install, upgrade or downgrade to match the version you have assigned with present.

with this the state:downgrade would be redundant

vexx32 commented 2 weeks ago

Presently the behaviour of state: present is that the task will fail if the package is installed at a different version, so changing that would be a breaking change.

state: downgrade does do what's needed, and that somewhat inherits from choco's pattern where doing this would require a choco upgrade $version --allow-downgrade -- it's weird to specify that for an upgrade action, but it's permitted even if the version specified is actually an upgrade.

We already have a couple aliased state names if memory serves, so adding a new alias for state: downgrade would not be too hard to add really if it makes it more intuitive. I'm not really sold on any of the current suggestions for state names in this issue though so far.