Extract certbot version using regex

Hello,
I have a question about getting a certbot version using regex.
We think our ansible command is outdated, since I get this error

I replaced the personal data with {}

Check if the latest version of Certbot is already installed...
  {server} failed | msg: [Errno 2] No such file or directory: b'certbot'
Extract installed Certbot version using regex...
  {server} failed | msg: The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'stdout'

The error appears to be in '/home/{me}/ansible/{directory}/{company}.webapp/tasks/7.5-letsencrypt.yml': line 70, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


- name: Extract installed Certbot version using regex
  ^ here

Now this is the ansible command we use

- name: Extract installed Certbot version using regex
  set_fact:
    installed_certbot_version_extracted: "{{ installed_certbot_version.stdout | regex_search('(?<=certbot )\\d+\\.\\d+\\.\\d+') }}"
  when: webapp.use_letsencrypt | default(False) | bool

A colleague of mine have not updated his system and stuff and everything is working fine at his instance, but when it comes to mine I get this error.
He only gets the {server} failed | msg: [Errno 2] No such file or directory: b'certbot' but its continuing after that.

The regex is not the problem per se. See the following error message:

The error was: 'dict object' has no attribute 'stdout'

It's probably talking about this variable, which is the input for the regex:

installed_certbot_version.stdout

So it seems installed_certbot_version is not populated properly and is missing the stdout entry.

My guess is, and I have no clue what Ansible is entirely, is that the issue is with the No such file or directory: b'certbot' error. My guess is that the thing above the regex would populate the installed_certbot_version dictionary with the stdout entry, but somehow it doesn't.

1 Like

This would be a better question for ansible communities.

If you want other ways to get the Certbot version...

Since 1.0, Certbot has had a __version__ variable in the main file. so...

import certbot
print(certbot.__version__)

is a valid python script that would work.

you could also do pip freeze

both require being invoked from the (virtual) environment that Certbot runs in.

5 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.