-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Summary
The community.general.gem
module incorrectly reports changed : true
on Ubuntu when trying to uninstall a default gem e.g. 'json', without actually uninstalling the gem. This occurs either when the uninstall occurs in the user's local cache (user_install: true
) or for all users. In contrast, on Fedora, RHEL and Rocky we receive an error message, which is the expected behaviour.
Issue Type
Bug Report
Component Name
gem
Ansible Version
$ ansible --version
ansible [core 2.18.6]
python version = 3.12.3
jinja version = 3.1.6
libyaml = True
Community.general Version
$ ansible-galaxy collection list community.general
ansible [core 2.18.6]
python version = 3.12.3
jinja version = 3.1.6
libyaml = True
Configuration
$ ansible-config dump --only-changed
OS / Environment
Issue reproduced on Ubuntu 22.04 & 24.04. On Fedora (40,41,42), RHEL 9 and Rocky 9.3 we get a behaviour which is more expected.
Steps to Reproduce
On Ubuntu 24.04, install gem and run the following task:
- name: Try to uninstall json gem from user scope
community.general.gem:
name: json
state: absent
user_install: true
register: result
Expected Results
On Rocky, RHEL, Fedora we get this failure:
fatal: [localhost]: FAILED! => {"changed": false, "cmd": "/usr/bin/gem uninstall --norc --all --executable json", "msg": "ERROR:********@ rb_check_realpath_internal - /usr/local/share/gems", "rc": 1, "stderr": "ERROR: While executing gem ... (Errno::ENOENT)\n No such file or directory @ rb_check_realpath_internal - /usr/local/share/gems\n", "stderr_lines": ["ERROR: While executing gem ... (Errno::ENOENT)", " No such file or directory @ rb_check_realpath_internal - /usr/local/share/gems"], "stdout": "", "stdout_lines": []}
Actual Results
On Ubuntu we get a changed status, even if we run the same task multiple times:
TASK [Try to uninstall json gem from user scope] ******************************************************************************************************************************************************
changed: [localhost]
Additional Details:
On Ubuntu when we run:
sudo gem uninstall json
we get:
Gem json-2.6.3 cannot be uninstalled because it is a default gem
while on Rocky:
ERROR: While executing gem ... (Errno::ENOENT)
No such file or directory @ rb_check_realpath_internal - /usr/local/share/gems```
The Ubuntu message likely misleads the module into treating the uninstall as a success, even though nothing has changed. This results in incorrect reporting (changed: true) despite the system state remaining the same.
Code of Conduct
- I agree to follow the Ansible Code of Conduct