This has been reworded, expanded upon and clarified via an update late on 11/9/18. I request it be upvoted now that it has enough code.
I want to find a softlink (to another file) in the $PATH environment variable on Linux managed nodes.
I have an Ansible playbook that uses a find module. I have a string of potential directories to look in. This string is the value assigned to the variable "result_from_prev". My playbook looks like this:
- debug: msg: "{{ item }}: {{ lookup('env', 'PATH') }}" with_dict: {a, 1} register: prevar - set_fact: midvar: "{{ prevar | dictsort | join('') }}" - set_fact: result_from_prev: "{{ midvar.split(':') }}" - find: paths: "{{ item }}" patterns: "goodfile" file_type: link register: files_found loop: "{{ result_from_prev }}" register - set_fact: files_found jsonvar: "{{ files_found | to_json }}" - set_fact: varspecial var: "{{ files_found | tolist json}}" - debug: msg: "{{ item }}" loop: "{{ files_found | json_query('files[*].path' }}" I want to extract the path of the file name for the file that is found. How do I do this?
The above gives me an error about invalid data being passed to loop. A list must be passed. I think that files_found is a dictionary. How would I use wantlist=True here? I tried, but I had no luck.
I tried using jsonvar instead of "files_found" in the loop. But I got the same error about invalid data being passed to 'loop.'
I tried using listvar instead of files_found. But I got the same error about invalid data being passed to 'loop.'
I tried using "with_items" instead of "loop". But this prints out nothing for the msg.
In the JSON that the varspecialjsonvar variable can print out, there is a "matched" key. The value is "0" for each directory path that the file was not found and the value is "1" if the file was found. But I do not know how to extract just the full path of the file found. I'd like it to be clean like this: