Ansible tasks are actions transferred and executed on the remote servers, their ansible_python_interpreter
is discovered, and it likely is "platform-python" (python3.6 on RHEL8). You need to make sure the required module is installed there if needed by the module (check ansible-doc ).
However Ansible callback filters, like json_query
, run on the Ansible control node. And that may be using another version of Ansible, even if you manage the same machine with ansible.
On the controller you might use a package named ansible
or ansible-core
, or you might have installed ansible in a python3 venv. In any case jmespath
should be installed in the same python version that runs your playbook on the controller.
Recent changes in the ansible-core
package complicate this dependency:
Ansible-core 2.13 depends on python 3.9 which installs pip as a weak dependency:
Ansible-core 2.14 depends on python 3.11 which does not install pip, at least on AlmaLinux 8.7.
On AlmaLinux 8.7 there is no python3.11-pip RPM, the same might apply to RHEL8.7 and RockyLinux 8.7.
But in the 8.8 release pip re-appears!
If your build depends on AlmaLinux8 your (providers') package repositories might have, or might not have the RPMs needed to install pip. And whether you can access Pypi depends on your situation as well.
Note that pip3
points to platform-python
on RHEL8, which is Python3.6, that is fine for python libraries required by modules, but not for jmespath. You better be more explicit!
If you run ansible-core
2.14 with python3.11
then you can install jmespath
with:
/usr/bin/pip3.11 install jmespath
If you run ansible-core
2.12 with python3.9
then you can install `jmespath with:
/usr/bin/pip3.9 install jmespath
Conclusion
Batteries seem too heavy to include nowadays, the json_query
plugin is not a part of ansible-core, but included in the collection community.general
, it depends on an external library jmespath
that you need to install on the controller with python3 -m pip install jmespath
. You might not be successful for various reasons. There might be other ways to post-process the JSON return values on the controller, like the jq
program.
https://github.com/ansible/ansible/blob/56f2e65ee78bd0031775e986ff45501b590d9dc1/docs/docsite/rst/playbook_guide/playbooks_filters.rst#selecting-json-data-json-queries