How to fix certbot unrecognized arguments: --dns-cloudflare-credentials on Ubuntu

Problem:

You are trying to request a Let’s Encrypt certificate using certbot, but instead you see an error message like

certbot: error: unrecognized arguments: --dns-cloudflare-credentials /root/.secrets/cloudflare.ini

Solution

Install the required package. This is the solution if you have installed python3-certbot as an apt package:

sudo apt -y install python3-certbot-dns-cloudflare

This is the solution if you have installed certbot as a snap:

sudo snap set certbot trust-plugin-with-root=ok
sudo snap install certbot-dns-cloudflare