ansible file模块主要用于对文件的创建、删除、修改、权限、属性的维护和管理,file模块使用详解:
src ansible端源文件或者目录;
follow 支持link文件拷贝;
force 覆盖远程主机不一致的内容;
group 设定远程主机文件夹的组名;
mode 指定远程主机文件及文件权限;
owner 设定远程主机文件夹的用户名;
path 目标路径,也可以用dest,name代替;
state 状态包括:file、link、directory、hard、touch、absent;
attributes 文件或者目录特殊属性;
1.创建目录
[root@cent79-2 ~]# ansible all -m file -a \”path=/tmp/$(date +%F) state=directory mode=755\”
结果:


2.创建文件
[root@cent79-2 ~]# ansible all -m file -a \”path=/tmp/test.txt state=touch mode=644\”
结果:
<




