# Python-interpreter failing

**URL:** <https://forum.ansible.com/t/python-interpreter-failing/1909>\
**Category:** Get Help\
**Tags:** playbook\
**Created:** [October 24, 2023, 11:43am UTC](https://forum.ansible.com/t/python-interpreter-failing/1909 "2023-10-24T11:43:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![valkiriaaquatica](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/valkiriaaquatica/32/1308_2.png) [@valkiriaaquatica](https://forum.ansible.com/u/valkiriaaquatica)\
**Post date:** [October 24, 2023, 11:43am UTC](https://forum.ansible.com/t/python-interpreter-failing/1909/1 "2023-10-24T11:43:25Z")

</div>

Hi,  
I am executing ansible against a red hat 6.1 machine which I have installed a parallel version of python3.8 which is in /usr/local/bin/python3.8. The problem comes when I try to run any role. or independet playbook. I mean, in the inventories or in the --extra-vars or in ansible.cfg I have already tried to put ansible\_python\_interpreter=/usr/local/bin/python3.8 and all I get it fine, and the playbook is running but suddenly it comes to some task and jumps the error “ansible-core requires a minimum of Python2 version 2.7 or Python3 version 3.5. Current version: 2.6.6 (r266:84292,”) . The weird thing is that sometimes it runs the tasks (either on localhost or on the red hat machine) and in some other task the error pops up, it is very random. I am using:

- ansible version = 2.14.2
- operating system = oracle linux 8.8
- python3.11.2

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [October 24, 2023, 12:02pm UTC](https://forum.ansible.com/t/python-interpreter-failing/1909/2 "2023-10-24T12:02:42Z")

</div>

It isn’t random. We just haven’t identified the relevant circumstances. You’re going to have to gather more data. Are there some tasks that are more likely to have this occur? Is the RHEL 6.1 machine the only target, or are multiple hosts involved when this happens. I’m curious about the “either on localhost or on the red hat machine” part. Are you saying this happens on the local host (ansible controller) as well as the RHEL 6.1 host?

---

<div class="post-metadata">

**Author:** ![valkiriaaquatica](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/valkiriaaquatica/32/1308_2.png) [@valkiriaaquatica](https://forum.ansible.com/u/valkiriaaquatica)\
**Post date:** [October 24, 2023, 12:20pm UTC](https://forum.ansible.com/t/python-interpreter-failing/1909/3 "2023-10-24T12:20:27Z")

</div>

Hi, than you for the quickk answer

- Gather facts: true
- Are there some tasks that are more likely to have this occur? → No, normal tasks as change the value of a file, add some data into config files and install software (like falcon sensor, antivirus…) , so are write, modify and execute actions.
- Yes, it is the only target -l ip\_direction
- either on localhost or on the red hat machine; with this i trully wanna say thast the error is just occuring on the red hat machine and it doesnot happen on localhost.

---

<div class="post-metadata">

**Author:** ![gotmax23](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/gotmax23/32/106_2.png) [@gotmax23](https://forum.ansible.com/u/gotmax23)\
**Post date:** [October 24, 2023, 5:50pm UTC](https://forum.ansible.com/t/python-interpreter-failing/1909/4 "2023-10-24T17:50:30Z")

</div>

Welcome to the forum, @valkiriaaquatica!

What modules are failing? Some modules like `yum` require the system python interpreter, and they’ll respawn themselves to use `/usr/bin/python2` which will then fail, as python2.6 is not supported. If you want to use such an ancient version of RHEL, you’ll have to use an older version of ansible that still supports python2.6.

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [October 24, 2023, 8:42pm UTC](https://forum.ansible.com/t/python-interpreter-failing/1909/5 "2023-10-24T20:42:15Z")

</div>

🤔 I get that the `yum` program is itself an OS-provided python program, so of course _it_ would require the system python, but … ? So the `yum` Ansible module doesn’t treat `/usr/bin/yum` like a black box, but uses its internals directly, and respawns itself to do so!? That seems kinda sketchy.

Regardless, would a work-around - for yum at least (on a RHEL that’s so old it could be treated like alien technology) - be to use the `command` module and run `/usr/bin/yum` with appropriate parameters? I’m all for upgrades etc., but @valkiriaaquatica has _so much_ working, it’d be a shame to be stopped by a module that’s being too clever. Maybe the yum module needs a `working_trumps_clever: true` option.

---

<div class="post-metadata">

**Author:** ![gotmax23](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/gotmax23/32/106_2.png) [@gotmax23](https://forum.ansible.com/u/gotmax23)\
**Post date:** [October 24, 2023, 9:01pm UTC](https://forum.ansible.com/t/python-interpreter-failing/1909/6 "2023-10-24T21:01:14Z")

</div>

Yum has a public API that ansible uses, so it’s not sketchy at all. The respawn thing only happens when `import yum` fails, and was apparently added in core 2.11 to allow RHEL 8 to package ansible-core for python3.8 despite the system python being python3.6. None of the package management modules, including the dnf and dnf5 ones that have superseded yum, support calling the package management binary directly. They all use the Python bindings. Ansible modules are written in Python so it makes perfect sense for them to use actual Python APIs when they exist instead of shelling out to other programs.

---

<div class="post-metadata">

**Author:** ![valkiriaaquatica](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/valkiriaaquatica/32/1308_2.png) [@valkiriaaquatica](https://forum.ansible.com/u/valkiriaaquatica)\
**Post date:** [October 24, 2023, 9:07pm UTC](https://forum.ansible.com/t/python-interpreter-failing/1909/7 "2023-10-24T21:07:16Z")

</div>

Thanks @gotmax23 really plesed to be here

I get the main idea from @utoddl (no ansible this time).

By the way @gotmax23 I didn’t know that yum was using the API for that Ansible version, that’s why the update also failed on some machines… I tried to modify the module itself and remove the respawn by adding a loop that always takes the path I want from python but it ended up failing. Maybe it’s my turn not to do it with Ansible! a pity haha  
Thanks!!! You have been reeally kind 🙂

---

<div class="post-metadata">

**Author:** ![valkiriaaquatica](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/valkiriaaquatica/32/1308_2.png) [@valkiriaaquatica](https://forum.ansible.com/u/valkiriaaquatica)\
**Post date:** [October 24, 2023, 9:08pm UTC](https://forum.ansible.com/t/python-interpreter-failing/1909/8 "2023-10-24T21:08:01Z")

</div>

With the respawn i mean, i indicate always the python version that i wanted and not the default
