geerlingguy / mac-dev-playbook

Mac setup and configuration via Ansible.
Other
5.95k stars 1.76k forks source link

Running straight from clone installation throws exception - Brew Casks Functionality Broken #196

Closed BoggyBumblebee closed 1 month ago

BoggyBumblebee commented 7 months ago

Followed the steps provided, and I did not provide a custom config.yml, so using default 'default.config.yml'. When it comes to processing homebrew_cask_apps, it throws this error for every entry in the 'homebrew_cask_apps':

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: '<' not supported between instances of 'str' and 'int'
failed: [127.0.0.1] (item=chromedriver) => changed=false 
  ansible_loop_var: item
  item: chromedriver
  module_stderr: |-
    Traceback (most recent call last):
      File "/Users/cmb/.ansible/tmp/ansible-tmp-1708506861.4051142-1294-146175815614559/AnsiballZ_homebrew_cask.py", line 107, in <module>
        _ansiballz_main()
      File "/Users/cmb/.ansible/tmp/ansible-tmp-1708506861.4051142-1294-146175815614559/AnsiballZ_homebrew_cask.py", line 99, in _ansiballz_main
        invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
      File "/Users/cmb/.ansible/tmp/ansible-tmp-1708506861.4051142-1294-146175815614559/AnsiballZ_homebrew_cask.py", line 47, in invoke_module
        runpy.run_module(mod_name='ansible_collections.community.general.plugins.modules.homebrew_cask', init_globals=dict(_module_fqn='ansible_collections.community.general.plugins.modules.homebrew_cask', _modlib_path=modlib_path),
      File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py", line 210, in run_module
        return _run_module_code(code, init_globals, run_name, mod_spec)
      File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py", line 97, in _run_module_code
        _run_code(code, mod_globals, init_globals,
      File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
        exec(code, run_globals)
      File "/var/folders/vl/3dh1j32505z1s0dmgkk63z7m0000gn/T/ansible_homebrew_cask_payload_xmuhnua8/ansible_homebrew_cask_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_cask.py", line 895, in <module>
      File "/var/folders/vl/3dh1j32505z1s0dmgkk63z7m0000gn/T/ansible_homebrew_cask_payload_xmuhnua8/ansible_homebrew_cask_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_cask.py", line 887, in main
      File "/var/folders/vl/3dh1j32505z1s0dmgkk63z7m0000gn/T/ansible_homebrew_cask_payload_xmuhnua8/ansible_homebrew_cask_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_cask.py", line 450, in run
      File "/var/folders/vl/3dh1j32505z1s0dmgkk63z7m0000gn/T/ansible_homebrew_cask_payload_xmuhnua8/ansible_homebrew_cask_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_cask.py", line 523, in _run
      File "/var/folders/vl/3dh1j32505z1s0dmgkk63z7m0000gn/T/ansible_homebrew_cask_payload_xmuhnua8/ansible_homebrew_cask_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_cask.py", line 671, in _install_casks
      File "/var/folders/vl/3dh1j32505z1s0dmgkk63z7m0000gn/T/ansible_homebrew_cask_payload_xmuhnua8/ansible_homebrew_cask_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_cask.py", line 622, in _install_current_cask
      File "/var/folders/vl/3dh1j32505z1s0dmgkk63z7m0000gn/T/ansible_homebrew_cask_payload_xmuhnua8/ansible_homebrew_cask_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_cask.py", line 485, in _current_cask_is_installed
      File "/var/folders/vl/3dh1j32505z1s0dmgkk63z7m0000gn/T/ansible_homebrew_cask_payload_xmuhnua8/ansible_homebrew_cask_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_cask.py", line 513, in _brew_cask_command_is_deprecated
      File "/var/folders/vl/3dh1j32505z1s0dmgkk63z7m0000gn/T/ansible_homebrew_cask_payload_xmuhnua8/ansible_homebrew_cask_payload.zip/ansible/module_utils/compat/version.py", line 78, in __ge__
      File "/var/folders/vl/3dh1j32505z1s0dmgkk63z7m0000gn/T/ansible_homebrew_cask_payload_xmuhnua8/ansible_homebrew_cask_payload.zip/ansible/module_utils/compat/version.py", line 338, in _cmp
    TypeError: '<' not supported between instances of 'str' and 'int'
  module_stdout: ''
  msg: |-
    MODULE FAILURE
    See stdout/stderr for the exact error
  rc: 1

I can see where the error is (homebrew_cask.py), I'm struggling to find where that code resides, so I can work out what has gone wrong.

I know that the way in which Casks are installed has recently changed in homebrew, so I removed them and provided an empty 'homebrew_cask_apps' in the default config. The remainder of script then works. However, adding the cask list to the 'homebrew_installed_packages' did not work. Any suggestions on what needs to be fixed (happy to help), or a workaround?

BoggyBumblebee commented 7 months ago

Issue is found here in the homebrew. I see Jeff you commented on Ansible version being the issue - I'll see if that makes a difference. https://github.com/ansible-collections/community.general/issues/1524

BoggyBumblebee commented 7 months ago

I've found the root of the issue. When homebrew is first installed in the VM that I am using to test the installation, running the command brew --version returns the string "Homebrew >=4.1.0 (shallow or no git repository)", which cannot be correctly parsed by the code in homebrew_cask.py in the function def _get_brew_version(self): on line 498, that in turn throws an issue on line 513:

return LooseVersion(self._get_brew_version()) >= LooseVersion('2.6.0')

If I run brew update and then brew --version it nows returns "Homebrew 4.2.9", and if the Ansible script is re-run, everything works.

In @geerlingguy's tasks/main.yml there is a step that should force an update, post installation of brew, when "not homebrew_binary.stat.exists", but that is being skipped, as I assume that does exist. Should it not be forced regardless? Clearly, I can run the Ansible script several times, but that feels wrong.

github-actions[bot] commented 3 months ago

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

github-actions[bot] commented 1 month ago

This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.