I am using Ansible on top of Python3 and Enterprise Linux 8 (Rocky Linux 8).
When I try to use json_query
, I am getting the following error:
fatal: [ansible]: FAILED! => {"msg": "You need to install \"jmespath\" prior to running json_query filter"}
But the Python module appears to be installed already:
# dnf install python3-jmespath
Last metadata expiration check: 1:44:38 ago on Mi 02 Nov 2022 12:54:28 CET.
Package python3-jmespath-0.9.0-11.el8.noarch is already installed.
Dependencies resolved.
Nothing to do.
Complete!
# pip3 install jmespath
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Requirement already satisfied: jmespath in /usr/lib/python3.6/site-packages
I tested jmespath
in an interactive Python interpreter, which is running correctly, without error. This seems to confirm that the Python module is installed, and works correctly.
It seems that the problem only occurs when using Ansible.
Here is the playbook I am using for testing:
---
- name: test json_query
hosts: ansible
vars:
data:
list1:
one:
name: "hello"
two:
name: "world"
tasks:
- name: search variable
ansible.builtin.debug:
var: item
loop: "{{ data | community.general.json_query('list1[*].name') }}"
What am I missing?