I've written some custom facts which I reference to as values for a module in a task . When I have 1 custom fact I don't have a problem running the task , but the question is , what do I do when I have an unknown number of facts that I want to run the task for each one of them ? I have the following facts:
"ansible_facts": {
"ansible_local": {
"facts": {
"finance": {
"files": {
"file1": {
"dest": "/tmp/dir1",
"path": "/etc/finance/file1"
},
"file2": {
"dest": "/tmp/dir2",
"path": "/etc/finance/file2"
}
}
}
}
}
},
This is my task's code:
- name: Copy files
copy:
src: "/tmp/file1/{{ ansible_local.facts.finance.files.file1.path }}"
dest: "/ghostcache/{{ ansible_local.facts.finance.files.file1.dest }}/"
remote_src: yes
How do I iterate over all the items under "files" and take both values (dest and path) and place them as values to the copy module given that I have an unknown number of items under files ? I may have only 1 , i.e file1 or may have file1...fileN .
Thank you !