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

Calling brew cask install is disabled! Use brew install [--cask] instead. #1524

Closed
dsnyder0pc opened this issue Dec 21, 2020 · 30 comments · Fixed by #1481
Closed

Calling brew cask install is disabled! Use brew install [--cask] instead. #1524

dsnyder0pc opened this issue Dec 21, 2020 · 30 comments · Fixed by #1481
Labels
bug This issue/PR relates to a bug has_pr module module os packaging plugins plugin (any type) python3

Comments

@dsnyder0pc
Copy link

dsnyder0pc commented Dec 21, 2020

SUMMARY

I have a simple playbook that ensures a set of brew casks are installed. It stopped working this morning (actually, probably three days ago with this merge) because, apparently, the Homebrew folks disabled brew cask install. I'm submitting this as a bug report because I imagine it affects everyone using the homebrew_cask module. Cask installation is no longer possible with homebrew_cask until this issue is resolved.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

homebrew_cask

ANSIBLE VERSION
ansible 2.10.3
  config file = None
  configured module search path = ['/Users/dsnyder/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/dsnyder/.pyenv/versions/3.9.1/lib/python3.9/site-packages/ansible
  executable location = /Users/dsnyder/.pyenv/versions/3.9.1/bin/ansible
  python version = 3.9.1 (default, Dec 14 2020, 14:55:40) [Clang 11.0.3 (clang-1103.0.32.62)]
CONFIGURATION
// No Changes //
OS / ENVIRONMENT
  • macOS Catalina v10.15.7
  • MacBook Pro (13-inch, 2019, Four Thunderbolt 3 ports)
  • Processor. 2.8 GHz Quad-Core Intel Core i7
  • Memory. 16 GB 2133 MHz LPDDR3
STEPS TO REPRODUCE

Create a simple inventory playbook to ensure that the "docker" cask is installed locally.

$ head -n 500 inventory docker.yml
==> inventory <==
localhost ansible_connection=local ansible_python_interpreter=/Users/dsnyder/.pyenv/shims/python3

==> docker.yml <==
---
- name: Homebrew Cask Demo
  hosts: all
  tasks:
    - name: Try to install the docker cask
      community.general.homebrew_cask:
        name: docker
        install_options: 'debug,appdir=/Applications'
        accept_external_apps: true
        state: present

$ ansible-playbook -i inventory docker.yml
EXPECTED RESULTS

Since I already have this cask installed, I expect Ansible to report that no change was required.

ACTUAL RESULTS

The play fails with this stack trace:

Updating Homebrew...
Error: Calling brew cask install is disabled! Use brew install [--cask] instead.
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:177:in `run'
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:117:in `run'
/usr/local/Homebrew/Library/Homebrew/cmd/cask.rb:15:in `cask'
/usr/local/Homebrew/Library/Homebrew/brew.rb:124:in `<main>'
Error: Kernel.exit
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:188:in `exit'
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:188:in `rescue in run'
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:165:in `run'
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:117:in `run'
/usr/local/Homebrew/Library/Homebrew/cmd/cask.rb:15:in `cask'
/usr/local/Homebrew/Library/Homebrew/brew.rb:124:in `<main>'
$ ansible-playbook -i inventory docker.yml

PLAY [Homebrew Cask Demo] ******************************************************

TASK [Gathering Facts] *********************************************************
ok: [localhost]

TASK [Try to install the docker cask] ******************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Updating Homebrew...\nError: Calling brew cask install is disabled! Use brew install [--cask] instead.\n/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:177:in `run'\n/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:117:in `run'\n/usr/local/Homebrew/Library/Homebrew/cmd/cask.rb:15:in `cask'\n/usr/local/Homebrew/Library/Homebrew/brew.rb:124:in `<main>'\nError: Kernel.exit\n/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:188:in `exit'\n/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:188:in `rescue in run'\n/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:165:in `run'\n/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:117:in `run'\n/usr/local/Homebrew/Library/Homebrew/cmd/cask.rb:15:in `cask'\n/usr/local/Homebrew/Library/Homebrew/brew.rb:124:in `<main>'"}

PLAY RECAP *********************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
ADDITIONAL COMMENTS

I can easily reproduce this error by running the following command:

$ brew cask --debug --appdir=/Applications install docker
Error: Calling brew cask install is disabled! Use brew install [--cask] instead.
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:177:in `run'
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:117:in `run'
/usr/local/Homebrew/Library/Homebrew/cmd/cask.rb:15:in `cask'
/usr/local/Homebrew/Library/Homebrew/brew.rb:124:in `<main>'
Error: Kernel.exit
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:188:in `exit'
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:188:in `rescue in run'
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:165:in `run'
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:117:in `run'
/usr/local/Homebrew/Library/Homebrew/cmd/cask.rb:15:in `cask'
/usr/local/Homebrew/Library/Homebrew/brew.rb:124:in `<main>'

The solution seems to be to use a command-line like this instead:

$ brew install --cask --appdir=/Applications docker
Warning: Cask 'docker' is already installed.

To re-install docker, run:
  brew reinstall docker

$ echo $?
0
TRYING community.general.homebrew

I tried to do the same thing with the homebrew module, but the idempotency check fails because the --cask option is required for both list and install for casks:

$ cat docker2.yml
---
- name: Homebrew Cask Demo
  hosts: all
  tasks:
    - name: Try to install the docker cask
      community.general.homebrew:
        name: docker
        install_options: 'cask,appdir=/Applications'
        state: present

$ ansible-playbook -i inventory docker2.yml

PLAY [Homebrew Cask Demo] ******************************************************************

TASK [Gathering Facts] *********************************************************************
ok: [localhost]

TASK [Try to install the docker cask] ******************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Warning: Cask 'docker' is already installed.\n\nTo re-install docker, run:\n  brew reinstall docker"}

PLAY RECAP *********************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

I've not studied the code in the homebrew module, but I imagine it checks for installation by doing something like this:

$ brew list docker
Error: No such keg: /usr/local/Cellar/docker

For casks, it needs to do this:

$ brew list --cask docker
==> App
/Applications/Docker.app (15,133 files, 1.3GB)

I can work around this idempotency issue by adding another task to check if docker is installed first, but that's messy. This check should really be handled by the module.

$ cat docker3.yml
---
- name: Homebrew Cask Demo
  hosts: all
  tasks:
    - name: Check to see if docker is installed
      command: brew list --cask docker
      register: result
      ignore_errors: true
      changed_when: false

    - name: Try to install the docker cask
      community.general.homebrew:
        name: docker
        install_options: 'cask,appdir=/Applications'
        state: present
      when: result is failed

$ ansible-playbook -i inventory docker3.yml

PLAY [Homebrew Cask Demo] ******************************************************************

TASK [Gathering Facts] *********************************************************************
ok: [localhost]

TASK [Check to see if docker is installed] *************************************************
ok: [localhost]

TASK [Try to install the docker cask] ******************************************************
skipping: [localhost]

PLAY RECAP *********************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0
@ansibullbot
Copy link
Collaborator

Files identified in the description:
None

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@dsnyder0pc
Copy link
Author

Note: I've commented here about this issue. It's not helpful that the Homebrew folks have decided against maintaining a stable command-line interface. It would be worth checking for other Homebrew subcommands that may be in deprecated state since those changes will create similar problems.

@dsnyder0pc
Copy link
Author

dsnyder0pc commented Dec 21, 2020

There's probably more to do, but these quick local edits (patch file below) seem to have things working as expected for me.

--- homebrew_cask.py	2020-12-21 18:04:53.000000000 -0800
+++ homebrew_cask_edit.py	2020-12-21 18:05:07.000000000 -0800
@@ -437,8 +437,8 @@
         cask_is_outdated_command = (
             [
                 self.brew_path,
-                'cask',
                 'outdated',
+                '--cask',
             ]
             + (['--greedy'] if self.greedy else [])
             + [self.current_cask]
@@ -456,8 +456,8 @@
 
         cmd = [
             "{brew_path}".format(brew_path=self.brew_path),
-            "cask",
             "list",
+            "--cask",
             self.current_cask
         ]
         rc, out, err = self.module.run_command(cmd)
@@ -538,7 +538,7 @@
             raise HomebrewCaskException(self.message)
 
         opts = (
-            [self.brew_path, 'cask', 'upgrade']
+            [self.brew_path, 'upgrade', '--cask']
         )
 
         cmd = [opt for opt in opts if opt]
@@ -587,7 +587,7 @@
             raise HomebrewCaskException(self.message)
 
         opts = (
-            [self.brew_path, 'cask', 'install', self.current_cask]
+            [self.brew_path, 'install', '--cask', self.current_cask]
             + self.install_options
         )
 
@@ -651,7 +651,7 @@
             raise HomebrewCaskException(self.message)
 
         opts = (
-            [self.brew_path, 'cask', command]
+            [self.brew_path, 'command', '--cask']
             + self.install_options
             + [self.current_cask]
         )
@@ -704,7 +704,7 @@
             raise HomebrewCaskException(self.message)
 
         opts = (
-            [self.brew_path, 'cask', 'uninstall', self.current_cask]
+            [self.brew_path, 'uninstall', '--cask', self.current_cask]
             + self.install_options
         )

@ahawkins
Copy link

tl;dr: The recent homebrew 2.7 release broke the homebrew_cask module.

@raymondyou97
Copy link

raymondyou97 commented Dec 21, 2020

Was able to get it working again by downgrading and locking Homebrew to 2.6.2

  1. Downgrade to 2.6.2
cd /usr/local/Homebrew
git fetch --tags
git checkout 2.6.2
  1. Prevent automatic brew upgrades whenever you install/upgrade something. In your .zshrc or .bashrc,
export HOMEBREW_NO_AUTO_UPDATE=1

@felixfontein
Copy link
Collaborator

There's already a PR for this: #1481

Since you are Homebrew users, would be great if you could test it!

@felixfontein
Copy link
Collaborator

felixfontein commented Dec 21, 2020

(Also, I'm quite confused why everyone some people is are saying that brew cask is deprecated. It is apparently not deprecated (otherwise it would still work), but has been removed. Deprecation means there will be a warning that it will be removed in the future.)

@ansibullbot
Copy link
Collaborator

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.

click here for bot help

@ansibullbot
Copy link
Collaborator

@dsnyder0pc
Copy link
Author

(Also, I'm quite confused why everyone some people is are saying that brew cask is deprecated. It is apparently not deprecated (otherwise it would still work), but has been removed. Deprecation means there will be a warning that it will be removed in the future.)

Well, from looking at the commit history, the brew cask subcommand has been deprecated for a while. As of 2.7 of Homebrew, brew cask was deleted.

@dsnyder0pc
Copy link
Author

Response from the Homebrew team:

Homebrew/discussions#340 (comment)

@felixfontein
Copy link
Collaborator

(Also, I'm quite confused why everyone some people is are saying that brew cask is deprecated. It is apparently not deprecated (otherwise it would still work), but has been removed. Deprecation means there will be a warning that it will be removed in the future.)

Well, from looking at the commit history, the brew cask subcommand has been deprecated for a while. As of 2.7 of Homebrew, brew cask was deleted.

Ok, so it was indeed just deprecated a few days ago (December 1st), and got removed only since yesterday. So talking about it as deprecated was actually correct until the day before yesterday :)

@Rylan12
Copy link

Rylan12 commented Dec 23, 2020

Hi there, Homebrew maintainer here.

I can clear up a few things:

  • brew cask commands were deprecated on 2020-12-01 with the release of Homebrew 2.6.0. Starting then, all brew cask commands succeeded but displayed a warning informing users that the command would soon be disabled. The message also provides the appropriate replacement.
  • brew cask commands were disabled on 2020-12-21 with the release of Homebrew 2.7.0. Starting then, all brew cask commands failed and displayed a warning informing users that the command is disabled. The message also provides the appropriate replacement.
  • With the release of Homebrew 2.8.0 (release date TBD), this disable message will be removed.

The alternative to brew cask <command> is to use brew <command>. In many cases, you can add the --cask flag to specify casks only. For example, brew cask install atom is now brew install atom or brew install --cask atom. There are some casks that share a name with formulae (e.g. wireshark) so adding --cask ensures that the cask is installed not the formula.

I'm not much of an ansible user but I'm happy to try and help out if needed. Feel free to point me in the right direction if anything is blocked and could use feedback from the Homebrew side of things.

@felixfontein
Copy link
Collaborator

@Rylan12 thanks! We already have a PR which should fix that (#1481), it needs a little more work but should already work. It detects the homebrew version so it will work with older versions of homebrew as well.

@rpalri
Copy link

rpalri commented Dec 25, 2020

Hi there, Homebrew maintainer here.

I can clear up a few things:

  • brew cask commands were deprecated on 2020-12-01 with the release of Homebrew 2.6.0. Starting then, all brew cask commands succeeded but displayed a warning informing users that the command would soon be disabled. The message also provides the appropriate replacement.
  • brew cask commands were disabled on 2020-12-21 with the release of Homebrew 2.7.0. Starting then, all brew cask commands failed and displayed a warning informing users that the command is disabled. The message also provides the appropriate replacement.
  • With the release of Homebrew 2.8.0 (release date TBD), this disable message will be removed.

The alternative to brew cask <command> is to use brew <command>. In many cases, you can add the --cask flag to specify casks only. For example, brew cask install atom is now brew install atom or brew install --cask atom. There are some casks that share a name with formulae (e.g. wireshark) so adding --cask ensures that the cask is installed not the formula.

I'm not much of an ansible user but I'm happy to try and help out if needed. Feel free to point me in the right direction if anything is blocked and could use feedback from the Homebrew side of things.

Thank you @Rylan12!
For everyone else, this is the solution.

@carlos-ssh
Copy link

Very helpful @raymondyou97 Thanks.

wells0790 pushed a commit to wells0790/demo that referenced this issue Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug has_pr module module os packaging plugins plugin (any type) python3
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants