Summary: | sysutils/ansible: SHEBANG_FILES breaks ansible_python_interpreter and makes it impossible to manage non-freebsd hosts | ||||||||
---|---|---|---|---|---|---|---|---|---|
Product: | Ports & Packages | Reporter: | merlin | ||||||
Component: | Individual Port(s) | Assignee: | freebsd-ports-bugs (Nobody) <ports-bugs> | ||||||
Status: | Closed FIXED | ||||||||
Severity: | Affects Many People | CC: | ale, lifanov | ||||||
Priority: | --- | Flags: | bugzilla:
maintainer-feedback?
(lifanov) |
||||||
Version: | Latest | ||||||||
Hardware: | Any | ||||||||
OS: | Any | ||||||||
Attachments: |
|
The port (correctly) looks for the shebang line to replace with the target interpreter: `--> pkg info -l ansible| grep '\.py$'|xargs grep '/usr/bin/python' /usr/local/lib/python2.7/site-packages/ansible/runner/connection_plugins/ssh.py: # we can only use tty when we are not pipelining the modules. piping data into /usr/bin/python `--> head -n1 /usr/local/lib/python2.7/site-packages/ansible/modules/core/system/ping.py #!/usr/local/bin/python `--> ansible -i /tmp/hosts -m ping all 127.0.0.1 | success >> { "changed": false, "ping": "pong" } c6.test | success >> { "changed": false, "ping": "pong" } /tmp/hosts: [freebsd] 127.0.0.1 [centos] c6.test [centos:vars] ansible_python_interpreter=/usr/bin/python Can you provide a test case that's broken by the SHEBANG_FILES change please? It is incorrect to do it for the modules, direct from the ansible developers. Please take it up with them if you are not willing to take my word for it. Better yet, let's take a look at their coding guidelines: https://github.com/ansible/ansible/blob/devel/CODING_GUIDELINES.md """module code should still use '/usr/bin/python' as this is replaced automatically by 'ansible_python_interpreter', see the FAQ in the docs for more info.""" Their code looks for that specific shebang line otherwise it cannot make use of the variable "ansible_python_interpreter", which is necessary from FreeBSD to a Linux target because FreeBSD keeps python in /usr/local whilst Linux keeps python in /usr/bin. I suspect your centos image is modified. I do not accept the idea I should modify all target hosts. Here's what I did, root shell denoted by shell# and regular by shell$: shell# cd /usr/ports/sysutils/ansible shell# cp Makefile.orig Makefile shell# pkg delete -y ansible shell# portmaster sysutils/ansible -- Now I've got the incorrectly shebang fixed modules. I'll run ping module against my three test machines (FreeBSD 10.2, Debian 8.1, Centos 7.1, respectively) -- shell$ ansible -i inventory -m ping all debiansible | FAILED >> { "failed": true, "msg": "/bin/sh: 1: /usr/local/bin/python2.7: not found\r\nOpenSSH_6.6.1p1, OpenSSL 1.0.1p-freebsd 9 Jul 2015\r\ndebug1: Reading configuration data /home/merlin/.ssh/config\r\ndebug1: /home/merlin/.ssh/config line 8: Applying options for *\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: auto-mux: Trying existing master\r\ndebug1: mux_client_request_session: master session id: 2\r\nShared connection to debiansible closed.\r\n", "parsed": false } ansibeastie | success >> { "changed": false, "ping": "pong" } ancentos | FAILED >> { "failed": true, "msg": "/bin/sh: /usr/local/bin/python2.7: No such file or directory\r\nOpenSSH_6.6.1p1, OpenSSL 1.0.1p-freebsd 9 Jul 2015\r\ndebug1: Reading configuration data /home/merlin/.ssh/config\r\ndebug1: /home/merlin/.ssh/config line 8: Applying options for *\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: auto-mux: Trying existing master\r\ndebug1: mux_client_request_session: master session id: 2\r\nShared connection to ancentos closed.\r\n", "parsed": false } shell# cp Makefile.fixed Makefile shell# pkg delete -y ansible shell# portmaster sysutils/ansible -- Now I've got the correctly NOT shebang fixed modules. I'll run ping module against my three test machines (FreeBSD 10.2, Debian 8.1, Centos 7.1, respectively) -- shell$ ansible -i inventory -m ping all debiansible | success >> { "changed": false, "ping": "pong" } ansibeastie | success >> { "changed": false, "ping": "pong" } ancentos | success >> { "changed": false, "ping": "pong" } shell$ cat inventory [freebsd] ansibeastie [debian] debiansible [centos] ancentos [freebsd:vars] ansible_ssh_user=freebsd-admin ansible_python_interpreter=/usr/local/bin/python2.7 [debian:vars] ansible_ssh_user=debian-admin ansible_python_interpreter=/usr/bin/python [centos:vars] ansible_ssh_user=centos-admin ansible_python_interpreter=/usr/bin/python You're right. USES: shebangfix changed at some point to replace shebang with /usr/local/bin/python2.7 instead of /usr/local/bin/python. The port hasn't changed since, so I was testing with the old version. I built a fresh test box and rebuilt the package and now it doesn't work. Truth is, the code will work with shebangs that end in python (not python2.7), so either /usr/bin/python or /usr/local/bin/python would have worked, but not /usr/local/bin/python2.7. I, maintainer, approve the patch I'm about to attach. Thanks for the report! Created attachment 160688 [details]
sysutils/ansible: don't fix module shebangs
Module shebangs are replaced by ansible_python_interpreter variable only when they end in "python". This was broken by USES: shebangfix transitioning to python2.7. Since modules are not useful as standalone executables, stop modifying shebang lines for them.
Thanks for your quick retesting and patching! Comment on attachment 160688 [details]
sysutils/ansible: don't fix module shebangs
Please hold on a bit. This actually breaks Ansible by default on FreeBSD.
At least a change in pkg-message and UPDATING is necessary to do this.
Created attachment 160695 [details]
sysutils/ansible: fix shebang for modules
This is a fix suggested by Alex Dupre in a private email.
Restore the previous behavior of interpreter of /usr/local/bin/python
and add a warning to pkg-message for users with Python 3.x as the default.
Hopefully, this won't need to stay in for long, since the upstream
is working on Python 3 support.
FYI: it's possible to work around the breakage right now, until the attached patch is committed, by setting (undocumented, works coincidentally) ansible_python2.7_interpreter variable to /usr/bin/python for CentOS. A commit references this bug: Author: ale Date: Fri Sep 4 05:49:52 UTC 2015 New revision: 396055 URL: https://svnweb.freebsd.org/changeset/ports/396055 Log: Fix managing non-FreeBSD hosts. PR: 202799 Submitted by: merlin@merlinsbox.net Approved by: maintainer Changes: head/sysutils/ansible/Makefile head/sysutils/ansible/files/pkg-message.in A commit references this bug: Author: junovitch Date: Tue Sep 22 12:34:17 UTC 2015 New revision: 397537 URL: https://svnweb.freebsd.org/changeset/ports/397537 Log: MFH r396055, r397205: r396055 Fix managing non-FreeBSD hosts. PR: 202799 Submitted by: merlin@merlinsbox.net Approved by: maintainer r397205 sysutils/ansible: update 1.9.2 -> 1.9.3 and add NO_ARCH Changes: https://raw.githubusercontent.com/ansible/ansible/v1.9.3-1/CHANGELOG.md PR: 202895 Submitted by: Nikolai Lifanov <lifanov@mail.lifanov.com> (maintainer) Approved by: ports-secteam (feld) Changes: _U branches/2015Q3/ branches/2015Q3/sysutils/ansible/Makefile branches/2015Q3/sysutils/ansible/distinfo branches/2015Q3/sysutils/ansible/files/pkg-message.in |
The recent change to the port Makefile adding shebangfix and SHEBANG_FILES has broken ansible. According to the ansible developers, ansible modules must use the shebang line "#!/usr/bin/python" because that is what it looks for in order to replace when ansible_python_interpreter is overridden. Since this change, I was unable to manage linux hosts from my freebsd machine. In order to fix it, I had to rebuild the port with the following diff of the Makefile: /usr/ports/sysutils/ansible # diff Makefile Makefile.fixed 24,28c24,25 < SHEBANG_FILES= lib/ansible/runner/action_plugins/synchronize.py \ < lib/ansible/modules/core/*/*.py \ < lib/ansible/modules/core/*/*/*.py \ < lib/ansible/modules/extras/*/*.py \ < lib/ansible/modules/extras/*/*/*.py --- > SHEBANG_FILES= lib/ansible/runner/action_plugins/synchronize.py > As per discussion with upstream developers, all shebang lines in modules should NOT be fixed. This did indeed re-enable the use of ansible_python_interpreter which allowed my linux hosts to be managed again.