ansible / ansible

Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy and maintain. Automate everything from code deployment to network configuration to cloud management, in a language that approaches plain English, using SSH, with no agents to install on remote systems. https://docs.ansible.com.
https://www.ansible.com/
GNU General Public License v3.0
62.27k stars 23.79k forks source link

ansible.builtin.apt apt-get upgrade output differs from expected in Ubuntu 22.04LTS when LANGUAGE=en_GB: set, causing 'changed' to always be set to 'true' #83608

Closed ebgp closed 1 month ago

ebgp commented 1 month ago

Summary

With Ubuntu 24.04LTS system locale set as LANGUAGE="en_GB:" the behaviour of ansible.builtin.apt is to always report 'changed' as 'true' when parsing the output of an apt-get upgrade.

A workaround, to avoid the 'translated' output, is to unset the LANGUAGE system locale variable, but it may be preferable to have ansible unset LANGUAGE prior to performing apt-get operations.

The difference in behaviour with and without LANGUAGE set is due to the following substitutions with en_GB contained in the language-pack-en-base package : msgid "%lu upgraded, %lu newly installed, " msgstr "%lu to upgrade, %lu to newly install, "

Issue Type

Bug Report

Component Name

ansible.builtin.apt

Ansible Version

$ ansible --version
ansible [core 2.16.8]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.10.12 (main, Mar 22 2024, 16:50:05) [GCC 11.4.0] (/usr/bin/python3)
  jinja version = 3.0.3
  libyaml = True

Configuration

$ ansible-config dump --only-changed -t all
CONFIG_FILE() = /etc/ansible/ansible.cfg

OS / Environment

Ubuntu 24.04LTS LANGUAGE="en_GB:"

Steps to Reproduce

- name: update packages on ubuntu hosts
  hosts: jammy2204
  gather_facts: no
  become: yes
  roles:
    - ubuntu/all/upgrade-packages
- name: Update cache and upgrade packages
  ansible.builtin.apt:
    upgrade: yes

Expected Results

"changed": false, "msg": "Reading package lists...\nBuilding dependency tree...\nReading state information...\nCalculating upgrade...\n0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\n"

Actual Results

"changed": true, "msg": "Reading package lists...\nBuilding dependency tree...\nReading state information...\nCalculating upgrade...\n0 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.\n"

Code of Conduct

ansibot commented 1 month 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.

Akasurde commented 1 month ago

@ebgp Thanks for reporting this issue. We already reset locale to best guess locale.

Could you please provide me with additional steps to reproduce it? Thanks.

s-hertel commented 1 month ago

Since GNU gettext prefers LANGUAGE in some situations https://www.gnu.org/software/gettext/manual/html_node/Locale-Environment-Variables.html, https://www.gnu.org/software/gettext/manual/html_node/The-LANGUAGE-variable.html, anywhere parsing CLI output that uses gettext may need LANGUAGE set too. It looks like apt_key, apt_repository, and dpkg_selections have the same issue.