[英]Using find and copy modules in Ansible
我會知道如何使用查找和復制模塊。
當我運行以下代碼時,出現錯誤。
可能我沒有使用正確的寄存器。
- name: ACP Collection 2
find:
path: "{{item}}"
recurse: yes
patterns: '*.log'
with_items:
- '/usr/'
- '/opt/tomcat/logs/'
- '/var/'
- '/root/'
- '/opt/allot/'
register: files_to_copy
- name: copy files to tmp
copy:
src: "{{item}}"
dest: /data/Snapshot/ACP/
with_items: files_to_copy.results
請指教。
您正在遍歷查找模塊中的路徑。 循環返回結果列表,您需要從每個結果中再次遍歷由單個find
執行返回的列表。 取而代之的是,您可以提供find
模塊路徑的列表。 這將使事情變得容易。 然后,您只需要遍歷files_to_copy.files
而不是files_to_copy.results
- name: ACP Collection 2
find:
paths:
- '/usr/'
- '/opt/tomcat/logs/'
- '/var/'
- '/root/'
- '/opt/allot/'
recurse: yes
patterns: '*.log'
register: files_to_copy
- name: copy files to tmp
copy:
src: "{{ item }}"
dest: /data/Snapshot/ACP/
with_items: "{{ files_to_copy.files }}"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.