community.general
community.general copied to clipboard
homebrew_cask needs to use new syntax when command will upgrade homebrew
Summary
The fix in #1481 fails when brew updates itself before running the command. The version selection needs to take into account if Homebrew will be updated before the command is used.
- Check version -- select older syntax
- Update homebrew
- Run homebrew older syntax which fails
Issue Type
Bug Report
Component Name
homebrew_cask
Ansible Version
ansible 2.10.6
config file = None
configured module search path = ['/Users/jrhett/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/Cellar/ansible/3.0.0/libexec/lib/python3.9/site-packages/ansible
executable location = /usr/local/bin/ansible
python version = 3.9.2 (default, Feb 24 2021, 13:30:36) [Clang 12.0.0 (clang-1200.0.32.29)]
Configuration
- community.general.homebrew_cask:
name: docker
state: present
OS / Environment
OSX any version
Steps to Reproduce
cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
git checkout $(git rev-list -1 --before="Dec 1 2020" master)
Expected Results
homebrew_cask would succeed the first time
Actual Results
First time results:
failed: [ansible-development] (item=docker) => {"ansible_loop_var": "item", "changed": false, "item": "docker", "msg": "Updating Homebrew...\n==> **SNIP** ==> Auto-updated Homebrew!\nUpdated 1 tap (homebrew/core).\n==> Updated Formulae\nUpdated 4647 formulae.\n\nError: Unknown command: cask"}
Second application succeeds.
Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
Files identified in the description:
If these files are inaccurate, please update the component name
section of the description or use the !component
bot command.
cc @Akasurde @danieljaouen @enriclluelles @indrajitr @kyleabenson @martinm82 click here for bot help
Does homebrew has an option "do not self-upgrade"? Using that would be an option for this, I guess.
There's an environment variable you can set to disable auto update when certain brew commands are run, e.g. brew install
, brew tap
and brew upgrade
.
https://github.com/Homebrew/brew/blob/e59f93cf19e8e9d56565e55ad76432670039aa27/Library/Homebrew/env_config.rb#L221:
HOMEBREW_NO_AUTO_UPDATE=1
That's useful! The best mechanism for this is to use module.run_command_environ_update
, which I just saw the homebrew
module already does (it even has a update_homebrew
option to control this behavior). It should be easy to add this to the homebrew_cask and homebrew_tap modules as well. (Not sure whether an option is the best choice, or just disable auto-update... I guess the latter is probably better, if a user wants to update brew, they should use the homebrew
module.)
Disabling auto update is at best a workaround, and would defeat latest
state declarations.
While I realize this problem will eventually disappear because no older Homebrew installations exist, it's a very small patch for a repeatable failure.
just stumbling on this, haven't walked through the source code. think I may be best off refactoring the yaml to:
- name: Install wkhtmltopdf
homebrew:
name: homebrew/cask/wkhtmltopdf
state: present
if the "name" prop, supports the /cask/ notation?
I don't understand why this is still being discussed as if it's uncertain what to do... 6 months after these changes were made in Homebrew itself.
People keep talking about how to suppress updates, which really has nothing to do with this bug. The bug is that the code currently makes choices about which command to run. That choice is being made incorrectly. User action specific to knowing the current state when writing the maniifest is antithetical to what Ansible is and does. The module should make the expressed change regardless of the current state.
@jorhett feel free to propose a PR which fixes this correctly from your point of view. This is mainly not fixed because nobody else did that so far.
Disabling auto update is at best a workaround, and would defeat
latest
state declarations.
I'm not sure I can follow your argument here. The state=latest
is about the cask to install, not about brew itself.
Disabling auto update is at best a workaround, and would defeat
latest
state declarations.I'm not sure I can follow your argument here. The
state=latest
is about the cask to install, not about brew itself.
How does one ensure that the latest package is installed if brew is not updated? That makes 'present' and 'latest' exactly the same.
You could perhaps argue that homebrew doesn't need an update in a case of 'present' where it is already installed, but in a situation where the state was set to 'latest' and arguably when it was set to 'present' but not installed, it would defy expectations.
@jorhett feel free to propose a PR which fixes this correctly from your point of view. This is mainly not fixed because nobody else did that so far.
I take it the author of the code that makes this choice has no concerns that it doesn't work as intended?
How does one ensure that the latest package is installed if brew is not updated? That makes 'present' and 'latest' exactly the same.
Are you implying it is impossible to install the latest version of some casks when not the latest version of homebrew is installed?
Files identified in the description:
If these files are incorrect, please update the component name
section of the description or use the !component
bot command.