Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade of package when State is Present and Version is specified, fails unless forced #59

Closed
steviecoaster opened this issue Jul 28, 2021 · 9 comments · Fixed by #67
Closed
Assignees
Labels
5 - Released The issue has been resolved, and released to the public for consumption Documentation Issues for changes that only need to change documentation Improvement Issues that enhances existing functionality, or adds new features
Milestone

Comments

@steviecoaster
Copy link
Collaborator

Offending code:

if (-not $package_versions.Contains($version) -and -not $allow_multiple) {
                    $module.FailJson("Chocolatey package '$package' is already installed with version(s) '$($package_versions -join "', '")' but was expecting '$version'. Either change the expected version, set state=latest, set allow_multiple=yes, or set force=yes to continue")
} elseif ($version -notin $package_versions -and $allow_multiple) {
     # add the package back into the list of missing packages if installing multiple
     $missing_packages.Add($package) > $null
}

WORKAROUND:

- name: install Notepad++ at 7.6.3
  win_chocolatey:
    name: notepadplusplus
    version: 7.6.3
    allow_prerelease: yes
    state: latest
@steviecoaster steviecoaster added Bug Issues where something has happened which was not expected or intended 0 - _Triaging Issue is accepted, but a milestone has yet to be added for the issue labels Jul 28, 2021
@steviecoaster steviecoaster self-assigned this Jul 28, 2021
@vexx32
Copy link
Member

vexx32 commented Jul 28, 2021

This seems to be by design, at least going from the error message the code gives back here.

Though at least from my perspective it seems a little odd to require a different state for upgrades vs fresh installs, when choco is usually perfectly able to upgrade packages...

Maybe because this module also supports --allow-multiple and it could get confusing whether the user is asking us to upgrade a package vs install a side by side? 🤔

@jborean93 might be able to speak to the design intent here.

@jborean93
Copy link
Contributor

The code around this snippet provides a bit more context https://github.com/chocolatey/chocolatey-ansible/blob/master/chocolatey/plugins/modules/win_chocolatey.ps1#L780-L794.

This is only run when state: present and an explicit version is set. If the version reported by Chocolatey does not match what is installed and allow_multiple: yes is not set then it considers it a failure. Essentially the module currently treats state: present as install but never update so if you specify a version that isn't installed then it considers it a failure.

Maybe this could be amended by having the module implicitly upgrade it but how do decide what to update if there are multiple versions and allow_multiple is not set.

Oh did I mention package management versioning is hard :)

@vexx32
Copy link
Member

vexx32 commented Jul 30, 2021

how do decide what to update if there are multiple versions and allow_multiple is not set.

I don't think Chocolatey itself handles this eventuality well either, really, even if you did have --allow-multiple on the command, I doubt I'd be able to predict what Chocolatey would do in that kind of situation. It's probably part of the reason Rob tends to recommend against using side-by-side installations.

I'm not sure there's a ton we can do to do better here, but maybe it'd be more intuitive for some folks if we simply added state: upgrade as an accepted value that internally follows the same logic as state: latest.

@steviecoaster
Copy link
Collaborator Author

Agreeing with @vexx32 here. --allow-multiple is a bit of an anti-pattern, and something we don't recommend. There's edge cases where it's needed (Java a good example), but by and large should be avoided.

I think state: upgrade is a good path forward.

@vexx32
Copy link
Member

vexx32 commented Aug 27, 2021

Tangentially related: chocolatey/choco#1022

If that issue goes somewhere in future we might end up with --allow-multiple being eclipsed/deprecated by that functionality, and we can more easily reason about what should happen from this module as well.

@pauby pauby changed the title Upgrade of package when State is Present and Version is specified fails unlessed forced Upgrade of package when State is Present and Version is specified, fails unless forced Jan 21, 2022
@pauby pauby added 0 - Backlog Issue is accepted, but is not ready to be worked on or not in current sprint Documentation Issues for changes that only need to change documentation and removed Bug Issues where something has happened which was not expected or intended 0 - _Triaging Issue is accepted, but a milestone has yet to be added for the issue labels Jan 21, 2022
@pauby pauby added this to the 1.2.x milestone Jan 21, 2022
@vexx32 vexx32 added the Improvement Issues that enhances existing functionality, or adds new features label Jan 24, 2022
vexx32 added a commit to vexx32/chocolatey-ansible that referenced this issue Jan 25, 2022
vexx32 added a commit to vexx32/chocolatey-ansible that referenced this issue Jan 25, 2022
Added state: upgrade option to docs, clarified docs on version option
a bit more, attempting to make it abundantly clear that using
state: present with a specific target version can fail if the versions
don't match up.
vexx32 added a commit to vexx32/chocolatey-ansible that referenced this issue Jan 25, 2022
Duplicate some of our state: latest tests to use state: upgrade
to ensure both state commands work the same way.
@vexx32 vexx32 added 3 - Review Code has been added, and is available for review as a pull request 2 - Working A user or team member has started working on the issue and removed 0 - Backlog Issue is accepted, but is not ready to be worked on or not in current sprint 3 - Review Code has been added, and is available for review as a pull request labels Jan 25, 2022
vexx32 added a commit to vexx32/chocolatey-ansible that referenced this issue Jan 31, 2022
vexx32 added a commit to vexx32/chocolatey-ansible that referenced this issue Jan 31, 2022
Added state: upgrade option to docs, clarified docs on version option
a bit more, attempting to make it abundantly clear that using
state: present with a specific target version can fail if the versions
don't match up.
vexx32 added a commit to vexx32/chocolatey-ansible that referenced this issue Jan 31, 2022
Duplicate some of our state: latest tests to use state: upgrade
to ensure both state commands work the same way.
@corbob corbob closed this as completed in #67 Feb 1, 2022
@pauby pauby added the 5 - Released The issue has been resolved, and released to the public for consumption label May 13, 2022
@pauby pauby removed the 2 - Working A user or team member has started working on the issue label May 13, 2022
@drdamour
Copy link

I'm not sure there's a ton we can do to do better here, but maybe it'd be more intuitive for some folks if we simply added state: upgrade as an accepted value that internally follows the same logic as state: latest.

this and the docs confuse me, the way it reads it sounds like the behaviour is exactly the same as latest, but latests ignores the version correct? is upgrade constrained to the version?

@vexx32
Copy link
Member

vexx32 commented Apr 26, 2023

Neither latest or upgrade ignore a specified version. If you've specified a version number for either state, they will use just that version.

That confusion is somewhat exactly why I dislike the name latest for that state and why I added upgrade as an alias for it. But without breaking folks we can't remove latest at present, so until we do a major version release we'll have (somewhat confusingly) both states around.

@jansohn
Copy link

jansohn commented Jul 17, 2023

I think it is quite unintuitive that the combination state: present and version: '1.1' leads to an error if version 1.0 is currently installed. Wouldn't it be possible to let this combination just upgrade the package to 1.1?

@vexx32
Copy link
Member

vexx32 commented Jul 17, 2023

Sure, it's possible. It would be a fairly significant breaking change in the module behaviour, though, and I don't really see the value in changing it to effectively do the same thing as another state value. state: upgrade does the action you want already, so I think it's ultimately fine to have present as its own thing that lets users get an error back indicating that a node has the wrong version installed if that's something they care about.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 - Released The issue has been resolved, and released to the public for consumption Documentation Issues for changes that only need to change documentation Improvement Issues that enhances existing functionality, or adds new features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants