Bug 2239728 - readfp was removed in Python 3.12, which breaks ansible.builtin.setup and ansible.builtin.ini
Summary: readfp was removed in Python 3.12, which breaks ansible.builtin.setup and ans...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: ansible-core
Version: 39
Hardware: Unspecified
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Kevin Fenzi
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks: 2184978
TreeView+ depends on / blocked
 
Reported: 2023-09-19 20:42 UTC by Jonathan Billings
Modified: 2023-10-04 08:13 UTC (History)
7 users (show)

Fixed In Version: ansible-core-2.15.4-2.fc40 ansible-core-2.16.0~b1-1.fc39
Clone Of:
Environment:
Last Closed: 2023-10-02 00:15:39 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github ansible ansible issues 81656 0 None closed ''ansible.builtin.ini'' uses removed function 2023-09-26 10:02:38 UTC

Description Jonathan Billings 2023-09-19 20:42:43 UTC
Due to a change in Python, the version of Python used to run Ansible on Fedora 39 needs to have this patch applied:

https://github.com/ansible/ansible/commit/a861b1adba5d4a12f61ed268f67a224bdaa5f835

This is because the readfp() function was removed in Python 3.12.

This breaks lookup of local facts in /etc/ansible/facts.d/, as well as the ansible.builtin.ini lookup() function when it uses ansible.builtin.ini.

This was reported in:
https://github.com/ansible/ansible/issues/81656

For example:
$ cat /etc/ansible/facts.d/test.fact 
[testsection]
testentry = test

$ ansible -m debug -a "msg={{ lookup('ansible.builtin.ini','testentry section=testsection file=/etc/ansible/facts.d/test.fact') }}" localhost
localhost | FAILED! => {
    "msg": "An unhandled exception occurred while running the lookup plugin 'ansible.builtin.ini'. Error was a <class 'AttributeError'>, original message: 'ConfigParser' object has no attribute 'readfp'. 'ConfigParser' object has no attribute 'readfp'"
}
$ sudo sed -i 's/readfp/read_file/' /usr/lib/python3.12/site-packages/ansible/plugins/lookup/ini.py
$ ansible -m debug -a "msg={{ lookup('ansible.builtin.ini','testentry section=testsection file=/etc/ansible/facts.d/test.fact') }}" localhost
localhost | SUCCESS => {
    "msg": "test"
}

also, this bug prevents ansible_local from being populated.  For example:
$ ansible -m setup localhost | grep ansible_local
        "ansible_locally_reachable_ips": {
$

It doesn't even show an empty dictionary.

But:

$ sudo sed -i 's/readfp/read_file/' /usr/lib/python3.12/site-packages/ansible/module_utils/facts/system/local.py
$ ansible -m setup localhost | grep ansible_local
        "ansible_local": {
        "ansible_locally_reachable_ips": {



Reproducible: Always

Steps to Reproduce:
1. Install ansible-core package
2. Create an INI file
3. Use ansible's lookup() function to read that file
Actual Results:  
You get an AttributeError while creating a ConfigParser object:

An unhandled exception occurred while running the lookup plugin 'ansible.builtin.ini'. Error was a <class 'AttributeError'>, original message: 'ConfigParser' object has no attribute 'readfp'. 'ConfigParser' object has no attribute 'readfp'"

Expected Results:  
Ansible should be able to read INI files fine.

Comment 2 Fedora Update System 2023-09-26 23:56:37 UTC
FEDORA-2023-6787b97c3e has been submitted as an update to Fedora 40. https://bodhi.fedoraproject.org/updates/FEDORA-2023-6787b97c3e

Comment 3 Fedora Update System 2023-09-27 00:04:44 UTC
FEDORA-2023-6787b97c3e has been pushed to the Fedora 40 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 4 Fedora Update System 2023-09-27 00:20:06 UTC
FEDORA-2023-6a4cb513e6 has been submitted as an update to Fedora 39. https://bodhi.fedoraproject.org/updates/FEDORA-2023-6a4cb513e6

Comment 5 Kamil Páral 2023-09-27 11:55:36 UTC
Let's keep it open until the F39 update is stable.

@jbilling Can you please verify whether it fixes the problem for you? (and give +1 karma if it does). Thanks!

Comment 6 Maxwell G 2023-09-27 15:09:03 UTC
Thanks for fixing this, Kevin! I am also planning to rebase the package to 2.16.0b1 tomorrow which actually supports Python 3.12 officially. I do not want to ship our heavily patched version of 2.15 in the final release.

Comment 7 Maxwell G 2023-09-27 15:12:06 UTC
Also, please don't block private bugs or leave private comments on Fedora bugs. We cannot see them and thus cannot do anything about them. Can someone @redhat please remove the Block on bug 2184978 (I don't even have sufficient permissions to remove the Block) or make the bug public?

Comment 8 Jonathan Billings 2023-09-27 20:20:05 UTC
Tested ansible-core-2.15.4-2.fc39.noarch.rpm, and it works with our playbooks, and correctly pulls ansible_local data and INI file information.

Comment 9 Fedora Update System 2023-09-28 20:16:47 UTC
FEDORA-2023-6a4cb513e6 has been pushed to the Fedora 39 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2023-6a4cb513e6`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2023-6a4cb513e6

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 10 Fedora Update System 2023-10-01 05:13:21 UTC
FEDORA-2023-5f1c7b81cd has been pushed to the Fedora 39 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2023-5f1c7b81cd`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2023-5f1c7b81cd

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 11 Fedora Update System 2023-10-02 00:15:39 UTC
FEDORA-2023-5f1c7b81cd has been pushed to the Fedora 39 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 12 Kamil Páral 2023-10-04 08:13:47 UTC
(In reply to Maxwell G from comment #7)
> Also, please don't block private bugs or leave private comments on Fedora
> bugs. We cannot see them and thus cannot do anything about them. Can someone
> @redhat please remove the Block on Red Hatbug 2184978 (I don't even have
> sufficient permissions to remove the Block) or make the bug public?

Hi, sorry, no. The bug in question is private because it concerns an internal product. This bug blocks it, so the relationship is correct (keep in mind that those relations are bidirectional - we don't really care about Blocks here, we care about Depends On in the other bug, but you can't have one without the other). But it has no negative impact on this public discussion, everything important is public here, and the fact that an internal product is blocked doesn't really impact anything in Fedora. In other words, you're really not losing any information, and if there was some important information hidden somewhere, I'd reprint the important and relevant parts even in the public section. But there's no such thing in this case. In general, I always make sure that everything that can be public is public, and private flags are used as little as possible.


Note You need to log in before you can comment on or make changes to this bug.