ansible-collections / community.general

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

mas: The error was: ValueError: invalid literal for int() with base 10 #2060

Open harapeko opened 3 years ago

harapeko commented 3 years ago

Summary

I get an error when updating mas-cli from 1.8.0 to 1.8.1

Issue Type

Bug Report

Component Name

Module mas

Ansible Version

ansible 2.10.6 config file = None configured module search path = ['/Users/harapeko/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /opt/homebrew/Cellar/ansible/3.0.0/libexec/lib/python3.9/site-packages/ansible executable location = /opt/homebrew/bin/ansible python version = 3.9.2 (default, Mar 15 2021, 10:13:36) [Clang 12.0.0 (clang-1200.0.32.29)]

Configuration

mas version 1.8.1

OS / Environment

macOS Big Sur 11.2.3 MacBook Air(M1, 2020) MacBook Pro(M1, 2020)

Steps to Reproduce

$ mas list
562184107 LanScan Pro (5.1.2)
497799835 Xcode (12.4)
409183694 Keynote (10.3.9)
408981434 iMovie (10.2.3)
425424353 The Unarchiver (4.2.4)
485812721 TweetDeck (3.18)
715768417 Microsoft Remote Desktop (8.0.30030)
1429033973 RunCat (9.0)
1258530160 Focus To-Do (6.4)
498944723 JPEGmini (2.2.4)
409201541 Pages (10.3.9)
539883307 LINE (6.7.1)
661532686 GPX Binder (2.0.12)
682658836 GarageBand (10.4.2)
1206246482 EdgeView 2 (2.918)
409203825 Numbers (10.3.9)

$ ansible-playbook -i hosts site.yml --ask-become-pass

Expected Results

TASK [mas : Upgrade all installed Mac App Store apps] ****************************************************************************************************************************************************
ok: [localhost]

source code↓

---
- name: Upgrade all installed Mac App Store apps
  community.general.mas:
    upgrade_all: yes

Actual Results

TASK [mas : Upgrade all installed Mac App Store apps] ******************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ValueError: invalid literal for int() with base 10: 'Warning:'
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/Users/harapeko/.ansible/tmp/ansible-tmp-1616247699.70544-5195-179563653852203/AnsiballZ_mas.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/Users/harapeko/.ansible/tmp/ansible-tmp-1616247699.70544-5195-179563653852203/AnsiballZ_mas.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/Users/harapeko/.ansible/tmp/ansible-tmp-1616247699.70544-5195-179563653852203/AnsiballZ_mas.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.general.plugins.modules.mas', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/runpy.py\", line 206, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/runpy.py\", line 96, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/runpy.py\", line 86, in _run_code\n    exec(code, run_globals)\n  File \"/var/folders/f8/kb247w791yb4fmgrxq6l4rb40000gn/T/ansible_community.general.mas_payload_5ygz1xdr/ansible_community.general.mas_payload.zip/ansible_collections/community/general/plugins/modules/mas.py\", line 295, in <module>\n  File \"/var/folders/f8/kb247w791yb4fmgrxq6l4rb40000gn/T/ansible_community.general.mas_payload_5ygz1xdr/ansible_community.general.mas_payload.zip/ansible_collections/community/general/plugins/modules/mas.py\", line 287, in main\n  File \"/var/folders/f8/kb247w791yb4fmgrxq6l4rb40000gn/T/ansible_community.general.mas_payload_5ygz1xdr/ansible_community.general.mas_payload.zip/ansible_collections/community/general/plugins/modules/mas.py\", line 221, in outdated\n  File \"/var/folders/f8/kb247w791yb4fmgrxq6l4rb40000gn/T/ansible_community.general.mas_payload_5ygz1xdr/ansible_community.general.mas_payload.zip/ansible_collections/community/general/plugins/modules/mas.py\", line 193, in get_current_state\nValueError: invalid literal for int() with base 10: 'Warning:'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

Code of Conduct

ansibullbot commented 3 years ago

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 commented 3 years ago

cc @lukasbestle @mheap click here for bot help

lukasbestle commented 3 years ago

@harapeko Could you please post the output of mas outdated? It looks like the changes in https://github.com/mas-cli/mas/pull/312 caused it.

harapeko commented 3 years ago

@lukasbestle thx!

$ mas outdated
Warning: Identifier 562184107 not found in store. Was expected to identify LanScan Pro.
Warning: Identifier 715768417 not found in store. Was expected to identify Microsoft Remote Desktop.
Warning: Identifier 498944723 not found in store. Was expected to identify JPEGmini.
lukasbestle commented 3 years ago

OK, that explains it. The Ansible mas module does not expect the Warning messages that were added in mas-cli 1.8.1.

I consider this a huge breaking change and I'm not sure if the warnings should be supported by the Ansible module or if mas-cli should instead have a "porcelain" mode that prints the data in a defined format that will never change (like Git does it for example). To be honest I prefer the latter to avoid similar issues in the future.

Pinging @rgoldberg and @phatblat who were engaged in the PR that changed the behavior.

harapeko commented 3 years ago

@lukasbestle Thanks for your great research and foresight!

harapeko commented 3 years ago

Here's my workaround. Here's how to revert to mas v1.8.0.

$ /opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/
$ git checkout a7a97a9818dbbfc299a2d21a4e22921513917052 mas.rb
$ brew uninstall mas
$ brew install mas
$ mas version
1.8.0
rgoldberg commented 3 years ago

The old version of mas outdated (& mas upgrade) used a now-broken Apple API that provided the outdated apps, so it hasn't been reporting any apps as outdated for a few years.

The new implementation iterates over the apps in your local App Library, checking each against the version in the store.

If the identifier of an app in your library is not found in the store, mas now outputs a warning. This situation was not possible using the old API, so it's a new warning.

If warnings aren't already output to stderr, maybe they should be switched there. I just used the standard warning function to report them.

Or a nowarn mode could be added to mas.

phatblat commented 3 years ago

It would be easy to send warnings to stderr as a quick fix for this.

The output from mas is mainly intended for humans but with tools such as this relying on that format this is a fragile dependency. Been thinking about introducing a JSON output for tools to use in v2. See mas-cli/mas#190

ansibullbot commented 2 years 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