Hi,
I’ve created a small demo below which demonstrates my problem.
I can’t seem to invoke the with_items and call {{item}} later on. What am I doing wrong? I’ve tried searching obviously but I can’t find the direct answer, sorry for the newbie question.
My playbook invokes a role, and below is my role:
- name: Mytest to register a variable
find: paths=“/tmp/demo/” patterns=“*.txt”
register: r
- name: mytest to show my results
debug: msg=“{{item}}”
with_items: r
The above doesn’t give the desired result. When i change my task mytest into
- name: mytest
debug: msg={{r.files.0.path}}
then i do get the first .txt file found, I can’t seem to make it dynamically.
Ultimately I’m trying to create a loop true a directory, and based on the file extension I want to invoke a certain action. For example, if the file extension is .sh, then invoke shell. If it’s .sql, then invoke sqlplus, and more extensions. If the extension is not listed then copy the file. Perhaps my whole approach is wrong in the first place, I’m trying to take it step by step of course, which might lead me in a wrong direction?
Again, thanks so much.