Hi,
I’m writing a playbook with the aim to search for IOC accross all managed hosts.
I’ve got a dict that contains several file as key (like /home/user/foo) with a checksum as value. The dict have been filled by a previous task.
I also have a list that contains well-known checksum.
I would like to parse the dict and compare values with the list, when one value matches, add the key:value pair in a new dict.
At the moment, i failed to get the expected result as the dictionary is overwritten at each iteration of the loop. Can’t find out how to append in it with jinja2.
Here’s the play for the task:
I'm very interested in the solution, I am looking for something similar (loop on hostvars and
add in a list some hosts depending on theirs vars) !
I guess json_query filter is the way to do it but I didn't succeed…
I tried to follow https://jmespath.org/tutorial.html#filter-projections, to filter hostvars,
with first a silly condition on inventory_hostname to get hostvars['foo']
debug:
msg: "{{ hostvars|json_query('*[inventory_hostname==`foo`].inventory_hostname') }}"
=> empty list
Hey Will -
As you say, in your script each iteration of the loop with_items: “{{ _checksumToCheck }}” in your set_fact task overwrites the final_dict variable.
If I understood correctly what you were trying to do, try changing the final_dict line in in your set_fact
Hi Piya !
Your solution works just fine !
I did try combine before, but the syntax was incorrect, this was driving me nuts.
Thanks a lot,
Wilfried.