AttributeError: 'NoneType' object has no attribute '__version__'

I’m getting a strange error when trying to use community.general.gitlab_issue using ansible semaphore in a python virtual env

Semaphore is running as systemd service usiung .deb installation on ubuntu 22.04

# /etc/systemd/system/semaphore.service
[Unit]
Description=Ansible Semaphore
Documentation=https://docs.ansible-semaphore.com/
Wants=network-online.target
After=network-online.target
ConditionPathExists=/usr/bin/semaphore
ConditionPathExists=/home/semaphore/config.json

[Service]
User=semaphore
Group=semaphore
Restart=always
RestartSec=10s

ExecStartPre=/bin/bash -c 'source /home/semaphore/venv/bin/activate'

ExecStart=/bin/bash -c 'source /home/semaphore/venv/bin/activate \
                        && /usr/bin/semaphore service --config /home/semaphore/config.json'
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target

when I am entering the same virtual env that semaphore is using


semaphore@ansible:~$ virtualenv venv/
created virtual environment CPython3.10.12.final.0-64 in 858ms
  creator CPython3Posix(dest=/home/semaphore/venv, clear=False, no_vcs_ignore=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/semaphore/.local/share/virtualenv)
    added seed packages: Jinja2==3.1.2, MarkupSafe==2.1.3, PyMySQL==1.1.0, PyYAML==6.0.1, ansible==9.4.0, ansible_core==2.16.5, boto3==1.28.84, botocore==1.31.84, certifi==2023.7.22, cffi==1.16.0, charset_normalizer==3.3.2, cryptography==41.0.5, dnspython==2.4.2, idna==3.4, jmespath==1.0.1, looseversion==1.3.0, netaddr==0.9.0, packaging==23.2, passlib==1.7.4, pip==22.0.2, pycparser==2.21, pyspnego==0.10.2, python_dateutil==2.8.2, python_gitlab==4.4.0, pywinrm==0.4.3, requests==2.31.0, requests_credssp==2.0.0, requests_ntlm==1.2.0, requests_toolbelt==1.0.0, resolvelib==1.0.1, s3transfer==0.7.0, setuptools==59.6.0, six==1.16.0, urllib3==2.0.7, wheel==0.37.1, xmltodict==0.13.0
  activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
semaphore@ansible:~$ source /home/semaphore/venv/bin/activate
(venv) semaphore@ansible:~$ 

the playbook runs without any problem. But semaphore is getting just

/gitlab_issue.py", line 333, in main\nAttributeError: ‘NoneType’ object has no attribute ‘version

So with other words, I cannot reproduce it. Any ideas what’s missing?

Ok, I’ve found it. The semaphore task escaped from its virtual environment because of it’s inventory. It’s connected via ssh to localhost and took the environment from the host.

1 Like

The module shouldn’t crash like this if python-gitlab isn’t installed. I’ve created a PR to fix that: gitlab modules: do not crash if python-gitlab isn't there by felixfontein · Pull Request #8158 · ansible-collections/community.general · GitHub - it will show a nicer message telling you that python-gitlab isn’t available.

4 Likes

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