noob question on ansible_python_interpreter

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
}

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

==ml

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)

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 :slight_smile:

Regards,
Patrik Lundin

[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 :slight_smile:

Thanks, glad you liked it.

==ml

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?

        -JP

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

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.

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.

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

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).

@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.