Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleNotFoundError: No module named 'flask' on RHEL 8 #353

Open
bschonec opened this issue Mar 29, 2022 · 5 comments
Open

ModuleNotFoundError: No module named 'flask' on RHEL 8 #353

bschonec opened this issue Mar 29, 2022 · 5 comments

Comments

@bschonec
Copy link

bschonec commented Mar 29, 2022

After days of attempting to solve the problem myself I'm forced to realize that I don't have the skills to debug Python or Apache.

On a brand new RHEL8 system with @minimal installed, I am unable to get Puppetboard installed properly due to an error about the flask module not being found.

Using a simple:

class { 'puppetboard':
  manage_git        => true,       
  manage_virtualenv => true,
}

Apache barks with:

[Tue Mar 29 08:57:24.729351 2022] [wsgi:error] [pid 6074] [remote 1.17.1.5:58516] mod_wsgi (pid=6074): Failed to exec Python script file '/srv/puppetboard/puppetboard/wsgi.py'.
[Tue Mar 29 08:57:24.729453 2022] [wsgi:error] [pid 6074] [remote 1.17.1.5:58516] mod_wsgi (pid=6074): Exception occurred processing WSGI script '/srv/puppetboard/puppetboard/wsgi.py'.
[Tue Mar 29 08:57:24.729764 2022] [wsgi:error] [pid 6074] [remote 1.17.1.5:58516] Traceback (most recent call last):
[Tue Mar 29 08:57:24.729823 2022] [wsgi:error] [pid 6074] [remote 1.17.1.5:58516]   File "/srv/puppetboard/puppetboard/wsgi.py", line 14, in <module>
[Tue Mar 29 08:57:24.729831 2022] [wsgi:error] [pid 6074] [remote 1.17.1.5:58516]     from puppetboard.app import app as application
[Tue Mar 29 08:57:24.729840 2022] [wsgi:error] [pid 6074] [remote 1.17.1.5:58516]   File "/srv/puppetboard/puppetboard/puppetboard/app.py", line 7, in <module>
[Tue Mar 29 08:57:24.729845 2022] [wsgi:error] [pid 6074] [remote 1.17.1.5:58516]     from flask import render_template, Response
[Tue Mar 29 08:57:24.729863 2022] [wsgi:error] [pid 6074] [remote 1.17.1.5:58516] ModuleNotFoundError: No module named 'flask'

Now, Puppetboard does seem to install properly but it's the Python module (I hope I'm describing it properly) that's giving me trouble.

Apache is running, but I get the following from curl/browser:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at [no address given] to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

A manual run of the WSGI yeilds:

[root@rhel8gold ~]# python3.8 /srv/puppetboard/puppetboard/wsgi.py
Traceback (most recent call last):
  File "/srv/puppetboard/puppetboard/wsgi.py", line 14, in <module>
    from puppetboard.app import app as application
  File "/srv/puppetboard/puppetboard/puppetboard/app.py", line 7, in <module>
    from flask import render_template, Response
ModuleNotFoundError: No module named 'flask'

It's been about four years since I've implemented a Puppet environment so I'm a bit rusty. I've tried the recommendations here:

voxpupuli/puppetboard#527

and here:

voxpupuli/puppetboard#582

but to no avail.

I've had even less success with RHEL7.

SELinux is off and the local firewall allows incoming TCP/80.

Here's my apache vhost config:

<VirtualHost *:80>
  ServerName rhel8gold-puppetboard

  ## Vhost docroot
  DocumentRoot "/srv/puppetboard/puppetboard"

  ## Directories, there should at least be a declaration for /srv/puppetboard/puppetboard

  <Directory "/srv/puppetboard/puppetboard">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Require all granted
  </Directory>

  ## Logging
  ErrorLog "/var/log/httpd/rhel8gold-puppetboard_error.log"
  ServerSignature Off
  CustomLog "/var/log/httpd/rhel8gold-puppetboard_access.log" combined

  ## WSGI configuration
  WSGIDaemonProcess puppetboard group=puppetboard python-home=/srv/puppetboard/virtenv-puppetboard threads=5 user=puppetboard
  WSGIProcessGroup puppetboard
  WSGIScriptAlias / "/srv/puppetboard/puppetboard/wsgi.py"
</VirtualHost>
@bschonec
Copy link
Author

Update:

If I set variable puppetboard::python_version: '3.6' then puppetboard does install properly and runs. The RedHat.8.yaml sets the python version to '3.8' and only when python is set to 3.6 does the virtual environment initialize properly.

@gdubicki
Copy link
Member

Same as #333?

@bschonec
Copy link
Author

Yep, nearly identical. When I changed the Python version to 3.6 everything worked. I'll rebuild my VM with python 3.8 and post the errors.

@jhunt-steds
Copy link

jhunt-steds commented Jun 14, 2022

Hello everyone! I think I've chased down the issue here. Couple things to keep in mind:

  • The RHEL 8 system version of Python is 3.6, so if you install the python3-whatever RPM, the Python whatever module gets installed in the Python 3.6 directories (e.g. /usr/lib64/python3.6/site-packages)
  • As noted above, this module specifies Python 3.8 as its default desired version

So if you have a puppetboard::apache::vhost section on a RHEL server and take the defaults, this module:

  1. Uses Python 3.8 in the virtual environment it sets up
  2. Calls puppetlabs-apache's apache::mod::wsgi class with defaults (see e.g. puppetboard::apache::vhost lines 56-58)
  3. apache::mod::wsgi installs the python3-mod_wsgi RPM, its default package for RHEL 8 (remember, this will be the Python 3.6 mod_wsgi package)
  4. The puppet-python module gets invoked and tries to install python3 and python3-pip, which fails (but you can work around this by telling it to install whichever version of Python you really want, e.g.:
class { 'python':
  version => 'python38',
}

Note that this module requires you to specify the Python version including the decimal point between major and minor release, but the RHEL packages do not have a decimal.

The upshot of all this is that at first the modules don't even get installed in the virtual environment, and then if you fix the problem with the puppet-python package trying to install the wrong version, they are installed but don't work, because the mod_wsgi that's installed is looking for packages in the Python 3.6 paths (I got this error by making wsgi.py write out sys.path: [Tue Jun 14 14:27:32.182043 2022] [wsgi:error] [pid 3519] ['/srv/puppetboard/puppetboard', '/usr/lib64/python36.zip', '/usr/lib64/python3.6', '/usr/lib64/python3.6/lib-dynload']). If you manually uninstall the python3-mod_wsgi RPM and install (assuming Python 3.8) python38-mod_wsgi, Puppetboard starts working after an Apache restart (but of course Puppet hates that and so do I ;-) ). Thus, it seems to me the solution is for this module to be more specific about the package name on RHEL8 servers when calling apache::mod::wsgi, especially since thanks to DNF modules people might be using a variety of Python versions.

@jhunt-steds
Copy link

Hello again, I've found a workaround for the "wrong mod_wsgi" issue: use Hiera to declare some class defaults for apache::mod::wsgi. I added the following to my node's Hiera YAML file (continuing to use Python 3.8 as the example version):

---
apache::mod::wsgi::package_name: 'python38-mod_wsgi'
apache::mod::wsgi::mod_path: 'modules/mod_wsgi_python3.so'

...and now Puppet runs and sets up Puppetboard without issues. Note you do need both, if you try to specify just package_name it complains that it needs mod_path also. In case you prefer it, the full path to the module on RHEL is /usr/lib64/httpd/modules/mod_wsgi_python3.so. Hope this is helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants