ansible-collections / community.general

Ansible Community General Collection
https://galaxy.ansible.com/ui/repo/published/community/general/
GNU General Public License v3.0
842 stars 1.54k forks source link

homebrew_cask TypeError: '<' not supported between instances of 'str' and 'int' #8432

Open gionn opened 6 months ago

gionn commented 6 months ago

Summary

When trying to install some casks via https://github.com/geerlingguy/ansible-collection-mac, I am getting a failure very similar to https://github.com/ansible-collections/community.general/issues/6842

brew --version
Homebrew >=4.1.0 (shallow or no git repository)

homebrew is installed via git: https://github.com/geerlingguy/ansible-collection-mac/blob/master/roles/homebrew/tasks/main.yml#L47

should make sense that homebrew_cask support homebrew checked out from git - if this is the culprit?

Issue Type

Bug Report

Component Name

homebrew_cask

Ansible Version

ansible [core 2.15.5]
  config file = None
  configured module search path = ['/Users/Giovanni.Toraldo/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/Giovanni.Toraldo/.pyenv/versions/3.9.0/lib/python3.9/site-packages/ansible
  ansible collection location = /Users/Giovanni.Toraldo/.ansible/collections:/usr/share/ansible/collections
  executable location = /Users/Giovanni.Toraldo/.pyenv/versions/3.9.0/bin/ansible
  python version = 3.9.0 (default, Jan 11 2022, 11:48:51) [Clang 13.0.0 (clang-1300.0.29.30)] (/Users/Giovanni.Toraldo/.pyenv/versions/3.9.0/bin/python3.9)
  jinja version = 3.1.2
  libyaml = True

Community.general Version

$ ansible-galaxy collection list community.general
Collection        Version
----------------- -------
community.general 9.0.1  

Configuration

$ ansible-config dump --only-changed
CONFIG_FILE() = None
EDITOR(env: EDITOR) = vim
PAGER(env: PAGER) = less

OS / Environment

MacOSX

Steps to Reproduce

---
- name: Setup macOS
  hosts: macos_host
  gather_facts: true
  vars:
    homebrew_cask_apps:
      - podman-desktop
  roles:
    - geerlingguy.mac.homebrew

Expected Results

Cask being installed without issues

Actual Results

The full traceback is:
Traceback (most recent call last):
  File "/Users/giovanni.toraldo/.ansible/tmp/ansible-tmp-1716891339.5577118-26934-129968400879188/AnsiballZ_homebrew_cask.py", line 107, in <module>
    _ansiballz_main()
  File "/Users/giovanni.toraldo/.ansible/tmp/ansible-tmp-1716891339.5577118-26934-129968400879188/AnsiballZ_homebrew_cask.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/Users/giovanni.toraldo/.ansible/tmp/ansible-tmp-1716891339.5577118-26934-129968400879188/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/8b/znm5ps_53cj6strkrp2q9j1h0000gp/T/ansible_homebrew_cask_payload_iwg1ihec/ansible_homebrew_cask_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_cask.py", line 895, in <module>
  File "/var/folders/8b/znm5ps_53cj6strkrp2q9j1h0000gp/T/ansible_homebrew_cask_payload_iwg1ihec/ansible_homebrew_cask_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_cask.py", line 887, in main
  File "/var/folders/8b/znm5ps_53cj6strkrp2q9j1h0000gp/T/ansible_homebrew_cask_payload_iwg1ihec/ansible_homebrew_cask_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_cask.py", line 450, in run
  File "/var/folders/8b/znm5ps_53cj6strkrp2q9j1h0000gp/T/ansible_homebrew_cask_payload_iwg1ihec/ansible_homebrew_cask_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_cask.py", line 523, in _run
  File "/var/folders/8b/znm5ps_53cj6strkrp2q9j1h0000gp/T/ansible_homebrew_cask_payload_iwg1ihec/ansible_homebrew_cask_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_cask.py", line 671, in _install_casks
  File "/var/folders/8b/znm5ps_53cj6strkrp2q9j1h0000gp/T/ansible_homebrew_cask_payload_iwg1ihec/ansible_homebrew_cask_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_cask.py", line 622, in _install_current_cask
  File "/var/folders/8b/znm5ps_53cj6strkrp2q9j1h0000gp/T/ansible_homebrew_cask_payload_iwg1ihec/ansible_homebrew_cask_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_cask.py", line 485, in _current_cask_is_installed
  File "/var/folders/8b/znm5ps_53cj6strkrp2q9j1h0000gp/T/ansible_homebrew_cask_payload_iwg1ihec/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/8b/znm5ps_53cj6strkrp2q9j1h0000gp/T/ansible_homebrew_cask_payload_iwg1ihec/ansible_homebrew_cask_payload.zip/ansible/module_utils/compat/version.py", line 78, in __ge__
  File "/var/folders/8b/znm5ps_53cj6strkrp2q9j1h0000gp/T/ansible_homebrew_cask_payload_iwg1ihec/ansible_homebrew_cask_payload.zip/ansible/module_utils/compat/version.py", line 338, in _cmp
TypeError: '<' not supported between instances of 'str' and 'int'
failed: [macos_host] (item=podman-desktop) => {
    "ansible_loop_var": "item",
    "changed": false,
    "item": "podman-desktop",
    "module_stderr": "Shared connection to 192.168.1.18 closed.\r\n",
    "module_stdout": "Traceback (most recent call last):\r\n  File \"/Users/giovanni.toraldo/.ansible/tmp/ansible-tmp-1716891339.5577118-26934-129968400879188/AnsiballZ_homebrew_cask.py\", line 107, in <module>\r\n    _ansiballz_main()\r\n  File \"/Users/giovanni.toraldo/.ansible/tmp/ansible-tmp-1716891339.5577118-26934-129968400879188/AnsiballZ_homebrew_cask.py\", line 99, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/Users/giovanni.toraldo/.ansible/tmp/ansible-tmp-1716891339.5577118-26934-129968400879188/AnsiballZ_homebrew_cask.py\", line 47, in invoke_module\r\n    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),\r\n  File \"/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py\", line 210, in run_module\r\n    return _run_module_code(code, init_globals, run_name, mod_spec)\r\n  File \"/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py\", line 97, in _run_module_code\r\n    _run_code(code, mod_globals, init_globals,\r\n  File \"/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py\", line 87, in _run_code\r\n    exec(code, run_globals)\r\n  File \"/var/folders/8b/znm5ps_53cj6strkrp2q9j1h0000gp/T/ansible_homebrew_cask_payload_iwg1ihec/ansible_homebrew_cask_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_cask.py\", line 895, in <module>\r\n  File \"/var/folders/8b/znm5ps_53cj6strkrp2q9j1h0000gp/T/ansible_homebrew_cask_payload_iwg1ihec/ansible_homebrew_cask_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_cask.py\", line 887, in main\r\n  File \"/var/folders/8b/znm5ps_53cj6strkrp2q9j1h0000gp/T/ansible_homebrew_cask_payload_iwg1ihec/ansible_homebrew_cask_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_cask.py\", line 450, in run\r\n  File \"/var/folders/8b/znm5ps_53cj6strkrp2q9j1h0000gp/T/ansible_homebrew_cask_payload_iwg1ihec/ansible_homebrew_cask_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_cask.py\", line 523, in _run\r\n  File \"/var/folders/8b/znm5ps_53cj6strkrp2q9j1h0000gp/T/ansible_homebrew_cask_payload_iwg1ihec/ansible_homebrew_cask_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_cask.py\", line 671, in _install_casks\r\n  File \"/var/folders/8b/znm5ps_53cj6strkrp2q9j1h0000gp/T/ansible_homebrew_cask_payload_iwg1ihec/ansible_homebrew_cask_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_cask.py\", line 622, in _install_current_cask\r\n  File \"/var/folders/8b/znm5ps_53cj6strkrp2q9j1h0000gp/T/ansible_homebrew_cask_payload_iwg1ihec/ansible_homebrew_cask_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_cask.py\", line 485, in _current_cask_is_installed\r\n  File \"/var/folders/8b/znm5ps_53cj6strkrp2q9j1h0000gp/T/ansible_homebrew_cask_payload_iwg1ihec/ansible_homebrew_cask_payload.zip/ansible_collections/community/general/plugins/modules/homebrew_cask.py\", line 513, in _brew_cask_command_is_deprecated\r\n  File \"/var/folders/8b/znm5ps_53cj6strkrp2q9j1h0000gp/T/ansible_homebrew_cask_payload_iwg1ihec/ansible_homebrew_cask_payload.zip/ansible/module_utils/compat/version.py\", line 78, in __ge__\r\n  File \"/var/folders/8b/znm5ps_53cj6strkrp2q9j1h0000gp/T/ansible_homebrew_cask_payload_iwg1ihec/ansible_homebrew_cask_payload.zip/ansible/module_utils/compat/version.py\", line 338, in _cmp\r\nTypeError: '<' not supported between instances of 'str' and 'int'\r\n",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

Code of Conduct

ansibullbot commented 6 months ago

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.

click here for bot help

ansibullbot commented 6 months ago

cc @Akasurde @danieljaouen @enriclluelles @indrajitr @kyleabenson @martinm82 click here for bot help

felixfontein commented 6 months ago

The problem is the >= in the version output. The code currently treats that as part of the version.

gionn commented 6 months ago

@felixfontein I can raise a PR to extract the version via r"(\d+\.\d+\.\d+)" in https://github.com/ansible-collections/community.general/blob/main/plugins/modules/homebrew_cask.py#L443 or else?

felixfontein commented 6 months ago

@gionn you can, but you should also add some code that checks for >= and emits a warning that the version detection might yield a wrong result.

monika-canva commented 5 months ago

Having the same issue with:

brew --version
Homebrew 4.3.7-dirty