# centos7 target - sudden python interpreter trouble

**URL:** <https://forum.ansible.com/t/centos7-target-sudden-python-interpreter-trouble/35867>\
**Category:** Ansible Project\
**Created:** [October 14, 2021, 9:49am UTC](https://forum.ansible.com/t/centos7-target-sudden-python-interpreter-trouble/35867 "2021-10-14T09:49:31Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [October 14, 2021, 9:49am UTC](https://forum.ansible.com/t/centos7-target-sudden-python-interpreter-trouble/35867/1 "2021-10-14T09:49:31Z")

</div>

I am running a [playbook to install postgresql](https://paste.debian.net/1215359/) against a centos7 (python 2.75) target and am getting this [error about a bad python interpreter](https://paste.debian.net/1215357/).

I try to solve this via the inventory.yml

all:  
hosts:  
[hostname]: # centos7  
ansible\_host: [my.domain.org](http://my.domain.org)  
ansible\_user: username  
ansible\_python\_interpreter: /usr/bin/python

(also tried interpreter\_python: /usr/bin/python). the error remains though

funny fact … I ran other playbooks successfully against the same host before even without having specified any python interpreter.

any ideas what may be going wrong here?

---

<div class="post-metadata">

**Author:** ![jean-yves](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jean-yves](https://forum.ansible.com/u/jean-yves)\
**Post date:** [October 14, 2021, 10:16am UTC](https://forum.ansible.com/t/centos7-target-sudden-python-interpreter-trouble/35867/2 "2021-10-14T10:16:38Z")

</div>

\<snip\>

Hi,

Maybe something wrong with alternatives ?

alternatives --list | grep -i python

Regards,

---

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [October 14, 2021, 10:56am UTC](https://forum.ansible.com/t/centos7-target-sudden-python-interpreter-trouble/35867/3 "2021-10-14T10:56:12Z")

</div>

thx for the hint

> Maybe something wrong with alternatives ?  
> \> alternatives --list | grep -i python

turns out empty.

have tried to get something working with

> alternatives --install /usr/bin/python python /usr/bin/python2.7

(where /usr/bin/python is already a symlink to /usr/bin/python2 which is a symlink to /usr/bin/python2.7). It did not change anything though.

probably it's my incompetence. I never heard about alternatives before (and don't really get it, as I thought the symlinks /usr/bin/python \> /usr/bin/python2 \> /usr/bin/python2.7) should be sufficient to guide anybody looking for python to the right executable. Neither do I get why all of a sudden a playbook requires this where opther playbooks running against the exact same host haven't.

---

<div class="post-metadata">

**Author:** ![jean-yves](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jean-yves](https://forum.ansible.com/u/jean-yves)\
**Post date:** [October 14, 2021, 10:59am UTC](https://forum.ansible.com/t/centos7-target-sudden-python-interpreter-trouble/35867/4 "2021-10-14T10:59:28Z")

</div>

Running from the same controller server with the same ansible version ?

Regards,

---

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [October 14, 2021, 11:05am UTC](https://forum.ansible.com/t/centos7-target-sudden-python-interpreter-trouble/35867/5 "2021-10-14T11:05:48Z")

</div>

no, I ran all that on the target. doing that on the Ansible controller server I get:

alternatives --list | grep python  
python manual /usr/bin/python3  
python3 auto /usr/bin/python3.6

---

<div class="post-metadata">

**Author:** ![jean-yves](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jean-yves](https://forum.ansible.com/u/jean-yves)\
**Post date:** [October 14, 2021, 11:15am UTC](https://forum.ansible.com/t/centos7-target-sudden-python-interpreter-trouble/35867/6 "2021-10-14T11:15:41Z")

</div>

That's not what I was asking... But you answer indirectly to one of my questions.  
You have only one ansible controller as I understand.

You seems to say that there were some playbooks which works OK and some don't on the same targets.  
Do you use the same ansible version for the the one which are OK and not OK ? There were some changes between versions of ansible for the python default interpreter search  
Do you use the same inventory ? If not did you force the ansible python interpreter on one and not the other ?

Regards,

---

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [October 14, 2021, 11:37am UTC](https://forum.ansible.com/t/centos7-target-sudden-python-interpreter-trouble/35867/7 "2021-10-14T11:37:08Z")

</div>

> \>\>  
> \>\>  
> \>\> \> thx for the hint  
> \>\> \>  
> \>\> \>\>  
> \>\> \>\> Maybe something wrong with alternatives ?  
> \>\> \>\> \> alternatives --list | grep -i python  
> \>\> \>  
> \>\> \> turns out empty.  
> \>\> \>  
> \>\> \> have tried to get something working with  
> \>\> \>\> alternatives --install /usr/bin/python python /usr/bin/python2.7  
> \>\> \>  
> \>\> \> (where /usr/bin/python is already a symlink to /usr/bin/python2 which  
> \>\> \> is a symlink to /usr/bin/python2.7). It did not change anything  
> \>\> \> though.  
> \>\> \>  
> \>\> \> probably it's my incompetence. I never heard about alternatives before  
> \>\> \> (and don't really get it, as I thought the symlinks /usr/bin/python \>  
> \>\> \> /usr/bin/python2 \> /usr/bin/python2.7) should be sufficient to guide  
> \>\> \> anybody looking for python to the right executable. Neither do I get  
> \>\> \> why all of a sudden a playbook requires this where opther playbooks  
> \>\> \> running against the exact same host haven't.  
> \>\>  
> \>\>  
> \>\> Running from the same controller server with the same ansible version  
> \>\> ?  
> \>  
> \> no, I ran all that on the target. doing that on the Ansible controller  
> \> server I get:  
> \>  
> \> alternatives --list | grep python  
> \> python manual /usr/bin/python3  
> \> python3 auto /usr/bin/python3.6
> 
> That's not what I was asking... But you answer indirectly to one of my  
> questions.  
> You have only one ansible controller as I understand.

yes, one single controller

> You seems to say that there were some playbooks which works OK and some  
> don't on the same targets.  
> Do you use the same ansible version for the the one which are OK and not  
> OK ? There were some changes between versions of ansible for the python  
> default interpreter search

yes same ansible version, no changes in either ansible version, not python

> Do you use the same inventory ? If not did you force the ansible python  
> interpreter on one and not the other ?

same inventory, no forcing

---

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [October 14, 2021, 11:41am UTC](https://forum.ansible.com/t/centos7-target-sudden-python-interpreter-trouble/35867/8 "2021-10-14T11:41:00Z")

</div>

also I can run ad-hoc commands (like ping) on that target successfully (which should proove to some extend that python can be addressed on target, shouldn't it?)

---

<div class="post-metadata">

**Author:** ![Sandip\_Bhattacharya](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@Sandip\_Bhattacharya](https://forum.ansible.com/u/Sandip_Bhattacharya)\
**Post date:** [October 14, 2021, 11:44am UTC](https://forum.ansible.com/t/centos7-target-sudden-python-interpreter-trouble/35867/9 "2021-10-14T11:44:32Z")

</div>

Is this literally what is in your inventory.yaml file? Is that even valid yaml?  
Shouldn't it be:

all:  
&nbsp;&nbsp;&nbsp;hosts:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hostname: # centos7

---

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [October 14, 2021, 12:03pm UTC](https://forum.ansible.com/t/centos7-target-sudden-python-interpreter-trouble/35867/10 "2021-10-14T12:03:26Z")

</div>

this i.e. also works

ansible [hostname] -m shell -a 'yum install @postgresql -y' --become

---

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [October 14, 2021, 12:14pm UTC](https://forum.ansible.com/t/centos7-target-sudden-python-interpreter-trouble/35867/11 "2021-10-14T12:14:58Z")

</div>

this is my literal inventory file: [https://paste.debian.net/1215386/](https://paste.debian.net/1215386/)  
it works for other playbooks, it works for ad-hoc commands (where I addresse a particular host from that group)

---

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [October 14, 2021, 12:23pm UTC](https://forum.ansible.com/t/centos7-target-sudden-python-interpreter-trouble/35867/12 "2021-10-14T12:23:55Z")

</div>

the '# centos7' comment on 2 targets is legal I believe.  
To rule this out I have removed it for a test run. Still the error was present

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [October 14, 2021, 12:28pm UTC](https://forum.ansible.com/t/centos7-target-sudden-python-interpreter-trouble/35867/13 "2021-10-14T12:28:38Z")

</div>

> the '# centos7' comment on 2 targets is legal I believe.  
> To rule this out I have removed it for a test run. Still the error was present

Somewhere the value /usr/bin/python3 must come from ... try to grep for this string through all relevant directories.

Regards

```
    Racke

```

---

<div class="post-metadata">

**Author:** ![jean-yves](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jean-yves](https://forum.ansible.com/u/jean-yves)\
**Post date:** [October 14, 2021, 12:50pm UTC](https://forum.ansible.com/t/centos7-target-sudden-python-interpreter-trouble/35867/14 "2021-10-14T12:50:51Z")

</div>

Did you surcharge the python interpreter variable in a config file ? (/etc/ansible.cfg, ~/.ansible.cfg, etc...)

See:  
[https://docs.ansible.com/ansible/latest/reference\_appendices/config.html](https://docs.ansible.com/ansible/latest/reference_appendices/config.html)

Regards,

---

<div class="post-metadata">

**Author:** ![Sandip\_Bhattacharya](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@Sandip\_Bhattacharya](https://forum.ansible.com/u/Sandip_Bhattacharya)\
**Post date:** [October 14, 2021, 1:05pm UTC](https://forum.ansible.com/t/centos7-target-sudden-python-interpreter-trouble/35867/15 "2021-10-14T13:05:11Z")

</div>

Can you do:  
&nbsp;&nbsp;&nbsp;&nbsp;ansible [hostname] -m setup

---

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [October 14, 2021, 1:30pm UTC](https://forum.ansible.com/t/centos7-target-sudden-python-interpreter-trouble/35867/16 "2021-10-14T13:30:55Z")

</div>

> Can you do:  
> &nbsp;&nbsp;&nbsp;&nbsp;ansible [hostname] -m setup

yes, that works

> Did you surcharge the python interpreter variable in a config file ?

(/etc/ansible.cfg, ~/.ansible.cfg, etc...)

I had a similar idea nad see an 'interpreter\_ansible=auto\_silent' in my effective ansible.cfg- Turning that off does not change anything though
