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