semaphoreui/semaphore

Problem: Inventory Scripts no longer able to be parsed

vdudejon opened this issue · 2 comments

Issue

I use python scripts to generate inventory, and that has worked great in Semaphore by pointing to an inventory type of file. In at least the latest release, maybe earlier but I never noticed because I hadn't upgraded recently, my inventory files are no longer able to be parsed. My inventory script checks a database, and I'm seeing errors like:

Failed to parse /tmp/semaphore/repository_3_93/inventory/skyhawk2_inventory.py with script
plugin: 
Inventory script (/tmp/semaphore/repository_3_93/inventory/skyhawk2_inventory.py) had an execution error: 
Traceback (most recent call last):   
File "/tmp/semaphore/repository_3_93/inventory/skyhawk2_inventory.py", line 3, in <module> import psycopg2 ModuleNotFoundError: No module named 'psycopg2' 

In the past I used an ansible playbook to install required python modules on the docker container itself, and that task still works but it seems like it is not installing to the right place any more? I've also tried placing the requirements.txt file in /etc/semaphore/requirements.txt. I've also tried using the venv python binary to install it directly, such as /opt/semaphore/apps/ansible/9.4.0/venv/bin/pip3 install -r /etc/semaphore/requirements.txt

Is there a new way to install python modules so that inventory scripts can work? Am I missing something?

Impact

Ansible (task execution), Docker

Installation method

Docker

Database

Postgres

Browser

Firefox

Semaphore Version

v2.10.32-f33944e-1729509451

Ansible Version

No response

Logs & errors

 
No /tmp/semaphore/repository_3_75/playbooks/legacy_automation/collections/requirements.yml file found. Skip galaxy install process.

No /tmp/semaphore/repository_3_75/playbooks/legacy_automation/requirements.yml file found. Skip galaxy install process.

No /tmp/semaphore/repository_3_75/playbooks/legacy_automation/roles/requirements.yml file found. Skip galaxy install process.

No /tmp/semaphore/repository_3_75/playbooks/legacy_automation/requirements.yml file found. Skip galaxy install process.

ansible-playbook [core 2.16.12]

  config file = /tmp/semaphore/repository_3_75/ansible.cfg

  configured module search path = ['/tmp/semaphore/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']

[DEPRECATION WARNING]: [defaults]collections_paths option, does not fit var 

  ansible python module location = /opt/semaphore/apps/ansible/9.4.0/venv/lib/python3.11/site-packages/ansible

  ansible collection location = /tmp/semaphore/repository_3_75/collections:/tmp/semaphore/collections:/etc/ansible/collections

  executable location = /opt/semaphore/apps/ansible/9.4.0/venv/bin/ansible-playbook

naming standard, use the singular form collections_path instead. This feature 

will be removed from ansible-core in version 2.19. Deprecation warnings can be 

disabled by setting deprecation_warnings=False in ansible.cfg.

  python version = 3.11.10 (main, Sep 11 2024, 09:58:40) [GCC 13.2.1 20231014] (/opt/semaphore/apps/ansible/9.4.0/venv/bin/python3)

  jinja version = 3.1.4

  libyaml = True

Using /tmp/semaphore/repository_3_75/ansible.cfg as config file

setting up inventory plugins

Loading collection ansible.builtin from 

host_list declined parsing /tmp/semaphore/repository_3_75/inventory/legacy/dynamic_db_inventory.py as it did not pass its verify_file() method

auto declined parsing /tmp/semaphore/repository_3_75/inventory/legacy/dynamic_db_inventory.py as it did not pass its verify_file() method

yaml declined parsing /tmp/semaphore/repository_3_75/inventory/legacy/dynamic_db_inventory.py as it did not pass its verify_file() method

toml declined parsing /tmp/semaphore/repository_3_75/inventory/legacy/dynamic_db_inventory.py as it did not pass its verify_file() method

[WARNING]:  * Failed to parse

/tmp/semaphore/repository_3_75/inventory/legacy/dynamic_db_inventory.py with

  File "/opt/semaphore/apps/ansible/9.4.0/venv/lib/python3.11/site-packages/ansible/inventory/manager.py", line 293, in parse_source

    plugin.parse(self._inventory, self._loader, source, cache=cache)

  File "/opt/semaphore/apps/ansible/9.4.0/venv/lib/python3.11/site-packages/ansible/plugins/inventory/script.py", line 152, in parse

script plugin: Inventory script

(/tmp/semaphore/repository_3_75/inventory/legacy/dynamic_db_inventory.py) had

    raise AnsibleParserError(to_native(e))

  File "/opt/semaphore/apps/ansible/9.4.0/venv/lib/python3.11/site-packages/ansible/inventory/manager.py", line 293, in parse_source

    plugin.parse(self._inventory, self._loader, source, cache=cache)

  File "/opt/semaphore/apps/ansible/9.4.0/venv/lib/python3.11/site-packages/ansible/plugins/inventory/ini.py", line 138, in parse

    raise AnsibleParserError(e)

an execution error: Traceback (most recent call last):   File

"/tmp/semaphore/repository_3_75/inventory/legacy/dynamic_db_inventory.py", line

3, in <module>     import psycopg2 ModuleNotFoundError: No module named

'psycopg2'

[WARNING]:  * Failed to parse

/tmp/semaphore/repository_3_75/inventory/legacy/dynamic_db_inventory.py with

ini plugin:

/tmp/semaphore/repository_3_75/inventory/legacy/dynamic_db_inventory.py:3:

Expected key=value host variable assignment, got: psycopg2

[WARNING]: Unable to parse

/tmp/semaphore/repository_3_75/inventory/legacy/dynamic_db_inventory.py as an

inventory source

[WARNING]: No inventory was parsed, only implicit localhost is available

[WARNING]: provided hosts list is empty, only localhost is available. Note that

the implicit localhost does not match 'all'

Loading callback plugin default of type stdout, v2.0 from /opt/semaphore/apps/ansible/9.4.0/venv/lib/python3.11/site-packages/ansible/plugins/callback/default.py

Skipping callback 'default', as we already have a stdout callback.

Skipping callback 'minimal', as we already have a stdout callback.

Skipping callback 'oneline', as we already have a stdout callback.

Manual installation - system information

No response

Configuration

No response

Additional information

No response

This is probably a duplicate of #2464 which removed all ENV vars from the Semaphore runner.

@Omicron7 thanks for that, yeah I think you are right. Reverting to v2.10.31-2a8f7cf-1729425177 and my original workflow works, which was installing requirements via an Ansible task