Certbot Nginx Plugin Not Working

6. January 2020
bug certbot

EDIT

The solution below did not fix the error message. Suddenly I realized that I edited the wrong file. In my /etc/cron.d folder where two certbot related files. First, the certbot file mentioned below, but also a file called letsencrypt. This file did non contain any PATH at all, so I copied the entry from the certbot file and now it apparently works.

I recently set my server new up and chose to use the nginx plugin of certbot. Now certbot does everything for me when I set up a new site. It changes automatically the config files for the needed paths, issues the http challenge and cleans everything after the successful certificate acquisition up.

To renew old certificates automatically there was a cron job installed, which will call certbot twice a day. Unfortunately there was an error:

Attempting to renew cert (webschneider.org) from /etc/letsencrypt/renewal/webschneider.org.conf produced an unexpected error: The nginx plugin is not working; there may be problems with your existing configuration.
The error was: NoInstallationError("Could not find a usable 'nginx' binary. Ensure nginx exists, the binary is executable, and your PATH is set correctly.",). Skipping.

Okay…

A manual check to verify that nginx is executable an in PATH was of course succsuccessful. There was also no problem with the user (root). So there had to be a different problem.

Cron jobs use their own $PATH which you can set in the cron files. For certbot this is /etc/cron.d/certbot. I changed the existing PATH with what echo $PATH gave me for the root user.

I don't know which path was missing, but now it's working.