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

apt_repository module breaks with strange UnicodeDecodeError #81259

Open
1 task done
manuel-hiller-ebm opened this issue Jul 14, 2023 · 2 comments
Open
1 task done

apt_repository module breaks with strange UnicodeDecodeError #81259

manuel-hiller-ebm opened this issue Jul 14, 2023 · 2 comments
Labels
affects_2.15 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_verified This issue needs to be verified/reproduced by maintainer P3 Priority 3 - Approved, No Time Limitation

Comments

@manuel-hiller-ebm
Copy link

manuel-hiller-ebm commented Jul 14, 2023

Summary

I think this problem could be the same as #79523 but for the module apt_repository

Issue Type

Bug Report

Component Name

lib/ansible/modules/apt_repository.py

Ansible Version

bash-5.1$ ansible --version
ansible [core 2.15.1]
  config file = None
  configured module search path = ['/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.11/site-packages/ansible
  ansible collection location = /runner/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.11.2 (main, May 24 2023, 00:00:00) [GCC 11.3.1 20221121 (Red Hat 11.3.1-4)] (/usr/bin/python3.11)
  jinja version = 3.1.2
  libyaml = True

Configuration

# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all

OS / Environment

RHEL 9 (ubi)

Remote host:
OS: Ubuntu 22.04 LTS
Python: 3.10

Steps to Reproduce

- name: Add Vscode repository
  become: true
  ansible.builtin.apt_repository:
    repo: "deb [arch=amd64 signed-by=/etc/apt/keyrings/microsoft.asc] https://packages.microsoft.com/repos/vscode stable main"
    state: present
    filename: vscode

Expected Results

I expect that the Microsoft VScode repository will be added.

Actual Results

{
  "module_stdout": "UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 3: invalid continuation byte\r\n\r\nThe above exception was the direct cause of the following exception:\r\n\r\nSystemError: <class 'UnicodeDecodeError'> returned a result with an exception set\r\n\r\nThe above exception was the direct cause of the following exception:\r\n\r\nSystemError: <class 'UnicodeDecodeError'> returned a result with an exception set\r\n\r\nThe above exception was the direct cause of the following exception:\r\n\r\nSystemError: <class 'UnicodeDecodeError'> returned a result with an exception set\r\n\r\nThe above exception was the direct cause of the following exception:\r\n\r\nSystemError: <class 'UnicodeDecodeError'> returned a result with an exception set\r\n\r\nThe above exception was the direct cause of the following exception:\r\n\r\nSystemError: <class 'UnicodeDecodeError'> returned a result with an exception set\r\n\r\nThe above exception was the direct cause of the following exception:\r\n\r\nSystemError: <class 'UnicodeDecodeError'> returned a result with an exception set\r\n\r\nThe above exception was the direct cause of the following exception:\r\n\r\nTraceback (most recent call last):\r\n  File \"/opt/local_users/ansible/.ansible/tmp/ansible-tmp-1689323618.630589-41-38337135334436/AnsiballZ_apt_repository.py\", line 107, in <module>\r\n    _ansiballz_main()\r\n  File \"/opt/local_users/ansible/.ansible/tmp/ansible-tmp-1689323618.630589-41-38337135334436/AnsiballZ_apt_repository.py\", line 99, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/opt/local_users/ansible/.ansible/tmp/ansible-tmp-1689323618.630589-41-38337135334436/AnsiballZ_apt_repository.py\", line 47, in invoke_module\r\n    runpy.run_module(mod_name='ansible.modules.apt_repository', init_globals=dict(_module_fqn='ansible.modules.apt_repository', _modlib_path=modlib_path),\r\n  File \"/usr/lib/python3.10/runpy.py\", line 224, in run_module\r\n    return _run_module_code(code, init_globals, run_name, mod_spec)\r\n  File \"/usr/lib/python3.10/runpy.py\", line 96, in _run_module_code\r\n    _run_code(code, mod_globals, init_globals,\r\n  File \"/usr/lib/python3.10/runpy.py\", line 86, in _run_code\r\n    exec(code, run_globals)\r\n  File \"/tmp/ansible_ansible.builtin.apt_repository_payload_lkwi0eiu/ansible_ansible.builtin.apt_repository_payload.zip/ansible/modules/apt_repository.py\", line 763, in <module>\r\n  File \"/tmp/ansible_ansible.builtin.apt_repository_payload_lkwi0eiu/ansible_ansible.builtin.apt_repository_payload.zip/ansible/modules/apt_repository.py\", line 740, in main\r\n  File \"/usr/lib/python3/dist-packages/apt/cache.py\", line 152, in __init__\r\n    self.open(progress)\r\n  File \"/usr/lib/python3/dist-packages/apt/cache.py\", line 214, in open\r\n    self._cache = apt_pkg.Cache(progress)\r\nSystemError: <class 'apt_pkg.Cache'> returned a result with an exception set\r\n",
  "module_stderr": "Shared connection to demulvdi7006 closed.\r\n",
  "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
  "rc": 1,
  "_ansible_no_log": null,
  "changed": false
}

Moreover the VScode repository will be added and is located in /etc/apt/sources.list.d/vscode.list

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibot ansibot added needs_triage Needs a first human triage before being processed. affects_2.15 module This issue/PR relates to a module. labels Jul 14, 2023
@ansibot
Copy link
Contributor

ansibot commented Jul 14, 2023

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.

@ansibot ansibot added the bug This issue/PR relates to a bug. label Jul 17, 2023
@mkrizek mkrizek changed the title apt_repository module breaks with strange UnicodeDecodeError using python3.11 and RHEL 9 apt_repository module breaks with strange UnicodeDecodeError Jul 18, 2023
@mkrizek mkrizek added P3 Priority 3 - Approved, No Time Limitation needs_verified This issue needs to be verified/reproduced by maintainer and removed needs_triage Needs a first human triage before being processed. labels Jul 18, 2023
@s-hertel
Copy link
Contributor

This does appear to be another case of #79523. We never set the locale for python-apt, which is used for the Cache. The module also runs commands with apt-key, and it appears the locale is set via env var for those here https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/apt_repository.py#L498-L500. Suggested solution #79523 (comment) should work for apt_repository too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects_2.15 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_verified This issue needs to be verified/reproduced by maintainer P3 Priority 3 - Approved, No Time Limitation
Projects
None yet
Development

No branches or pull requests

4 participants