鍍金池/ 問答/網絡安全/ ansible 如何下載文件到本地?

ansible 如何下載文件到本地?

有300多臺服務器,每臺/tmp/log/目錄下都有個文件,名字為 本機ip.txt
如192.168.1.1.txt、192.168.1.2.txt
...
如何批量下載回本機?

以下親測無效

ansible all -m fetch -a "src=/tmp/log/* dest=/tmp/"
回答
編輯回答
夢若殤
 fetch:
      src: /tmp/{{ inventory_hostname }}.txt
      dest: /tmp/ss-{{ inventory_hostname }}
      flat: yes
//fetch 是調用這個模塊
 fetch:
 //src 是遠程服務器的路徑,這里的 inventory_hostname 就是填在 /etc/ansible/hosts 文件里面的內容。比如說 hosts 文件你填的是 192.168.1.3
// 那這里的 {{inventory_hostname}}.txt 就是 192.168.1.3.txt
      src: /tmp/{{ inventory_hostname }}.txt
      dest: /tmp/ss-{{ inventory_hostname }}
      flat: yes
2017年3月3日 16:33