0
使用Ansible角色。我想遍歷的文件路徑列表,但我得到一個錯誤:Ansible:找到文件並循環遍歷路徑
template error while templating string: unexpected '/'.
String: {{/home/xyz/download.log}}
這是main.yml
爲「list_log_files」的角色:
- name: "find logs"
find:
paths:/
patterns: 'download.log'
recurse: yes
register: find_logs
- name: "list log files"
debug: var="{{ item.path }}"
with_items: "{{ find_logs.files }}"
這一發現返回數組「文件「,每一個都是一本字典。這本字典包含路徑條目,這是我感興趣的
不幸的是,「debug:var:item.path」不僅僅打印路徑,而是打印「item」的全部內容,但我只想要路徑。也許過濾器會工作? – J21042
不完全。除此之外,任何在循環中運行的'debug'任務都會將指定的變量打印出整個'item' **,因爲這就是模塊寫入的方式。有人剛剛設計了'debug'以用於...驚喜...調試。 – techraf
是的,我對Ansible有很多瞭解。我真的想從「find」中得到一系列路徑來傳遞給其他步驟,但我還不知道該怎麼做。 – J21042