I have an Ansible Playbook where I have two JSON arrays:
List1:
[
{
"DistinguishedName": "CN=Warren\\, Oscar J.,OU=Users,OU=Finance Division,OU=Departments,DC=domain,DC=local",
"Name": "Warren, Oscar J.",
"ObjectClass": "user",
"mail": "Oscar.Warren@domain.local"
},
{
"DistinguishedName": "CN=Bodden\\, John B.,OU=Users,OU=Finance Division,OU=Departments,DC=domain,DC=local",
"Name": "Bodden, John B.",
"ObjectClass": "user",
"mail": "John.Bodden@domain.local"
}
]
List2:
[
{
"id": "ABC123",
"userName": "john.bodden@domain.local"
},
{
"id": "DEF456",
"userName": "oscar.warren@domain.local"
}
]
I want to loop through the userName
attribute of each user in List2
, and if there is no object in List1
with a matching mail
value, then I want to perform a task.
I really don't know how even to get started on doing this. I've tried the example below, which is producing errors:
- debug:
var: "{{ item }}"
loop: "{{ List2 }}"
when: "{{ List1 | selectattr('mail', 'equalto', item.userName) }}"
How do I perform a simple loop with the "match" condition I am looking for?