Roots Discourse

TASK [letsencrypt : Generate the certificates]: /usr/bin/env: ‘python’: No such file or directory

ansible
trellis

#1

I’m playing around a bit with Trellis 1.0 and try to provision on a fresh Ubuntu 18.04 staging server.
The provision via ansible-playbook server.yml -e env=staging works just fine until the TASK [letsencrypt : Generate the certificates]where it breaks with the error:

non-zero return code
/usr/bin/env: ‘python’: No such file or directory
fatal: [xxx.xxx.xxx.xxx]: FAILED! => {"changed": false, "cmd": ["./renew-certs.py"], "delta": "0:00:00.001970", "end": "2019-01-04 11:13:32.475369", "rc": 127, "start": "2019-01-04 11:13:32.473399", "stderr_lines": ["/usr/bin/env: ‘python’: No such file or directory"], "stdout": "", "stdout_lines": []}

Looking at renew-certs.pyI find #!/usr/bin/env pythonin the first line but on the server python is not availabe as it is python3:

# python --version

Command 'python' not found, but can be installed with:

apt install python3
apt install python
apt install python-minimal

You also have python3 installed, you can run 'python3' instead.

Regarding this reference the first line should read #!/usr/bin/env python3 but doesn’t solve it for me.

It seems to me that renew-certs.pyneeds some modifications to get compatible with Python >3.
I’ll open a PR for this as of:

The above hints helped me to fix this for now.

Best,

Philipp


#2

Please see: https://github.com/roots/trellis/pull/1057


#3

Hi @swalkinshaw,

sadly I’m having some more python related issues when trying to deploy to staging server with Trellis 1.0:

1.) Running ./bin/deploy.sh staging domain.com breaks on PLAY [Deploy WP site] with error:

PLAY [Deploy WP site] ***************************************************************************************************************************************************************************

TASK [Gathering Facts] **************************************************************************************************************************************************************************
System info:
  Ansible 2.7.5; Darwin
  Trellis 1.0.0: December 27th, 2018
---------------------------------------------------
MODULE FAILURE
See stdout/stderr for the exact error
/bin/sh: 1: /usr/bin/python: not found

fatal: [xxx.xxx.xxx.xxx]]: FAILED! => {"changed": false, "module_stdout": "", "rc": 127}

I’m able to overcome this by setting gather_facts: false in /deploy.yml within name: Deploy WP site (l16).

2.) But then ./bin/deploy.sh staging domain.com breaks on TASK [deploy : Initialize] with error:

TASK [deploy : Initialize] **********************************************************************************************************************************************************************
System info:
  Ansible 2.7.5; Darwin
  Trellis 1.0.0: December 27th, 2018
---------------------------------------------------
MODULE FAILURE
See stdout/stderr for the exact error
/bin/sh: 1: /usr/bin/python: not found

fatal: [xxx.xxx.xxx.xxx]: FAILED! => {"changed": false, "module_stdout": "", "rc": 127}

Here it does not find python, again. Sadly and I’m not able to find out where this is set.

Thank you and best regards!

EDIT:

Just tried ln -s /usr/bin/python3 /usr/bin/pythonon the remote to make python command available. That solved the second issue and I was able to deploy to the server. However I don’t think that this is a good solution for the long run.


#4

:thinking:

I think we just need to copy this task block from server.yml to deploy.yml:

- name: Set ansible_python_interpreter
  hosts: web:&{{ env }}
  gather_facts: false
  become: yes
  roles:
    - { role: python_interpreter, tags: [always] }

That would go before - name: Deploy WP site. Could you try that?


#5

I just put up a PR for this: https://github.com/roots/trellis/pull/1058


#6

@philipp I’ve been thinking more of the problems you’ve been running into. It all comes down to Python 2 (/usr/bin/python) not being installed. What kind of modifications have you made to Trellis?

I was just doing some testing because I knew that the python package got installed at some point as a transitive dependency (dependency of a package) and I wanted to track it down.

The fail2ban package definitely depends on it (https://packages.ubuntu.com/bionic/fail2ban) and installs it and it’s one of the first roles Trellis runs. Did you disable or remote that by any chance?


#7

@swalkinshaw I double checked that fail2ban is installed on remote via dpkg -l fail2ban and it is there:

||/ Name                                                    Version                          Architecture                     Description
+++-=======================================================-================================-================================-===================================================================================================================
ii  fail2ban                                                0.10.2-2                         all                              ban hosts that cause multiple authentication errors

I also didn’t change any dependency specific except I replaced vagrant-hostmanager with landrush in vagrant.default.yml as I’m using Multisite.

The fail2ban package definitely depends on it (https://packages.ubuntu.com/bionic/fail2ban) and installs it and it’s one of the first roles Trellis runs. Did you disable or remote that by any chance?

As I read it the package fail2ban just “recommends” python but “requires” python3. Are you sure it is really installed?

As there is nothing to loose on the remote server, I’ll completely destroy it and start from the beginning. Let’s see whether that changes anything.


#8

Ah, true. Yeah basically I installed every package Trellis does one by one and after I tried to run /usr/bin/python. It was definitely installed after fail2ban and uninstalled after I removed it and run apt autoclean.

Regardless, certain parts of Trellis assume /usr/bin/python exists right now and if it is installed, it’s happening as a transitive dependency and not explicitly. I’m thinking we should just install python2 explicitly for the time being to prevent these issues.


#9

1.) Fresh Ubuntu 18.04:

  • python: NO
  • python3: YES

2.) After running ansible-playbook server.yml -e env=staging:

  • python: NO
  • python3: YES

3.) Trying ./bin/deploy.sh staging dev.ouun.io deploy breaks on “Gathering Facts”:

TASK [Gathering Facts] **************************************************************************************************************************************************************************
System info:
  Ansible 2.7.5; Darwin
  Trellis 1.0.0: December 27th, 2018
---------------------------------------------------
MODULE FAILURE
See stdout/stderr for the exact error
/bin/sh: 1: /usr/bin/python: not found

fatal: [xxx.xxx.xxx.xx]: FAILED! => {"changed": false, "module_stdout": "", "rc": 127}

4.) Manually installing python via apt install python

5.) Deploy via ./bin/deploy.sh staging dev.ouun.io: SUCCESS :rocket:

Regardless, certain parts of Trellis assume /usr/bin/python exists right now and if it is installed, it’s happening as a transitive dependency and not explicitly. I’m thinking we should just install python2 explicitly for the time being to prevent these issues.

Yes, I agree that this would help especially those who start with the latest Trellis version and come to the point to deploy.


#10

Thank you for trying this out and reporting back :heart:

It’s still quite weird to me since we’ve created many Ubuntu 18.04 servers (at least locally and on DigitalOcean) and haven’t run into this issue. Python 2 ends up being installed. Regardless, we’re going to do it explicitly for now.


closed #11

This topic was automatically closed after 42 days. New replies are no longer allowed.