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

Since 6.16 ANSIBLE_VERBOSITY=4 causes an unhandeld exception #3522

Closed
gone-for-coding opened this issue Jun 1, 2023 · 0 comments · Fixed by ansible/ansible-compat#287
Closed
Assignees
Labels

Comments

@gone-for-coding
Copy link

Summary

When setting ANSIBLE_VERBOSITY=4, parsing the json output of ansible-galaxy fails as STDOUT contains debug information prior to the json string.

Affected line: https://github.com/ansible/ansible-compat/blob/main/src/ansible_compat/runtime.py#L245

Issue Type
  • Bug Report
OS / ENVIRONMENT
ansible-lint --version
ansible-lint 6.16.2 using ansible-core:2.15.0 ruamel-yaml:0.17.28 ruamel-yaml-clib:0.2.7
  • ansible installation method: one of source, pip, OS package
  • ansible-lint installation method: one of source, pip, OS package
STEPS TO REPRODUCE

Put an arbitrary playbook into a folder and run the commands below.

root@242ee89e87fa:/code# export ANSIBLE_VERBOSITY=4
root@242ee89e87fa:/code# ansible-lint -vvvv
DEBUG    Logging initialized to level 10
INFO     Identified /code as project root due .git directory.
DEBUG    Options: Options(cache_dir=PosixPath('/root/.cache/ansible-compat/5694d0'), colored=True, configured=True, cwd=PosixPath('/code'), display_relative_path=True, exclude_paths=['.cache', '.git', '.hg', '.svn', '.tox'], format=None, lintables=[], list_rules=False, list_tags=False, write_list=[], parseable=False, quiet=False, rulesdirs=[PosixPath('/usr/local/lib/python3.11/site-packages/ansiblelint/rules')], skip_list=['galaxy', 'galaxy', 'galaxy'], tags=[], verbosity=4, warn_list=['experimental', 'jinja'], mock_filters=[], mock_modules=[], mock_roles=[], loop_var_prefix=None, only_builtins_allow_collections=[], only_builtins_allow_modules=[], var_naming_pattern=None, offline=False, project_dir='.', extra_vars=None, enable_list=[], skip_action_validation=True, strict=False, rules={}, profile=None, task_name_prefix='{stem} | ', sarif_file=None, config_file='/code/.ansible-lint', generate_ignore=False, rulesdir=[], cache_dir_lock=<filelock._unix.UnixFileLock object at 0x7f172e4c0b10>, use_default_rules=False, version=False, list_profiles=False, ignore_file=None)
DEBUG    CWD: /code
DEBUG    Checking for updated schemas...
DEBUG    Refreshing ansible-lint-config schema ...
DEBUG    Schema https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/ansible-lint-config.json is not modified
DEBUG    Refreshing ansible-navigator-config schema ...
DEBUG    Schema https://raw.githubusercontent.com/ansible/ansible-navigator/main/src/ansible_navigator/data/ansible-navigator.json is not modified
DEBUG    Refreshing changelog schema ...
DEBUG    Schema https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/changelog.json is not modified
DEBUG    Refreshing execution-environment schema ...
INFO     Schema execution-environment was updated
DEBUG    Refreshing galaxy schema ...
DEBUG    Schema https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/galaxy.json is not modified
DEBUG    Refreshing inventory schema ...
DEBUG    Schema https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/inventory.json is not modified
DEBUG    Refreshing meta schema ...
INFO     Schema meta was updated
DEBUG    Refreshing meta-runtime schema ...
DEBUG    Schema https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/meta-runtime.json is not modified
DEBUG    Refreshing molecule schema ...
DEBUG    Schema https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/molecule.json is not modified
DEBUG    Refreshing playbook schema ...
INFO     Schema playbook was updated
DEBUG    Refreshing requirements schema ...
DEBUG    Schema https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/requirements.json is not modified
DEBUG    Refreshing role-arg-spec schema ...
DEBUG    Schema https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/role-arg-spec.json is not modified
DEBUG    Refreshing rulebook schema ...
INFO     Schema rulebook was updated
DEBUG    Refreshing tasks schema ...
INFO     Schema tasks was updated
DEBUG    Refreshing vars schema ...
DEBUG    Schema https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/vars.json is not modified
DEBUG    Effective yamllint rules used: {'anchors': {'level': 'error', 'forbid-undeclared-aliases': True, 'forbid-duplicated-anchors': False, 'forbid-unused-anchors': False}, 'braces': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 1, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'brackets': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 0, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'colons': {'level': 'error', 'max-spaces-before': 0, 'max-spaces-after': 1}, 'commas': {'level': 'error', 'max-spaces-before': 0, 'min-spaces-after': 1, 'max-spaces-after': 1}, 'comments': {'level': 'warning', 'require-starting-space': True, 'ignore-shebangs': True, 'min-spaces-from-content': 1}, 'comments-indentation': False, 'document-end': False, 'document-start': False, 'empty-lines': {'level': 'error', 'max': 2, 'max-start': 0, 'max-end': 0}, 'empty-values': False, 'float-values': False, 'hyphens': {'level': 'error', 'max-spaces-after': 1}, 'indentation': {'level': 'error', 'spaces': 'consistent', 'indent-sequences': True, 'check-multi-line-strings': False}, 'key-duplicates': {'level': 'error'}, 'key-ordering': False, 'line-length': {'level': 'error', 'max': 160, 'allow-non-breakable-words': True, 'allow-non-breakable-inline-mappings': False}, 'new-line-at-end-of-file': {'level': 'error'}, 'new-lines': {'level': 'error', 'type': 'unix'}, 'octal-values': {'forbid-implicit-octal': True, 'forbid-explicit-octal': True, 'level': 'error'}, 'quoted-strings': False, 'trailing-spaces': {'level': 'error'}, 'truthy': {'level': 'warning', 'allowed-values': ['true', 'false'], 'check-keys': True}}
INFO     Set ANSIBLE_LIBRARY=/root/.cache/ansible-compat/5694d0/modules:/root/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO     Set ANSIBLE_COLLECTIONS_PATH=/root/.cache/ansible-compat/5694d0/collections:/root/.ansible/collections:/usr/share/ansible/collections
INFO     Set ANSIBLE_ROLES_PATH=/root/.cache/ansible-compat/5694d0/roles:/root/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
INFO     Running from /code : ansible-galaxy collection install -vvv --force .
Traceback (most recent call last):
  File "/usr/local/bin/ansible-lint", line 8, in <module>
    sys.exit(_run_cli_entrypoint())
             ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ansiblelint/__main__.py", line 310, in _run_cli_entrypoint
    sys.exit(main(sys.argv))
             ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ansiblelint/__main__.py", line 258, in main
    app = get_app()
          ^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ansiblelint/app.py", line 387, in get_app
    app.runtime.prepare_environment(
  File "/usr/local/lib/python3.11/site-packages/ansiblelint/_vendor/ansible_compat/runtime.py", line 564, in prepare_environment
    self.load_collections()
  File "/usr/local/lib/python3.11/site-packages/ansiblelint/_vendor/ansible_compat/runtime.py", line 180, in load_collections
    data = json.loads(proc.stdout)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
@gone-for-coding gone-for-coding added bug new Triage required labels Jun 1, 2023
@audgirka audgirka self-assigned this Jun 1, 2023
@audgirka audgirka removed the new Triage required label Jun 1, 2023
asmacdo added a commit to asmacdo/molecule that referenced this issue Jun 5, 2023
ansible-compat 4.0.1 included a breaking change. If we want to use
latest, minimum version must be at least 4.0.1.

ansible-compat < 4.1.2 has an issue that causes an unhandled exception
for certain log levels. ansible/ansible-lint#3522
Since this issue caused CI trouble, we go ahead and bump to 4.1.2.
zhan9san pushed a commit to ansible/molecule that referenced this issue Jun 7, 2023
* Use run, not exec, for ansible-compat 4.0.2

4.0.2 dropped the use of `exec`, needs to be replaced with `run`

Fixes #3903

ansible/ansible-compat#256

* bump ansible-compat 4.1.2

ansible-compat 4.0.1 included a breaking change. If we want to use
latest, minimum version must be at least 4.0.1.

ansible-compat < 4.1.2 has an issue that causes an unhandled exception
for certain log levels. ansible/ansible-lint#3522
Since this issue caused CI trouble, we go ahead and bump to 4.1.2.

* fixup

* [DATALAD RUNCMD] recompile requirements.lock.txt

=== Do not change lines below ===
{
 "chain": [],
 "cmd": "pip-compile --no-annotate --output-file=.config/requirements-lock.txt --resolver=backtracking --strip-extras --unsafe-package=ruamel-yaml-clib pyproject.toml",
 "exit": 0,
 "extra_inputs": [],
 "inputs": [],
 "outputs": [],
 "pwd": "."
}
^^^ Do not change lines above ^^^

* fix tests for command init role and init scenario

Currently the tests fail for `test_command_init_role` and
`test_command_init_scneario`. The tests execute `ansible-lint` on the
newly-created roles and the linter recently got more restrictive, so we
now have to adapt.

* [DATALAD RUNCMD] recompile requirements.txt

=== Do not change lines below ===
{
 "chain": [],
 "cmd": "pip-compile --extra=docs --extra=test --no-annotate --output-file=.config/requirements.txt --resolver=backtracking --strip-extras pyproject.toml",
 "exit": 0,
 "extra_inputs": [],
 "inputs": [],
 "outputs": [],
 "pwd": "."
}
^^^ Do not change lines above ^^^

* Fake 3.9 for autogenerated files

I used 3.10, but CI will run this on 3.9, and fail if there is a diff.
This means it is safe to change this by hand, since it will be checked.

---------

Co-authored-by: Daniel Ziegenberg <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants