Open
Description
Summary
I use a Python virtualenv to install ansible
and ansible-lint
. Now I want to use the community.general.dconf
role which requires psutil
. So I did pip install psutil
but the role does not find it.
Installing python3-psutils
from my distro's package manager resolves the issue, but I'd like to avoid polluting my work machine.
The reason might be the the shebang in plugins/modules/dconf.py
being #!/usr/bin/python
rather than #!/usr/bin/env python
.
Issue Type
Bug Report
Component Name
dconf
Ansible Version
$ ansible --version
ansible [core 2.18.4]
config file = /home/kvite/ansible/ansible.cfg
configured module search path = ['/home/kvite/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/kvite/ansible/venv/lib/python3.13/site-packages/ansible
ansible collection location = /home/kvite/.ansible/collections:/usr/share/ansible/collections
executable location = /home/kvite/ansible/venv/bin/ansible
python version = 3.13.2 (main, Feb 4 2025, 00:00:00) [GCC 14.2.1 20250110 (Red Hat 14.2.1-7)] (/home/kvite/ansible/venv/bin/python)
jinja version = 3.1.6
libyaml = True
Community.general Version
$ ansible-galaxy collection list community.general
# /home/kvite/ansible/venv/lib/python3.13/site-packages/ansible_collections
Collection Version
----------------- -------
community.general 10.5.0
Configuration
$ ansible-config dump --only-changed
CACHE_PLUGIN(/home/kvite/ansible/ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/kvite/ansible/ansible.cfg) = .facts
CONFIG_FILE() = /home/kvite/ansible/ansible.cfg
DEFAULT_BECOME_METHOD(/home/kvite/ansible/ansible.cfg) = su
DEFAULT_GATHERING(/home/kvite/ansible/ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/kvite/ansible/ansible.cfg) = ['/home/kvite/ansible/hosts']
DEFAULT_VAULT_PASSWORD_FILE(/home/kvite/ansible/ansible.cfg) = /home/kvite/ansible/vault-password
EDITOR(env: EDITOR) = nvim
INTERPRETER_PYTHON(/home/kvite/ansible/ansible.cfg) = auto_silent
GALAXY_SERVERS:
OS / Environment
Fedora 41 Workstation
Steps to Reproduce
- name: Set dark mode
community.general.dconf:
key: /org/gnome/desktop/interface/color-scheme
value: "'prefer-dark'"
Expected Results
the dconf
plugin should work
Actual Results
TASK [gnome : Set dark mode] ****************************************************************************************************************
task path: /home/kvite/ansible/roles/gnome/tasks/main.yml:2
<hermos> ESTABLISH LOCAL CONNECTION FOR USER: kvite
<hermos> EXEC /bin/sh -c 'echo ~kvite && sleep 0'
<hermos> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/kvite/.ansible/tmp `"&& mkdir "` echo /home/kvite/.ansible/tmp/ansible-tmp-1744035082.4922552-50110-246453920777471 `" && echo ansible-tmp-1744035082.4922552-50110-246453920777471="` echo /home/kvite/.ansible/tmp/ansible-tmp-1744035082.4922552-50110-246453920777471 `" ) && sleep 0'
Using module file /home/kvite/ansible/venv/lib/python3.13/site-packages/ansible_collections/community/general/plugins/modules/dconf.py
<hermos> PUT /home/kvite/.ansible/tmp/ansible-local-50092679xhrzc/tmpnim_30d9 TO /home/kvite/.ansible/tmp/ansible-tmp-1744035082.4922552-50110-246453920777471/AnsiballZ_dconf.py
<hermos> EXEC /bin/sh -c 'chmod u+x /home/kvite/.ansible/tmp/ansible-tmp-1744035082.4922552-50110-246453920777471/ /home/kvite/.ansible/tmp/ansible-tmp-1744035082.4922552-50110-246453920777471/AnsiballZ_dconf.py && sleep 0'
<hermos> EXEC /bin/sh -c '/home/kvite/ansible/venv/bin/python3.13 /home/kvite/.ansible/tmp/ansible-tmp-1744035082.4922552-50110-246453920777471/AnsiballZ_dconf.py && sleep 0'
<hermos> EXEC /bin/sh -c 'rm -f -r /home/kvite/.ansible/tmp/ansible-tmp-1744035082.4922552-50110-246453920777471/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_community.general.dconf_payload_z7j8irdi/ansible_community.general.dconf_payload.zip/ansible_collections/community/general/plugins/module_utils/deps.py", line 65, in declare
yield dep
File "/tmp/ansible_community.general.dconf_payload_z7j8irdi/ansible_community.general.dconf_payload.zip/ansible_collections/community/general/plugins/modules/dconf.py", line 149, in <module>
import psutil
ModuleNotFoundError: No module named 'psutil'
fatal: [hermos]: FAILED! =>
changed: false
invocation:
module_args:
key: /org/gnome/desktop/interface/color-scheme
state: present
value: '''prefer-dark'''
msg: Failed to import the required Python library (psutil) on hermos's Python /usr/bin/python3.
Please read the module documentation and install it in the appropriate location.
If the required library is installed, but Ansible is using the wrong Python interpreter,
please consult the documentation on ansible_python_interpreter
Code of Conduct
- I agree to follow the Ansible Code of Conduct