I’m pulling some information from Active Directory and trying to use json_query
to filter it, without success. I’ve written up equivalent code and mock data that reproduces my issue.
using data from here with the following playbook, I’d expect one instance of the with_items loop would have 1/2 the results (Group Name 1) and then the second would have the other 1/2 (Group Name 2)
---
- name: "JSON Query MVP Test"
hosts: localhost
tasks:
- name: "Setup Loop Var"
ansible.builtin.set_fact:
looper: [
{ "ou": "OU=AD Group Name 1,OU=Location,DC=domain,DC=org",
"group": "AD Group Name 1",
},
{ "ou": "OU=AD Group Name 2,OU=Location,DC=domain,DC=org",
"group": "AD Group Name 2"
}
]
- name: "Read in JSON"
include_vars:
file: data.json
name: data
- name: "Debug JSON"
ansible.builtin.debug:
msg: "{{ data }}"
- name: "Test Query"
ansible.builtin.debug:
msg: "{{ data | community.general.json_query('results[?item.ou==' 'item.ou' '].objects[].DistinguishedName')}}"
with_items: "{{ looper }}"
But instead I am getting this
This matches the issue I am having with my real data (the json_query
filter isn’t actually filtering my data).
Can anyone help me spot either my logical or syntactical error here?
UPDATE
when I run this query using jpterm
(manually subbing in the string I’m expecting) it produces the results I’m looking for, but running in a playbook does not. Either that means my variable substitution isn’t working how I think it is (I’ll verify that later) or the query isn’t working the same