# noob question on ansible\_python\_interpreter

**URL:** <https://forum.ansible.com/t/noob-question-on-ansible-python-interpreter/13021>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [June 26, 2013, 1:49pm UTC](https://forum.ansible.com/t/noob-question-on-ansible-python-interpreter/13021 "2013-06-26T13:49:27Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Lucas](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@Michael\_Lucas](https://forum.ansible.com/u/Michael_Lucas)\
**Post date:** [June 26, 2013, 1:49pm UTC](https://forum.ansible.com/t/noob-question-on-ansible-python-interpreter/13021/1 "2013-06-26T13:49:27Z")

</div>

Hi,

I'm running ansible 1.2 on an OpenBSD-current snapshot, from OpenBSD  
packages, and having trouble with ansible\_python\_interpreter.

BSD systems put python in /usr/local/bin/, which I assume is why . I want to start managing my  
Ubuntu systems. I've added a standalone entry at the top of hosts:

web1.domain.com ansible\_python\_interpreter=/usr/bin/python

$ ansible -m ping web1.lodden.com  
web1.domain.com | FAILED \>\> {  
&nbsp;&nbsp;&nbsp;&nbsp;"failed": true,  
&nbsp;&nbsp;&nbsp;&nbsp;"msg": "/bin/sh: /usr/local/bin/python2.7: not found\n",  
&nbsp;&nbsp;&nbsp;&nbsp;"parsed": false  
}

Obviously, I lack understanding. How can I tell ansible to use  
/usr/bin/python?

==ml

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [June 26, 2013, 2:46pm UTC](https://forum.ansible.com/t/noob-question-on-ansible-python-interpreter/13021/2 "2013-06-26T14:46:56Z")

</div>

Ansible should always be using /usr/bin/python, unless ansible\_python\_interpreter is set differently.

In your example, this looks pretty strange/unusual to me, is there a chance you have edited another inventory file?

(Or perhaps did the package edit the shebang line of the ping module? If so, that would be bad, and it should not do that)

---

<div class="post-metadata">

**Author:** ![Patrik\_Lundin](https://avatars.discourse-cdn.com/v4/letter/p/8e7dd6/32.png) [@Patrik\_Lundin](https://forum.ansible.com/u/Patrik_Lundin)\
**Post date:** [June 26, 2013, 2:59pm UTC](https://forum.ansible.com/t/noob-question-on-ansible-python-interpreter/13021/3 "2013-06-26T14:59:03Z")

</div>

That is a bit interesting, my experience has been that OpenBSD  
boxes need the extra ansible\_python\_interpreter for the reasons you  
state where linux works out of the box (while using OpenBSD as the  
management host).

I have never run ansible from packages though. And to verify I just now  
created a host inventory containing a bare ip addrss (.124 is an ubuntu  
12.10 host):  
192.168.1.124

And:  
$ cd git/ansible  
$ . hacking/env-setup  
$ cd  
$ ansible -i \<hosts file\> -u root -c ssh -m ping 192.168.1.124

... returns a successful result on the Jun 13 snapshot I am running.

Nice to see more OpenBSD users around here though! (and I just finished  
Absolute OpenBSD 2:ed the other day, a really good read 🙂

Regards,  
Patrik Lundin

---

<div class="post-metadata">

**Author:** ![Michael\_Lucas](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@Michael\_Lucas](https://forum.ansible.com/u/Michael_Lucas)\
**Post date:** [June 26, 2013, 3:26pm UTC](https://forum.ansible.com/t/noob-question-on-ansible-python-interpreter/13021/4 "2013-06-26T15:26:56Z")

</div>

[I've added the OpenBSD ansible package maintainer to this discussion,  
as it's an error in the package. Leaving the discussion on  
ansible-project because I have no idea what the proper fix is from  
both the OpenBSD and ansible sides.]

> \> Hi,  
> \>  
> \> I'm running ansible 1.2 on an OpenBSD-current snapshot, from OpenBSD  
> \> packages, and having trouble with ansible\_python\_interpreter.  
> \>  
> \> BSD systems put python in /usr/local/bin/, which I assume is why . I want to start managing my  
> \> Ubuntu systems. I've added a standalone entry at the top of hosts:  
> \>  
> \> web1.domain.com ansible\_python\_interpreter=/usr/bin/python  
> \>  
> \> $ ansible -m ping web1.lodden.com  
> \> web1.domain.com | FAILED \>\> {  
> \> "failed": true,  
> \> "msg": "/bin/sh: /usr/local/bin/python2.7: not found\n",  
> \> "parsed": false  
> \> }  
> \>
> 
> That is a bit interesting, my experience has been that OpenBSD  
> boxes need the extra ansible\_python\_interpreter for the reasons you  
> state where linux works out of the box (while using OpenBSD as the  
> management host).
> 
> I have never run ansible from packages though. And to verify I just now  
> created a host inventory containing a bare ip addrss (.124 is an ubuntu  
> 12.10 host):  
> 192.168.1.124
> 
> And:  
> $ cd git/ansible  
> $ . hacking/env-setup  
> $ cd  
> $ ansible -i \<hosts file\> -u root -c ssh -m ping 192.168.1.124
> 
> ... returns a successful result on the Jun 13 snapshot I am running.

The ansible file starts with:

#!/usr/local/bin/python2.7  
...

OpenBSD doesn't come with a /usr/bin/python, and it never  
will. Neither will any other BSD. The ports don't install a "python"  
package, actually: they install a version of python, named after the  
version. If the sysadmin wants a plain "python," he picks the version  
he wants.

So, will ansible work if it starts with, say, "env python"?

> Nice to see more OpenBSD users around here though! (and I just finished  
> Absolute OpenBSD 2:ed the other day, a really good read 🙂

Thanks, glad you liked it.

==ml

---

<div class="post-metadata">

**Author:** ![jpmens1](https://avatars.discourse-cdn.com/v4/letter/j/e9c0ed/32.png) [@jpmens1](https://forum.ansible.com/u/jpmens1)\
**Post date:** [June 26, 2013, 3:29pm UTC](https://forum.ansible.com/t/noob-question-on-ansible-python-interpreter/13021/5 "2013-06-26T15:29:42Z")

</div>

> web1.domain.com ansible\_python\_interpreter=/usr/bin/python
> 
> $ ansible -m ping web1.lodden.com

names mismatch: web1.domain and web1.lodden. Is that the reason?

Other than that, do you perhaps have a second line 'web1.domain.com' in  
your inventory file which possibly overrides the variable?

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-JP

---

<div class="post-metadata">

**Author:** ![Michael\_Lucas](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@Michael\_Lucas](https://forum.ansible.com/u/Michael_Lucas)\
**Post date:** [June 26, 2013, 3:34pm UTC](https://forum.ansible.com/t/noob-question-on-ansible-python-interpreter/13021/6 "2013-06-26T15:34:48Z")

</div>

I insufficiently sanitized my problem report, and was hoping that  
people would let that gracefully slip past. But apparently not.

On the plus side, I know that you folks actually read the debugging  
output.

==ml

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [June 26, 2013, 5:03pm UTC](https://forum.ansible.com/t/noob-question-on-ansible-python-interpreter/13021/7 "2013-06-26T17:03:16Z")

</div>

The ansible file starts with:

#!/usr/local/bin/python2.7

Is this the module? It should absolutely not do that. If the packager did this, they should undo this. It would prevent ansible\_python\_interpreter from working.

If it’s set in /usr/bin/ansible or ansible-playbook (the central script), that is ok.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [June 26, 2013, 5:09pm UTC](https://forum.ansible.com/t/noob-question-on-ansible-python-interpreter/13021/8 "2013-06-26T17:09:30Z")

</div>

Assume this, to make it easy to understand.

I’m running from any given OS, I’m managing 5 different OSes. I should definitely NOT be modifying the shebang line because it wouldn’t be appropriate for all systems I am managing.

Instead, I set ansible\_foo\_interpreter, which replaces shebang lines ending in “foo” which what the value of ansible\_foo\_interpeter is set to.

In fact, when executed, Ansible isn’t even using the shebang at all, it’s prefixing the executed command with what was there on the shebang line.

If you have modified the upstream source to say something other than “foo” the replacement mechanism no longer works, and you can no longer manage multiple types of remote operating systems.

So the question is, if the module has “/usr/local/bin/python2.7” at the top, where did the change happen? Was it something the FreeBSD packager did, or is it something you made on your end? If it’s that way in the BSD package, we need to make sure a bug is filed so he undoes that, as he’s breaking the ability of Ansible to manage other operating systems from that BSD machine.

---

<div class="post-metadata">

**Author:** ![Michael\_Lucas](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@Michael\_Lucas](https://forum.ansible.com/u/Michael_Lucas)\
**Post date:** [June 26, 2013, 5:42pm UTC](https://forum.ansible.com/t/noob-question-on-ansible-python-interpreter/13021/9 "2013-06-26T17:42:50Z")

</div>

Sorry, should have been more clear:

In the OpenBSD package, /usr/local/bin/ansible starts with  
#!/usr/local/bin/python2.7

I'm willing to play intermediary to get a proper solution back to the  
FreeBSD & OpenBSD communities.

> From the BSD side, the issue is that you won't find /usr/bin/python on

any major BSD. /usr/bin contains only the core system programs.

FreeBSD might have /usr/local/bin/python  
OpenBSD will only have /usr/local/bin/python$version  
NetBSD and DragonFly will only have /usr/pkg/bin/python

So, is there something that they can put there that would satisfy  
everyone? Or should the BSD folks just not include an Ansible package?

Thanks,

==ml

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [June 26, 2013, 5:46pm UTC](https://forum.ansible.com/t/noob-question-on-ansible-python-interpreter/13021/10 "2013-06-26T17:46:58Z")

</div>

The BSD folks should absolutely continue to include an Ansible package!

They just shouldn’t be running sed on the source code and should port it straight, and need to be taught about ansible\_python\_interpreter (which is mentioned in the docs).

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [June 30, 2013, 10:29pm UTC](https://forum.ansible.com/t/noob-question-on-ansible-python-interpreter/13021/11 "2013-06-30T22:29:23Z")

</div>

@mdehaan, the BSDs have different packages, so the FreeBSD one I authored inside the repo is not what OpenBSD uses. I can also assure that this port does NOT mess with module shebang lines.

@mlucas, check the shebang in the modules (setup, command, etc), that is what is being replaced, if the OpenBSD package changes those it breaks the ansible\_python\_interpreter functionality and should be fixed by the package maintainer.

ansible, ansible-playbook shebangs SHOULD be modified on the system installed, the modules should NOT.
