Ansible使用copy、file模塊實現文件傳輸和管理


以並行的方式同時 SCP 大量的文件到多台機器. 命令如下:

ansible atlanta -m copy -a "src=/etc/hosts dest=/tmp/hosts"

使用 file 模塊可以做到修改文件的屬主和權限:

ansible webservers -m file -a "dest=/srv/foo/a.txt mode=600"
ansible webservers -m file -a "dest=/srv/foo/b.txt mode=600 owner=mdehaan group=mdehaan"

使用 file 模塊也可以創建目錄,與執行 mkdir -p 效果類似:

ansible webservers -m file -a "dest=/path/to/c mode=755 owner=mdehaan group=mdehaan state=directory"

刪除目錄(遞歸的刪除)和刪除文件:

ansible webservers -m file -a "dest=/path/to/c state=absent"


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM