-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
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